Rename nuke to EMP, apply clippy fixes
This commit is contained in:
parent
7548b38b04
commit
bf43d63c8a
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1093,7 +1093,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fren"
|
name = "fren"
|
||||||
version = "1.9.0"
|
version = "2.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum 0.8.1",
|
"axum 0.8.1",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fren"
|
name = "fren"
|
||||||
version = "1.9.0"
|
version = "2.0.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|||||||
@ -62,7 +62,7 @@ pub async fn load_db(
|
|||||||
let json_value: JsonValue = match json::parse(&db_string) {
|
let json_value: JsonValue = match json::parse(&db_string) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
ctx.reply(format!("Error parsing json: {}", e)).await?;
|
ctx.reply(format!("Error parsing json: {e}")).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -71,7 +71,7 @@ pub async fn load_db(
|
|||||||
match ctx.data().db.import_db(json_value) {
|
match ctx.data().db.import_db(json_value) {
|
||||||
Ok(_) => ctx.reply("Database imported successfully").await?,
|
Ok(_) => ctx.reply("Database imported successfully").await?,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
ctx.reply(format!("Error importing db: {}", err)).await?;
|
ctx.reply(format!("Error importing db: {err}")).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -262,7 +262,7 @@ pub async fn remove_role(
|
|||||||
ManagedRole::remove_role(&ctx.data().db, role)?;
|
ManagedRole::remove_role(&ctx.data().db, role)?;
|
||||||
guild_id.delete_role(ctx, role).await?;
|
guild_id.delete_role(ctx, role).await?;
|
||||||
|
|
||||||
ctx.reply(format!("Finally got rid of '{}', thank GOD", name))
|
ctx.reply(format!("Finally got rid of '{name}', thank GOD"))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -278,8 +278,7 @@ pub async fn add_social_credit_phrase(
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
if upper_limit < lower_limit {
|
if upper_limit < lower_limit {
|
||||||
ctx.reply(format!(
|
ctx.reply(format!(
|
||||||
"Invalid range, upper limit ({}) is less than lower limit ({})",
|
"Invalid range, upper limit ({upper_limit}) is less than lower limit ({lower_limit})"
|
||||||
upper_limit, lower_limit
|
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -348,7 +347,7 @@ pub async fn remove_movie(
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Movie::remove_movie(&ctx.data().db, &movie)?;
|
Movie::remove_movie(&ctx.data().db, &movie)?;
|
||||||
|
|
||||||
ctx.reply(format!("Removed *{}* from the library", movie))
|
ctx.reply(format!("Removed *{movie}* from the library"))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ pub async fn add_image(
|
|||||||
|
|
||||||
let plural = if images.len() > 1 { "s" } else { "" };
|
let plural = if images.len() > 1 { "s" } else { "" };
|
||||||
|
|
||||||
ctx.reply(format!("Image{} added to {}!", plural, album_name))
|
ctx.reply(format!("Image{plural} added to {album_name}!"))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -48,7 +48,7 @@ pub async fn list_albums(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
message_builder.push_bold_line("Albums:");
|
message_builder.push_bold_line("Albums:");
|
||||||
|
|
||||||
for album in &album_names {
|
for album in &album_names {
|
||||||
message_builder.push_line(format!("* {}", album));
|
message_builder.push_line(format!("* {album}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.reply(message_builder.build()).await?;
|
ctx.reply(message_builder.build()).await?;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ fn cleanup_race(db: &Database) -> Result<(), Error> {
|
|||||||
async fn add_bet(ctx: Context<'_>, bet: Bet, racers: &[Racer]) -> Result<(), RaceError> {
|
async fn add_bet(ctx: Context<'_>, bet: Bet, racers: &[Racer]) -> Result<(), RaceError> {
|
||||||
User::try_take_funds(&ctx.data().db, bet.author, bet.amount).map_err(|err| match err {
|
User::try_take_funds(&ctx.data().db, bet.author, bet.amount).map_err(|err| match err {
|
||||||
Error::UserError(e) => RaceError::BetFundError(e),
|
Error::UserError(e) => RaceError::BetFundError(e),
|
||||||
_ => panic!("Recv'ed error when trying to bet: {}", err),
|
_ => panic!("Recv'ed error when trying to bet: {err}"),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if !racers.iter().any(|r| r.emoji.id == bet.emoji) {
|
if !racers.iter().any(|r| r.emoji.id == bet.emoji) {
|
||||||
@ -135,10 +135,7 @@ pub async fn start_race(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
} else {
|
} else {
|
||||||
payout /= bet_winners.len() as i64;
|
payout /= bet_winners.len() as i64;
|
||||||
|
|
||||||
winner_msg.push_bold_line(format!(
|
winner_msg.push_bold_line(format!("The following winner(s) got a payout of {payout}:"));
|
||||||
"The following winner(s) got a payout of {}:",
|
|
||||||
payout
|
|
||||||
));
|
|
||||||
|
|
||||||
for winner in bet_winners {
|
for winner in bet_winners {
|
||||||
winner_msg.push("* ");
|
winner_msg.push("* ");
|
||||||
@ -180,7 +177,7 @@ pub async fn bet(
|
|||||||
bet_amount,
|
bet_amount,
|
||||||
racer
|
racer
|
||||||
),
|
),
|
||||||
Err(err) => format!("Yeah something's fucked. {}", err),
|
Err(err) => format!("Yeah something's fucked. {err}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.reply(resp).await?;
|
ctx.reply(resp).await?;
|
||||||
|
|||||||
@ -114,7 +114,7 @@ pub async fn random(
|
|||||||
|
|
||||||
let response_template_str = match random.get_response(&global_data.db)? {
|
let response_template_str = match random.get_response(&global_data.db)? {
|
||||||
None => {
|
None => {
|
||||||
msg.reply(&ctx, format!("I'm all out of material for {}", random_name))
|
msg.reply(&ctx, format!("I'm all out of material for {random_name}"))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ pub async fn add_random(
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
if let Err(err) = render_random(ctx.author().display_name(), ctx.data(), &random_response).await
|
if let Err(err) = render_random(ctx.author().display_name(), ctx.data(), &random_response).await
|
||||||
{
|
{
|
||||||
ctx.reply(format!("Template failed test render, try again: {}", err))
|
ctx.reply(format!("Template failed test render, try again: {err}"))
|
||||||
.await?;
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
RandomConfig::add_random(&ctx.data().db, &random_name, &random_response)?;
|
RandomConfig::add_random(&ctx.data().db, &random_name, &random_response)?;
|
||||||
@ -230,8 +230,8 @@ pub async fn roll(
|
|||||||
let roll = die_roll.parse::<ndm::Dice>();
|
let roll = die_roll.parse::<ndm::Dice>();
|
||||||
|
|
||||||
let reply = match roll {
|
let reply = match roll {
|
||||||
Ok(roll) => format!("You rolled: **{}**", roll),
|
Ok(roll) => format!("You rolled: **{roll}**"),
|
||||||
Err(err) => format!("Error parsing dice roll: {}", err),
|
Err(err) => format!("Error parsing dice roll: {err}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.reply(reply).await?;
|
ctx.reply(reply).await?;
|
||||||
@ -358,7 +358,7 @@ pub async fn insult(
|
|||||||
if let Some(output) = output {
|
if let Some(output) = output {
|
||||||
ctx.reply(output).await?;
|
ctx.reply(output).await?;
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(format!("No {}s, mr freeman??", target)).await?;
|
ctx.reply(format!("No {target}s, mr freeman??")).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@ -267,10 +267,10 @@ pub async fn help(ctx: Context<'_>, command: Option<String>) -> Result<(), Error
|
|||||||
for (category, command) in &commands {
|
for (category, command) in &commands {
|
||||||
if !last_category.eq_ignore_ascii_case(category) {
|
if !last_category.eq_ignore_ascii_case(category) {
|
||||||
last_category = category.clone();
|
last_category = category.clone();
|
||||||
msg_builder.push_line(format!("### {}", last_category));
|
msg_builder.push_line(format!("### {last_category}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_builder.push_line(format!("* `!{}`", command));
|
msg_builder.push_line(format!("* `!{command}`"));
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_builder.push_line("-# Made with :sparkling_heart: by Joey");
|
msg_builder.push_line("-# Made with :sparkling_heart: by Joey");
|
||||||
|
|||||||
@ -35,7 +35,7 @@ pub async fn join_role(
|
|||||||
let role = if let Some(role) = role {
|
let role = if let Some(role) = role {
|
||||||
role
|
role
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(format!("I don't know of this '{}' role. If it exists, only god knows. And I have met god. DO NOT MEET GOD", role_name)).await?;
|
ctx.reply(format!("I don't know of this '{role_name}' role. If it exists, only god knows. And I have met god. DO NOT MEET GOD")).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -53,8 +53,7 @@ pub async fn join_role(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
ctx.reply(format!(
|
ctx.reply(format!(
|
||||||
"You have been added to the ~~cult~~ role '{}'",
|
"You have been added to the ~~cult~~ role '{role_name}'"
|
||||||
role_name
|
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -72,7 +71,7 @@ pub async fn leave_role(
|
|||||||
let role = if let Some(role) = role {
|
let role = if let Some(role) = role {
|
||||||
role
|
role
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(format!("I don't know of this '{}' role. If it exists, only god knows. And I have met god. DO NOT MEET GOD", role_name)).await?;
|
ctx.reply(format!("I don't know of this '{role_name}' role. If it exists, only god knows. And I have met god. DO NOT MEET GOD")).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -90,8 +89,7 @@ pub async fn leave_role(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
ctx.reply(format!(
|
ctx.reply(format!(
|
||||||
"You have left '{}'. Its over. All things come to an end. But did it have to be this way?",
|
"You have left '{role_name}'. Its over. All things come to an end. But did it have to be this way?"
|
||||||
role_name
|
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@ -80,7 +80,7 @@ pub async fn buy(
|
|||||||
let resp = match err {
|
let resp = match err {
|
||||||
UserError::NotEnoughFunds => "Sorry Link, but I can't give store credit. Come back when you are mhhmm richer.".to_string(),
|
UserError::NotEnoughFunds => "Sorry Link, but I can't give store credit. Come back when you are mhhmm richer.".to_string(),
|
||||||
UserError::InvalidTarget => "I don't know who you are or how you got here.".to_string(),
|
UserError::InvalidTarget => "I don't know who you are or how you got here.".to_string(),
|
||||||
UserError::InventoryError(err) => format!("Something went wrong with that item: {}", err)
|
UserError::InventoryError(err) => format!("Something went wrong with that item: {err}")
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.reply(resp).await?;
|
ctx.reply(resp).await?;
|
||||||
@ -88,7 +88,7 @@ pub async fn buy(
|
|||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(format!("Congrats, you now own a '{}'", item))
|
ctx.reply(format!("Congrats, you now own a '{item}'"))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,8 +232,7 @@ pub async fn use_item(
|
|||||||
ctx,
|
ctx,
|
||||||
CreateMessage::new()
|
CreateMessage::new()
|
||||||
.content(format!(
|
.content(format!(
|
||||||
"Your NFT my good friend. It's worth **{} FC**!",
|
"Your NFT my good friend. It's worth **{value} FC**!"
|
||||||
value
|
|
||||||
))
|
))
|
||||||
.add_file(
|
.add_file(
|
||||||
CreateAttachment::file(&file, "nft.jpg".to_string())
|
CreateAttachment::file(&file, "nft.jpg".to_string())
|
||||||
@ -301,7 +300,7 @@ pub async fn use_item(
|
|||||||
ItemType::Helmet => {
|
ItemType::Helmet => {
|
||||||
ctx.reply("Your trusty helmet regards you helmetly").await?;
|
ctx.reply("Your trusty helmet regards you helmetly").await?;
|
||||||
}
|
}
|
||||||
ItemType::TacticalNuke => {
|
ItemType::EMP => {
|
||||||
let mut users: Vec<User> = ctx.data().db.filter(|_, _user: &User| true)?.collect();
|
let mut users: Vec<User> = ctx.data().db.filter(|_, _user: &User| true)?.collect();
|
||||||
|
|
||||||
for user in &mut users {
|
for user in &mut users {
|
||||||
@ -318,7 +317,8 @@ pub async fn use_item(
|
|||||||
ctx.data().db.insert(user.clone())?;
|
ctx.data().db.insert(user.clone())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.reply("I have become cancel, the canceller of worlds. https://tenor.com/view/explosion-mushroom-cloud-atomic-bomb-bomb-boom-gif-4464831").await?;
|
ctx.reply("All technology is null and void, have fun suckers!")
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,7 +416,7 @@ pub async fn restock_shop(
|
|||||||
|
|
||||||
bot_user
|
bot_user
|
||||||
.inventory
|
.inventory
|
||||||
.give_item(ItemType::TacticalNuke, rng().random_range(0..=1), None);
|
.give_item(ItemType::EMP, rng().random_range(0..=1), None);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut dir = tokio::fs::read_dir(&global_data.cfg.nft_path).await?;
|
let mut dir = tokio::fs::read_dir(&global_data.cfg.nft_path).await?;
|
||||||
@ -437,7 +437,7 @@ pub async fn restock_shop(
|
|||||||
hasher.write(&nft);
|
hasher.write(&nft);
|
||||||
let nft_hash = hasher.finish();
|
let nft_hash = hasher.finish();
|
||||||
|
|
||||||
let path = global_data.cfg.nft_path.join(format!("{}.jpg", nft_hash));
|
let path = global_data.cfg.nft_path.join(format!("{nft_hash}.jpg"));
|
||||||
|
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -224,7 +224,7 @@ pub async fn cta_bets(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
let payout = (100.0 * outcome.payout_factor()) as u32;
|
let payout = (100.0 * outcome.payout_factor()) as u32;
|
||||||
let mut winner_msg = MessageBuilder::new();
|
let mut winner_msg = MessageBuilder::new();
|
||||||
winner_msg.push_line("## Congrats to our winners:");
|
winner_msg.push_line("## Congrats to our winners:");
|
||||||
winner_msg.push_line(format!("They each get {} Fren Coins!", payout));
|
winner_msg.push_line(format!("They each get {payout} Fren Coins!"));
|
||||||
for winner in &winners {
|
for winner in &winners {
|
||||||
User::give_funds(&ctx.data().db, *winner, payout)?;
|
User::give_funds(&ctx.data().db, *winner, payout)?;
|
||||||
winner_msg.push_line(format!("* {}", winner.mention()));
|
winner_msg.push_line(format!("* {}", winner.mention()));
|
||||||
|
|||||||
@ -87,9 +87,9 @@ pub enum VoiceError {
|
|||||||
impl Display for VoiceError {
|
impl Display for VoiceError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
VoiceError::VoiceNotFound(v) => write!(f, "{} voice not found", v),
|
VoiceError::VoiceNotFound(v) => write!(f, "{v} voice not found"),
|
||||||
VoiceError::WordNotFound(w) => write!(f, "{} is not in dictionary", w),
|
VoiceError::WordNotFound(w) => write!(f, "{w} is not in dictionary"),
|
||||||
VoiceError::Serenity(err) => write!(f, "Serenity error: {}", err),
|
VoiceError::Serenity(err) => write!(f, "Serenity error: {err}"),
|
||||||
VoiceError::NotInVoiceChannel => write!(f, "User not in voice channel"),
|
VoiceError::NotInVoiceChannel => write!(f, "User not in voice channel"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,12 +172,10 @@ pub async fn speak(
|
|||||||
let channel_id = {
|
let channel_id = {
|
||||||
let guild = ctx.cache().guild(guild_id).unwrap();
|
let guild = ctx.cache().guild(guild_id).unwrap();
|
||||||
|
|
||||||
let channel_id = guild
|
guild
|
||||||
.voice_states
|
.voice_states
|
||||||
.get(&user_id)
|
.get(&user_id)
|
||||||
.and_then(|voice_state| voice_state.channel_id);
|
.and_then(|voice_state| voice_state.channel_id)
|
||||||
|
|
||||||
channel_id
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let connect_to = match channel_id {
|
let connect_to = match channel_id {
|
||||||
@ -245,7 +243,7 @@ pub async fn say(
|
|||||||
VoiceError::VoiceNotFound(_)
|
VoiceError::VoiceNotFound(_)
|
||||||
| VoiceError::WordNotFound(_)
|
| VoiceError::WordNotFound(_)
|
||||||
| VoiceError::NotInVoiceChannel => {
|
| VoiceError::NotInVoiceChannel => {
|
||||||
ctx.reply(format!("Error: {}", err)).await?;
|
ctx.reply(format!("Error: {err}")).await?;
|
||||||
}
|
}
|
||||||
_ => return Err(err.into()),
|
_ => return Err(err.into()),
|
||||||
}
|
}
|
||||||
@ -261,7 +259,7 @@ pub async fn list_words(
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
match find_voice(&ctx.data().cfg.voice_path, &voice).await? {
|
match find_voice(&ctx.data().cfg.voice_path, &voice).await? {
|
||||||
None => {
|
None => {
|
||||||
ctx.reply(format!("No voice found called '{}'", voice))
|
ctx.reply(format!("No voice found called '{voice}'"))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Some(voice_path) => {
|
Some(voice_path) => {
|
||||||
@ -271,7 +269,7 @@ pub async fn list_words(
|
|||||||
words.sort();
|
words.sort();
|
||||||
|
|
||||||
let mut list_msg = MessageBuilder::new();
|
let mut list_msg = MessageBuilder::new();
|
||||||
list_msg.push_line(format!("Here are the words for {}:", voice));
|
list_msg.push_line(format!("Here are the words for {voice}:"));
|
||||||
|
|
||||||
for word in words {
|
for word in words {
|
||||||
list_msg.push("* ");
|
list_msg.push("* ");
|
||||||
|
|||||||
34
src/error.rs
34
src/error.rs
@ -10,7 +10,7 @@ use std::fmt::{Display, Formatter};
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
ConfigError(config::ConfigError),
|
ConfigError(config::ConfigError),
|
||||||
SerenityError(poise::serenity_prelude::Error),
|
SerenityError(Box<poise::serenity_prelude::Error>),
|
||||||
TeraError(tera::Error),
|
TeraError(tera::Error),
|
||||||
NoAlbumFound,
|
NoAlbumFound,
|
||||||
UserError(user::UserError),
|
UserError(user::UserError),
|
||||||
@ -21,7 +21,7 @@ pub enum Error {
|
|||||||
MagickError(magick_rust::MagickError),
|
MagickError(magick_rust::MagickError),
|
||||||
CommandError(String),
|
CommandError(String),
|
||||||
IoError(std::io::Error),
|
IoError(std::io::Error),
|
||||||
VoiceError(VoiceError),
|
VoiceError(Box<VoiceError>),
|
||||||
CTAError(cta_api::Error),
|
CTAError(cta_api::Error),
|
||||||
NoImageFound,
|
NoImageFound,
|
||||||
PipelineArgumentError(ModifyImageArgError),
|
PipelineArgumentError(ModifyImageArgError),
|
||||||
@ -38,7 +38,7 @@ impl From<config::ConfigError> for Error {
|
|||||||
|
|
||||||
impl From<poise::serenity_prelude::Error> for Error {
|
impl From<poise::serenity_prelude::Error> for Error {
|
||||||
fn from(err: poise::serenity_prelude::Error) -> Self {
|
fn from(err: poise::serenity_prelude::Error) -> Self {
|
||||||
Self::SerenityError(err)
|
Self::SerenityError(Box::new(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ impl From<std::io::Error> for Error {
|
|||||||
|
|
||||||
impl From<VoiceError> for Error {
|
impl From<VoiceError> for Error {
|
||||||
fn from(value: VoiceError) -> Self {
|
fn from(value: VoiceError) -> Self {
|
||||||
Self::VoiceError(value)
|
Self::VoiceError(Box::new(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,22 +99,22 @@ impl From<ModifyImageArgError> for Error {
|
|||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Error::ConfigError(e) => write!(f, "Config error: {}", e),
|
Error::ConfigError(e) => write!(f, "Config error: {e}"),
|
||||||
Error::SerenityError(e) => write!(f, "Discord error: {}", e),
|
Error::SerenityError(e) => write!(f, "Discord error: {e}"),
|
||||||
Error::TeraError(e) => write!(f, "Tera error: {}", e),
|
Error::TeraError(e) => write!(f, "Tera error: {e}"),
|
||||||
Error::NoAlbumFound => write!(f, "No album found"),
|
Error::NoAlbumFound => write!(f, "No album found"),
|
||||||
Error::UserError(e) => write!(f, "User error: {}", e),
|
Error::UserError(e) => write!(f, "User error: {e}"),
|
||||||
Error::DbError(e) => write!(f, "DB error: {}", e),
|
Error::DbError(e) => write!(f, "DB error: {e}"),
|
||||||
Error::ReqwestError(e) => write!(f, "Reqwest Error: {}", e),
|
Error::ReqwestError(e) => write!(f, "Reqwest Error: {e}"),
|
||||||
Error::ParseFailure => write!(f, "Failed to parse something or other"),
|
Error::ParseFailure => write!(f, "Failed to parse something or other"),
|
||||||
Error::RaasError(msg) => write!(f, "Got error from RaaS: {}", msg),
|
Error::RaasError(msg) => write!(f, "Got error from RaaS: {msg}"),
|
||||||
Error::MagickError(err) => write!(f, "ImageMagick error: {}", err),
|
Error::MagickError(err) => write!(f, "ImageMagick error: {err}"),
|
||||||
Error::CommandError(err_msg) => write!(f, "{}", err_msg),
|
Error::CommandError(err_msg) => write!(f, "{err_msg}"),
|
||||||
Error::IoError(err) => write!(f, "IO Error: {}", err),
|
Error::IoError(err) => write!(f, "IO Error: {err}"),
|
||||||
Error::VoiceError(err) => write!(f, "Voice error: {}", err),
|
Error::VoiceError(err) => write!(f, "Voice error: {err}"),
|
||||||
Error::CTAError(err) => write!(f, "The CTA had an error, I'm shocked: {}", err),
|
Error::CTAError(err) => write!(f, "The CTA had an error, I'm shocked: {err}"),
|
||||||
Error::NoImageFound => write!(f, "Image not found"),
|
Error::NoImageFound => write!(f, "Image not found"),
|
||||||
Error::PipelineArgumentError(err) => write!(f, "{}", err),
|
Error::PipelineArgumentError(err) => write!(f, "{err}"),
|
||||||
Error::NoRandomFound => write!(f, "No random found"),
|
Error::NoRandomFound => write!(f, "No random found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ pub enum ItemData {
|
|||||||
#[derive(
|
#[derive(
|
||||||
Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Copy, poise::ChoiceParameter,
|
Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Copy, poise::ChoiceParameter,
|
||||||
)]
|
)]
|
||||||
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
pub enum ItemType {
|
pub enum ItemType {
|
||||||
#[name = "Cancel Insurance"]
|
#[name = "Cancel Insurance"]
|
||||||
CancelInsurance,
|
CancelInsurance,
|
||||||
@ -48,8 +49,8 @@ pub enum ItemType {
|
|||||||
CancelRay,
|
CancelRay,
|
||||||
#[name = "Helmet"]
|
#[name = "Helmet"]
|
||||||
Helmet,
|
Helmet,
|
||||||
#[name = "Tactical Nuke"]
|
#[name = "EMP"]
|
||||||
TacticalNuke,
|
EMP,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ItemType {
|
impl ItemType {
|
||||||
@ -65,7 +66,7 @@ impl ItemType {
|
|||||||
ItemType::KillGun => "Used to kill people. `!use kill gun @Austin`".to_string(),
|
ItemType::KillGun => "Used to kill people. `!use kill gun @Austin`".to_string(),
|
||||||
ItemType::CancelRay => "Used to cancel people. `!use cancel ray @Austin`".to_string(),
|
ItemType::CancelRay => "Used to cancel people. `!use cancel ray @Austin`".to_string(),
|
||||||
ItemType::Helmet => "Automatically used to block being killed".to_string(),
|
ItemType::Helmet => "Automatically used to block being killed".to_string(),
|
||||||
ItemType::TacticalNuke => "Reset everyone back to the stone age".to_string(),
|
ItemType::EMP => "Disables weapons and defenses".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,8 +101,8 @@ impl FromStr for ItemType {
|
|||||||
Ok(ItemType::Helmet)
|
Ok(ItemType::Helmet)
|
||||||
} else if item.starts_with("cancelray") {
|
} else if item.starts_with("cancelray") {
|
||||||
Ok(ItemType::CancelRay)
|
Ok(ItemType::CancelRay)
|
||||||
} else if item.starts_with("tacticalnuke") {
|
} else if item.starts_with("emp") {
|
||||||
Ok(ItemType::TacticalNuke)
|
Ok(ItemType::EMP)
|
||||||
} else {
|
} else {
|
||||||
Err(InventoryError::UnkownItem)
|
Err(InventoryError::UnkownItem)
|
||||||
}
|
}
|
||||||
@ -119,10 +120,10 @@ impl Display for ItemType {
|
|||||||
ItemType::KillGun => "Kill Gun".to_string(),
|
ItemType::KillGun => "Kill Gun".to_string(),
|
||||||
ItemType::Helmet => "Helmet".to_string(),
|
ItemType::Helmet => "Helmet".to_string(),
|
||||||
ItemType::CancelRay => "Cancel Ray".to_string(),
|
ItemType::CancelRay => "Cancel Ray".to_string(),
|
||||||
ItemType::TacticalNuke => "Tactical Nuke".to_string(),
|
ItemType::EMP => "EMP".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "{}", name)
|
write!(f, "{name}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ impl InventorySlot {
|
|||||||
ItemType::KillGun => 2_000,
|
ItemType::KillGun => 2_000,
|
||||||
ItemType::Helmet => 10_000,
|
ItemType::Helmet => 10_000,
|
||||||
ItemType::CancelRay => 2_000,
|
ItemType::CancelRay => 2_000,
|
||||||
ItemType::TacticalNuke => 100_000,
|
ItemType::EMP => 50_000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
37
src/migrations/migration_9_update_to_emp.rs
Normal file
37
src/migrations/migration_9_update_to_emp.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use j_db::database::Database;
|
||||||
|
use j_db::migration::Migration;
|
||||||
|
use json::JsonValue;
|
||||||
|
|
||||||
|
pub struct Migration9UpdateToEMP {}
|
||||||
|
|
||||||
|
impl Migration for Migration9UpdateToEMP {
|
||||||
|
fn up(&self, db: &Database) -> j_db::error::Result<()> {
|
||||||
|
let tree = db.db.open_tree("Users")?;
|
||||||
|
|
||||||
|
for user in tree.iter() {
|
||||||
|
let (id, user_bytes) = user?;
|
||||||
|
|
||||||
|
let mut user = json::parse(std::str::from_utf8(&user_bytes).unwrap())?;
|
||||||
|
|
||||||
|
for item in user["inventory"]["inventory"].members_mut() {
|
||||||
|
let item_type = item["item_type"].as_str().unwrap();
|
||||||
|
|
||||||
|
if item_type == "TacticalNuke" {
|
||||||
|
item["item_type"] = JsonValue::String("EMP".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tree.insert(id, user.to_string().into_bytes())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn down(&self, _db: &Database) -> j_db::error::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn version(&self) -> u64 {
|
||||||
|
9
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ use crate::migrations::migration_5_update_motivation::Migration5UpdateMotivation
|
|||||||
use crate::migrations::migration_6_add_social_credit::Migration6AddSocialCredit;
|
use crate::migrations::migration_6_add_social_credit::Migration6AddSocialCredit;
|
||||||
use crate::migrations::migration_7_flip_bounds::Migration7FlipBounds;
|
use crate::migrations::migration_7_flip_bounds::Migration7FlipBounds;
|
||||||
use crate::migrations::migration_8_fix_metadata_id::Migration8FixMetadataId;
|
use crate::migrations::migration_8_fix_metadata_id::Migration8FixMetadataId;
|
||||||
|
use crate::migrations::migration_9_update_to_emp::Migration9UpdateToEMP;
|
||||||
use crate::migrations::migration2_remove_imgur::Migration2RemoveImgur;
|
use crate::migrations::migration2_remove_imgur::Migration2RemoveImgur;
|
||||||
use crate::migrations::migration3_remove_img::Migration3RemoveImage;
|
use crate::migrations::migration3_remove_img::Migration3RemoveImage;
|
||||||
use j_db::database::Database;
|
use j_db::database::Database;
|
||||||
@ -16,8 +17,9 @@ mod migration_5_update_motivation;
|
|||||||
mod migration_6_add_social_credit;
|
mod migration_6_add_social_credit;
|
||||||
mod migration_7_flip_bounds;
|
mod migration_7_flip_bounds;
|
||||||
mod migration_8_fix_metadata_id;
|
mod migration_8_fix_metadata_id;
|
||||||
|
mod migration_9_update_to_emp;
|
||||||
|
|
||||||
pub const CURRENT_DB_VERSION: u64 = 8;
|
pub const CURRENT_DB_VERSION: u64 = 9;
|
||||||
|
|
||||||
#[allow(clippy::single_match)]
|
#[allow(clippy::single_match)]
|
||||||
pub fn do_migration(db: &Database) {
|
pub fn do_migration(db: &Database) {
|
||||||
@ -72,6 +74,12 @@ pub fn do_migration(db: &Database) {
|
|||||||
Direction::Up,
|
Direction::Up,
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
9 => migration::do_migration::<Migration9UpdateToEMP>(
|
||||||
|
db,
|
||||||
|
Migration9UpdateToEMP {},
|
||||||
|
Direction::Up,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,9 +23,9 @@ impl Display for RaceError {
|
|||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
RaceError::RacerNotFound => write!(f, "Racer not found"),
|
RaceError::RacerNotFound => write!(f, "Racer not found"),
|
||||||
RaceError::BetFundError(e) => write!(f, "Fund error: {}", e),
|
RaceError::BetFundError(e) => write!(f, "Fund error: {e}"),
|
||||||
RaceError::UserHasBet => write!(f, "User already bet"),
|
RaceError::UserHasBet => write!(f, "User already bet"),
|
||||||
RaceError::GenericError(e) => write!(f, "Sorry the horse died: {}", e),
|
RaceError::GenericError(e) => write!(f, "Sorry the horse died: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ impl Display for UserError {
|
|||||||
match self {
|
match self {
|
||||||
UserError::NotEnoughFunds => write!(f, "Not enough funds"),
|
UserError::NotEnoughFunds => write!(f, "Not enough funds"),
|
||||||
UserError::InvalidTarget => write!(f, "Invalid target"),
|
UserError::InvalidTarget => write!(f, "Invalid target"),
|
||||||
UserError::InventoryError(e) => write!(f, "Inventory error: {}", e),
|
UserError::InventoryError(e) => write!(f, "Inventory error: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user