From c5cada372ecfa9927731a04785ca8abfa6451ea8 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 22 Mar 2025 21:30:59 -0600 Subject: [PATCH] 1.0 bby --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- src/config.rs | 1 + src/discord/admin.rs | 8 +++++++- src/discord/album.rs | 2 ++ src/discord/birthday.rs | 2 ++ src/discord/celeryman.rs | 15 ++++++++------- src/discord/color.rs | 6 ++++-- src/discord/emoji_race.rs | 5 ++++- src/discord/fren_coin.rs | 6 ++++-- src/discord/joke.rs | 12 +++++++++--- src/discord/little_fren.rs | 8 +++++++- src/discord/mod.rs | 15 ++++++++++++++- src/discord/motivate.rs | 2 ++ src/discord/shop.rs | 14 ++++++++++---- src/discord/voices.rs | 6 +++--- src/error.rs | 2 +- src/main.rs | 3 +-- src/models/api_key.rs | 2 ++ src/models/insult_compliment.rs | 1 - src/models/lil_fren.rs | 6 +++--- src/models/race.rs | 3 +-- src/models/random.rs | 4 ++-- 23 files changed, 90 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2cd9db8..04c79c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1080,7 +1080,7 @@ dependencies = [ [[package]] name = "fren" -version = "0.8.0" +version = "1.0.0" dependencies = [ "axum 0.8.1", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 1186ff2..343c99f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "fren" -version = "0.8.0" -edition = "2021" +version = "1.0.0" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/config.rs b/src/config.rs index 1352c01..abcd551 100644 --- a/src/config.rs +++ b/src/config.rs @@ -69,6 +69,7 @@ impl BotState { } pub struct GlobalData { + #[allow(dead_code)] pub args: Args, pub cfg: BotConfig, pub bot_state: Mutex, diff --git a/src/discord/admin.rs b/src/discord/admin.rs index 2ad0c1d..2dc26d3 100644 --- a/src/discord/admin.rs +++ b/src/discord/admin.rs @@ -1,4 +1,3 @@ -use crate::config::BotConfig; use crate::discord::Context; use crate::error::Error; use crate::inventory::ItemType; @@ -21,6 +20,7 @@ pub async fn is_admin(ctx: Context<'_>) -> Result { Ok(ctx.data().cfg.admins.contains(&ctx.author().id)) } +/// Dumps the bot's internal database as JSON #[poise::command(prefix_command, category = "Admin", check = "is_admin")] pub async fn dump_db(ctx: Context<'_>) -> Result<(), Error> { let db_dump = ctx.data().db.dump_db()?; @@ -45,6 +45,7 @@ pub async fn dump_db(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Loads the bot's database state from the attached file #[poise::command(prefix_command, category = "Admin", check = "is_admin")] pub async fn load_db( ctx: Context<'_>, @@ -73,6 +74,7 @@ pub async fn load_db( Ok(()) } +/// Add a new token for the bot's API #[poise::command(prefix_command, category = "Admin", check = "is_admin")] pub async fn add_key( ctx: Context<'_>, @@ -102,6 +104,7 @@ pub async fn add_key( Ok(()) } +/// Get Lil Buddy's Stats #[poise::command(prefix_command, category = "Admin", check = "is_admin")] pub async fn debug_buddy(ctx: Context<'_>) -> Result<(), Error> { let lil_fren = LilFren::get_lil_fren(&ctx.data().db)?; @@ -128,6 +131,7 @@ pub async fn debug_buddy(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Draw all the Lil Buddy states for debugging #[poise::command(prefix_command, category = "Admin", check = "is_admin")] pub async fn draw_buddy_states( ctx: Context<'_>, @@ -149,6 +153,7 @@ pub async fn draw_buddy_states( Ok(()) } +/// I'm from planet Minectaft, plz give op #[poise::command(prefix_command, category = "Admin", check = "is_admin")] pub async fn op_give( ctx: Context<'_>, @@ -169,6 +174,7 @@ pub async fn op_give( Ok(()) } +/// List the tasks the bot is preforming in the background #[poise::command(prefix_command, category = "Admin")] pub async fn list_tasks(ctx: Context<'_>) -> Result<(), Error> { let tasks: Vec = ctx.data().db.filter(|_, _task: &Task| true)?.collect(); diff --git a/src/discord/album.rs b/src/discord/album.rs index 8e0f74e..a98ffc8 100644 --- a/src/discord/album.rs +++ b/src/discord/album.rs @@ -4,6 +4,7 @@ use crate::discord::Context; use crate::error::Error; use poise::serenity_prelude::{Attachment, MessageBuilder}; +/// Add an image to a new or existing album #[poise::command(prefix_command, category = "Albums")] pub async fn add_image( ctx: Context<'_>, @@ -28,6 +29,7 @@ pub async fn add_image( Ok(()) } +/// List all albumbs #[poise::command(prefix_command, category = "Albums")] pub async fn list_albums(ctx: Context<'_>) -> Result<(), Error> { let albums = ctx diff --git a/src/discord/birthday.rs b/src/discord/birthday.rs index bdd9b0c..4afea05 100644 --- a/src/discord/birthday.rs +++ b/src/discord/birthday.rs @@ -5,6 +5,7 @@ use poise::serenity_prelude::model::id::UserId; use poise::serenity_prelude::utils::MessageBuilder; use rand::{rng, Rng}; +/// Add your birthday to the bot, it can probably be trusted with this info #[poise::command(prefix_command, category = "Birthdays")] pub async fn add_birthday( ctx: Context<'_>, @@ -43,6 +44,7 @@ pub async fn add_birthday( Ok(()) } +/// List birthdays added to the bot #[poise::command(prefix_command, category = "Birthdays")] pub async fn list_birthdays(ctx: Context<'_>) -> Result<(), Error> { let birthdays: Vec = diff --git a/src/discord/celeryman.rs b/src/discord/celeryman.rs index f7ccac2..2b5bad8 100644 --- a/src/discord/celeryman.rs +++ b/src/discord/celeryman.rs @@ -1,13 +1,12 @@ -use crate::config::GlobalData; use crate::discord::Context; use crate::error::Error; -use std::net::ToSocketAddrs; -#[poise::command(prefix_command)] +/// Are you sure? +#[poise::command(prefix_command, category = "Celery Man")] pub async fn nudetayne(ctx: Context<'_>) -> Result<(), Error> { - if ctx.invoked_command_name() == "nudetayne".to_string() { + if ctx.invoked_command_name() == "nudetayne" { ctx.reply("Not computing, please repeat.").await?; - } else if ctx.invoked_command_name() == "NUDETAYNE".to_string() { + } else if ctx.invoked_command_name() == "NUDETAYNE" { ctx.reply("This is not suitable for work are you sure?") .await?; @@ -19,14 +18,16 @@ pub async fn nudetayne(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } -#[poise::command(prefix_command)] +/// Tayne +#[poise::command(prefix_command, category = "Celery Man")] pub async fn tayne(ctx: Context<'_>) -> Result<(), Error> { ctx.reply("https://media.tenor.com/115eUl2XUaAAAAAM/flarhgunnstow-paul-rudd.gif") .await?; Ok(()) } -#[poise::command(prefix_command)] +/// THE Celeryman +#[poise::command(prefix_command, category = "Celery Man")] pub async fn celeryman(ctx: Context<'_>) -> Result<(), Error> { ctx.reply("https://media.tenor.com/1iOUXZFLpBgAAAAM/dance-dancing.gif") .await?; diff --git a/src/discord/color.rs b/src/discord/color.rs index 81fb25c..0e33525 100644 --- a/src/discord/color.rs +++ b/src/discord/color.rs @@ -3,6 +3,7 @@ use crate::error::Error; use poise::serenity_prelude::builder::EditRole; use poise::serenity_prelude::model::Colour; +/// Set your discord name's color #[poise::command(prefix_command, guild_only, category = "color")] pub async fn set_color( ctx: Context<'_>, @@ -45,7 +46,7 @@ pub async fn set_color( let guild_id = ctx.guild_id().unwrap(); let member = ctx.author_member().await.unwrap(); - let roles = member.roles(&ctx.cache()).unwrap(); + let roles = member.roles(ctx.cache()).unwrap(); let color_role = roles.iter().find(|role| role.name.contains("COwOlor")); @@ -77,11 +78,12 @@ pub async fn set_color( Ok(()) } +/// Remove your color (good for you!) #[poise::command(prefix_command, guild_only, category = "Color")] pub async fn remove_color(ctx: Context<'_>) -> Result<(), Error> { let guild_id = ctx.guild_id().unwrap(); let member = ctx.author_member().await.unwrap(); - let roles = member.roles(&ctx.cache()).unwrap(); + let roles = member.roles(ctx.cache()).unwrap(); let color_role = roles.iter().find(|role| role.name.contains("COwOlor")); if let Some(role) = color_role { diff --git a/src/discord/emoji_race.rs b/src/discord/emoji_race.rs index b107118..f5baf89 100644 --- a/src/discord/emoji_race.rs +++ b/src/discord/emoji_race.rs @@ -9,7 +9,7 @@ use poise::serenity_prelude::model::id::UserId; use poise::serenity_prelude::utils::MessageBuilder; use poise::serenity_prelude::{EmojiIdentifier, Mentionable}; use rand::seq::IteratorRandom; -use rand::{rng, Rng}; +use rand::rng; use std::time::Duration; fn cleanup_race(db: &Database) -> Result<(), Error> { @@ -39,6 +39,7 @@ async fn add_bet(ctx: Context<'_>, bet: Bet, racers: &[Racer]) -> Result<(), Rac Ok(()) } +/// Setup an emoji race to bet on #[poise::command(prefix_command, guild_only, category = "Race")] pub async fn race(ctx: Context<'_>) -> Result<(), Error> { cleanup_race(&ctx.data().db)?; @@ -64,6 +65,7 @@ pub async fn race(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Start the race! #[poise::command(prefix_command, guild_only, category = "Race")] pub async fn start_race(ctx: Context<'_>) -> Result<(), Error> { let mut racers = Racer::get_racers(&ctx.data().db)?; @@ -154,6 +156,7 @@ pub async fn start_race(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Bet on a race of emojis, a sound idea #[poise::command(prefix_command, guild_only, category = "Race")] pub async fn bet( ctx: Context<'_>, diff --git a/src/discord/fren_coin.rs b/src/discord/fren_coin.rs index 7c80af0..c31b913 100644 --- a/src/discord/fren_coin.rs +++ b/src/discord/fren_coin.rs @@ -7,7 +7,8 @@ use poise::serenity_prelude::model::id::UserId; use poise::serenity_prelude::prelude::Mentionable; use rand::{rng, Rng}; -#[poise::command(prefix_command, category = "FrenCoin", aliases("audit"))] +/// Get your balance or someone else's +#[poise::command(prefix_command, category = "Fren Coin", aliases("audit"))] pub async fn balance( ctx: Context<'_>, #[description = "User to get balance of"] user: Option, @@ -26,7 +27,8 @@ pub async fn balance( Ok(()) } -#[poise::command(prefix_command, category = "FrenCoin", aliases("audit"))] +/// Gift someone the gift that keeps on giving, Fren Coins! +#[poise::command(prefix_command, category = "Fren Coin", aliases("audit"))] pub async fn gift( ctx: Context<'_>, #[description = "User to gift coin to"] target: poise::serenity_prelude::User, diff --git a/src/discord/joke.rs b/src/discord/joke.rs index 9c5300c..73cd90d 100644 --- a/src/discord/joke.rs +++ b/src/discord/joke.rs @@ -9,7 +9,6 @@ use chrono::Utc; use emojis::Group; use log::debug; use poise::serenity_prelude::all::{CreateAttachment, CreateMessage}; -use poise::serenity_prelude::builder::EditMessage; use poise::serenity_prelude::constants::MESSAGE_CODE_LIMIT; use poise::serenity_prelude::model::channel::Message; use poise::serenity_prelude::utils::MessageBuilder; @@ -21,7 +20,6 @@ use rand::prelude::IndexedRandom; use rand::rng; use reqwest::Client; use serde::{Deserialize, Serialize}; -use songbird::id::UserId; use std::collections::HashMap; use std::time::Duration; @@ -32,6 +30,7 @@ struct DadJoke { pub status: i32, } +/// Ask your dad #[poise::command(prefix_command, category = "Joke")] pub async fn dad_joke(ctx: Context<'_>) -> Result<(), Error> { let client = Client::new(); @@ -136,6 +135,7 @@ pub async fn random( Ok(()) } +/// Add a random command to the bot #[poise::command(prefix_command, category = "Joke")] pub async fn add_random( ctx: Context<'_>, @@ -143,7 +143,7 @@ pub async fn add_random( #[description = "Random message"] random_response: String, ) -> Result<(), Error> { if let Err(err) = - render_random(&ctx.author().display_name(), ctx.data(), &random_response).await + render_random(ctx.author().display_name(), ctx.data(), &random_response).await { ctx.reply(format!("Template failed test render, try again: {}", err)) .await?; @@ -155,6 +155,7 @@ pub async fn add_random( Ok(()) } +/// List all of the random sets #[poise::command(prefix_command, category = "Joke")] pub async fn list_random( ctx: Context<'_>, @@ -195,6 +196,7 @@ pub async fn list_random( Ok(()) } +/// Roll a totally not loaded digital die! #[poise::command(prefix_command, category = "Joke")] pub async fn roll( ctx: Context<'_>, @@ -214,6 +216,7 @@ pub async fn roll( Ok(()) } +/// Roll a totally not loaded, real actual die! (No joke) #[poise::command(prefix_command, category = "Joke")] pub async fn real_roll(ctx: Context<'_>) -> Result<(), Error> { let addr = ctx.data().cfg.raas_server.clone(); @@ -271,6 +274,7 @@ pub async fn real_roll(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Play critically the acclaimed Bad Apple music video as god intended #[poise::command(prefix_command, category = "Joke")] pub async fn bad_apple(ctx: Context<'_>) -> Result<(), Error> { let mut frames = BAD_APPLE.split('|'); @@ -311,6 +315,7 @@ pub async fn bad_apple(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Insult or compliment your "friends"! #[poise::command(prefix_command, category = "Joke", aliases("compliment"))] pub async fn insult( ctx: Context<'_>, @@ -355,6 +360,7 @@ fn get_unicode_emojis() -> Vec { emoji.iter().map(|e| e.to_string()).collect() } +/// Stare into the digital black mirror and see what it reflects #[poise::command(prefix_command, category = "Joke", aliases("🎱"))] pub async fn emoji_8ball( ctx: Context<'_>, diff --git a/src/discord/little_fren.rs b/src/discord/little_fren.rs index e3990ae..01c6a38 100644 --- a/src/discord/little_fren.rs +++ b/src/discord/little_fren.rs @@ -7,6 +7,7 @@ use poise::serenity_prelude::utils::MessageBuilder; use rand::prelude::IndexedRandom; use rand::{rng, Rng}; +/// Adopt a new little buddy! #[poise::command(prefix_command, guild_only, category = "Lil Buddy")] pub async fn adopt( ctx: Context<'_>, @@ -34,6 +35,7 @@ pub async fn adopt( Ok(()) } +/// Checkup on your little buddy! #[poise::command(prefix_command, guild_only, category = "Lil Buddy")] pub async fn checkup(ctx: Context<'_>) -> Result<(), Error> { let lil_fren = LilFren::get_lil_fren(&ctx.data().db)?; @@ -82,6 +84,7 @@ pub async fn checkup(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Feed your little buddy something totally normal! #[poise::command(prefix_command, guild_only, category = "Lil Buddy")] pub async fn feed( ctx: Context<'_>, @@ -91,7 +94,7 @@ pub async fn feed( if let Some(mut lil_fren) = lil_fren { if lil_fren.is_alive() == AliveState::Alive { - let feed: f32 = rng().gen_range(-0.1..=1.0); + let feed: f32 = rng().random_range(-0.1..=1.0); lil_fren.hunger = (lil_fren.hunger + feed).clamp(-1.0, 1.0); let guild = ctx.guild_id().unwrap(); @@ -117,6 +120,7 @@ pub async fn feed( Ok(()) } +/// Give your little buddy the juice of life. #[poise::command(prefix_command, guild_only, category = "Lil Buddy")] pub async fn give_water(ctx: Context<'_>) -> Result<(), Error> { let lil_fren = LilFren::get_lil_fren(&ctx.data().db)?; @@ -149,6 +153,7 @@ pub async fn give_water(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Play with little buddy before he shreds up the remote again #[poise::command(prefix_command, guild_only, category = "Lil Buddy")] pub async fn play(ctx: Context<'_>) -> Result<(), Error> { let lil_fren = LilFren::get_lil_fren(&ctx.data().db)?; @@ -175,6 +180,7 @@ pub async fn play(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Give your little buddy medicine #[poise::command(prefix_command, guild_only, category = "Lil Buddy")] pub async fn give_medicine(ctx: Context<'_>) -> Result<(), Error> { let lil_fren = LilFren::get_lil_fren(&ctx.data().db)?; diff --git a/src/discord/mod.rs b/src/discord/mod.rs index fe45eb7..58204bd 100644 --- a/src/discord/mod.rs +++ b/src/discord/mod.rs @@ -55,7 +55,7 @@ async fn event_handler( { info!("Starting lil buddy task..."); let data = data.clone(); - tokio::spawn(async move { lil_fren_task(data) }); + tokio::spawn(async move { lil_fren_task(data).await }); } } serenity::FullEvent::Message { new_message } => { @@ -155,6 +155,18 @@ async fn pre_command(ctx: Context<'_>) { ); } +#[poise::command(prefix_command)] +pub async fn help(ctx: Context<'_>, command: Option) -> Result<(), Error> { + let configuration = poise::builtins::HelpConfiguration { + extra_text_at_bottom: "Made with 💖 by Joey", + include_description: false, + ..Default::default() + }; + poise::builtins::help(ctx, command.as_deref(), configuration).await?; + Ok(()) +} + + pub async fn run_bot(global_data: GlobalData) { let framework_options: FrameworkOptions, Error> = poise::FrameworkOptions { prefix_options: poise::PrefixFrameworkOptions { @@ -165,6 +177,7 @@ pub async fn run_bot(global_data: GlobalData) { ..Default::default() }, commands: vec![ + help(), admin::dump_db(), admin::load_db(), admin::add_key(), diff --git a/src/discord/motivate.rs b/src/discord/motivate.rs index 0c4e19e..1b7f3f0 100644 --- a/src/discord/motivate.rs +++ b/src/discord/motivate.rs @@ -57,6 +57,7 @@ pub async fn create_motivation_image(motivation: Motivation) -> Result, Ok(wand.write_image_blob("jpg")?) } +/// Become motivated #[poise::command(prefix_command, category = "Motivation")] pub async fn motivation( ctx: Context<'_>, @@ -87,6 +88,7 @@ pub async fn motivation( Ok(()) } +/// Add an album to the pool of images to be used for motivations #[poise::command(prefix_command, category = "Motivation")] pub async fn motivation_add_album( ctx: Context<'_>, diff --git a/src/discord/shop.rs b/src/discord/shop.rs index 0a9aa61..4a3ee08 100644 --- a/src/discord/shop.rs +++ b/src/discord/shop.rs @@ -9,7 +9,6 @@ use crate::user::{User, UserError}; use poise::serenity_prelude::all::{ parse_user_mention, CreateAttachment, CreateMessage, EditRole, GuildId, Member, }; -use poise::serenity_prelude::model::channel::Message; use poise::serenity_prelude::model::Colour; use poise::serenity_prelude::prelude::Mentionable; use poise::serenity_prelude::utils::MessageBuilder; @@ -20,6 +19,7 @@ use std::hash::Hasher; use std::sync::Arc; use tokio::io::AsyncWriteExt; +/// Shop at a real virtual shop in the Metaverse! #[poise::command(prefix_command, category = "Shop")] pub async fn shop(ctx: Context<'_>) -> Result<(), Error> { let bot_user = User::get_user(&ctx.data().db, ctx.cache().current_user().id)?; @@ -40,6 +40,7 @@ pub async fn shop(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Look at your inventory, this button is forced bound to any key other than "B" #[poise::command(prefix_command, category = "Shop")] pub async fn inventory(ctx: Context<'_>) -> Result<(), Error> { let mut inv_msg = MessageBuilder::new(); @@ -59,6 +60,7 @@ pub async fn inventory(ctx: Context<'_>) -> Result<(), Error> { Ok(()) } +/// Buy an item from the shop with your hard earned cash #[poise::command(prefix_command, category = "Shop")] pub async fn buy( ctx: Context<'_>, @@ -84,7 +86,7 @@ pub async fn buy( ctx.reply(resp).await?; } else { - return Err(err.into()); + return Err(err); } } else { ctx.reply(format!("Congrats, you now own a '{}'", item)) @@ -150,6 +152,7 @@ async fn blockable_item( } } +/// Use an item and hope it doesn't use you #[poise::command(prefix_command, category = "Shop", guild_only, aliases("use"))] pub async fn use_item( ctx: Context<'_>, @@ -323,6 +326,7 @@ pub async fn use_item( Ok(()) } +/// Sell an item for profit #[poise::command(prefix_command, category = "Shop", aliases("sell"))] pub async fn sell_item( ctx: Context<'_>, @@ -359,17 +363,19 @@ pub async fn sell_item( _ => {} } } else { - return Err(err.into()); + return Err(err); } } } Ok(()) } + +/// Get help on what an item does #[poise::command(prefix_command, category = "Shop")] pub async fn item_help( ctx: Context<'_>, - #[description = "I"] + #[description = "Item to get help on"] #[rest] item: ItemType, ) -> Result<(), Error> { diff --git a/src/discord/voices.rs b/src/discord/voices.rs index 2657102..35818c4 100644 --- a/src/discord/voices.rs +++ b/src/discord/voices.rs @@ -1,10 +1,8 @@ use crate::discord::Context; use crate::error::Error; -use magick_rust::bindings::wchar_t; use poise::async_trait; use poise::serenity_prelude::all::CreateAttachment; use poise::serenity_prelude::builder::CreateMessage; -use poise::serenity_prelude::model::channel::Message; use poise::serenity_prelude::model::id::UserId; use poise::serenity_prelude::model::prelude::GuildId; use poise::serenity_prelude::utils::MessageBuilder; @@ -132,7 +130,7 @@ pub async fn speak( voice: &str, phrase: &str, ) -> Result<(), VoiceError> { - let _ = ctx.data().speak_lock.lock(); + let _ = ctx.data().speak_lock.lock().await; let voice_path = match find_voice(&ctx.data().cfg.voice_path, voice).await.unwrap() { None => return Err(VoiceError::VoiceNotFound(voice.to_string())), @@ -231,6 +229,7 @@ pub async fn speak( Ok(()) } +/// Speak in the language of the gods #[poise::command(prefix_command, category = "Voice", guild_only)] pub async fn say( ctx: Context<'_>, @@ -296,6 +295,7 @@ pub async fn list_words( Ok(()) } +/// List all voices the bot has #[poise::command(prefix_command, category = "Voice", guild_only)] pub async fn list_voices(ctx: Context<'_>) -> Result<(), Error> { let mut voice_message = MessageBuilder::new(); diff --git a/src/error.rs b/src/error.rs index fca2f38..c99f4dd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,7 +2,7 @@ use crate::discord::voices::VoiceError; use crate::user; use magick_rust::MagickError; use serde::ser::StdError; -use std::fmt::{write, Display, Formatter}; +use std::fmt::{Display, Formatter}; #[derive(Debug)] #[allow(clippy::enum_variant_names)] diff --git a/src/main.rs b/src/main.rs index 6ea5e63..8ccfe2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,9 +9,8 @@ mod user; use crate::config::{Args, BotConfig, GlobalData}; use crate::discord::run_bot; -use log::{error, info, LevelFilter}; +use log::{error, info}; use magick_rust::magick_wand_genesis; -use songbird::SerenityInit; use std::sync::Once; use structopt::StructOpt; diff --git a/src/models/api_key.rs b/src/models/api_key.rs index 705ac3f..b264be5 100644 --- a/src/models/api_key.rs +++ b/src/models/api_key.rs @@ -62,6 +62,8 @@ impl Apikey { general_purpose::STANDARD_NO_PAD.encode(hash) } + + #[allow(dead_code)] pub fn find_key_from_secret(db: &Database, secret: &str) -> Result, Error> { let hash = Self::hash_secret(secret); diff --git a/src/models/insult_compliment.rs b/src/models/insult_compliment.rs index 252f9e2..8a766ff 100644 --- a/src/models/insult_compliment.rs +++ b/src/models/insult_compliment.rs @@ -3,7 +3,6 @@ use j_db::database::Database; use j_db::model::JdbModel; use rand::prelude::IndexedRandom; use rand::rng; -use rand::seq::SliceRandom; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use tera::{Context, Tera}; diff --git a/src/models/lil_fren.rs b/src/models/lil_fren.rs index d19b8eb..c6ad012 100644 --- a/src/models/lil_fren.rs +++ b/src/models/lil_fren.rs @@ -194,7 +194,7 @@ pub enum LilFrenState { impl Distribution for StandardUniform { fn sample(&self, rng: &mut R) -> LilFrenState { - match rng.gen_range(0..10) { + match rng.random_range(0..10) { 0 => LilFrenState::Standing, 1 => LilFrenState::TaxFraud, 2 => LilFrenState::Sick, @@ -253,8 +253,8 @@ impl LilFren { thirst: 1.0, entertainment: 1.0, state: LilFrenState::Standing, - smarts: rng().gen_range(0.0..0.5), - metabolism: rng().gen_range(0.2..0.75), + smarts: rng().random_range(0.0..0.5), + metabolism: rng().random_range(0.2..0.75), } } diff --git a/src/models/race.rs b/src/models/race.rs index 8af2640..b48521e 100644 --- a/src/models/race.rs +++ b/src/models/race.rs @@ -1,7 +1,6 @@ use crate::error::Error; use crate::user::UserError; use j_db::database::Database; -use j_db::error::JDbError; use j_db::model::JdbModel; use poise::serenity_prelude::{Emoji, EmojiId, MessageBuilder, UserId}; use rand::{rng, Rng}; @@ -134,7 +133,7 @@ impl Racer { } pub fn update_pos(&mut self) { - let speed_boost = rng().gen_range(-0.75..0.75); + let speed_boost = rng().random_range(-0.75..0.75); self.pos += self.speed + (self.speed * speed_boost); self.pos = self.pos.clamp(0.0, RACE_SIZE as f32); diff --git a/src/models/random.rs b/src/models/random.rs index 16f50d0..7ef520c 100644 --- a/src/models/random.rs +++ b/src/models/random.rs @@ -3,7 +3,7 @@ use j_db::database::Database; use j_db::model::JdbModel; use rand::distr::weighted::WeightedIndex; use rand::prelude::Distribution; -use rand::thread_rng; +use rand::rng; use serde::{Deserialize, Serialize}; use std::collections::HashSet; @@ -115,7 +115,7 @@ impl RandomConfig { let dist = WeightedIndex::new(responses.iter().map(|r| r.score)).unwrap(); - let mut resp = responses[dist.sample(&mut thread_rng())].clone(); + let mut resp = responses[dist.sample(&mut rng())].clone(); resp.score = resp.score.saturating_sub(1);