From 244dfac27084ae6503a35062187d1727098155bd Mon Sep 17 00:00:00 2001 From: shibedrill Date: Mon, 30 Sep 2024 20:36:44 -0400 Subject: [PATCH] Fixed some Clippy lints --- Cargo.lock | 2 +- Cargo.toml | 5 ++++- README.md | 2 +- src/command/fun.rs | 17 +++++++++-------- src/command/util.rs | 27 ++++++--------------------- src/main.rs | 12 ++++++------ src/settings.rs | 8 ++++---- 7 files changed, 31 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e68953f..a4f009a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1514,7 +1514,7 @@ dependencies = [ [[package]] name = "shibe-bot" -version = "0.3.0" +version = "0.3.1" dependencies = [ "build-time", "dotenvy", diff --git a/Cargo.toml b/Cargo.toml index ef308db..56e0c04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,9 @@ [package] name = "shibe-bot" -version = "0.3.0" +description = "A Discord bot written in Rust, using Poise." +license = "MIT" +readme = "README.md" +version = "0.3.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 1931201..e17538e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Shibe Bot 0.3.0 +# Shibe Bot 0.3.1 [![Rust](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml/badge.svg)](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml) [![GitHub License](https://img.shields.io/github/license/shibedrill/shibe-bot)](LICENSE.txt) diff --git a/src/command/fun.rs b/src/command/fun.rs index a68f861..abf4bd6 100644 --- a/src/command/fun.rs +++ b/src/command/fun.rs @@ -4,10 +4,10 @@ use crate::Error; use poise::serenity_prelude as serenity; use rand::prelude::SliceRandom; -use rand::*; +use rand::Rng; -use roux::util::*; -use roux::*; +use roux::util::{FeedOption, TimePeriod}; +use roux::Subreddit; /// mrow #[poise::command(slash_command)] @@ -31,11 +31,12 @@ pub async fn meow(ctx: Context<'_>) -> Result<(), Error> { ]; let response = { let mut rng = rand::thread_rng(); - match rng.gen_bool(0.05) { - true => "woof", + if rng.gen_bool(0.05) { + "woof" // Will never return None. The source is statically defined. // We know it will always have items in it. - false => meows + } else { + meows .choose(&mut rng) .ok_or("`meows` array is empty") .inspect_err(|e| { @@ -108,7 +109,7 @@ pub async fn eightball(ctx: Context<'_>) -> Result<(), Error> { .choose(&mut rng) .ok_or("Response array is empty".to_string()) .inspect_err(|e| { - error!("Executing command `eightball` failed: {}", e) + error!("Executing command `eightball` failed: {}", e); })? }; ctx.say(format!("Magic 8-ball says: '{}'", *response)) @@ -151,7 +152,7 @@ pub async fn deer(ctx: Context<'_>) -> Result<(), Error> { .choose(&mut rng) .ok_or("Unable to get any hot posts") .inspect_err(|e| { - error!("Executing command `deer` failed: {}", e) + error!("Executing command `deer` failed: {}", e); })? }; ctx.say(format!("https://vxreddit.com{}", &chosen_post.data.permalink)) diff --git a/src/command/util.rs b/src/command/util.rs index f93ae32..6aaa309 100644 --- a/src/command/util.rs +++ b/src/command/util.rs @@ -13,10 +13,9 @@ const INVITE_LINK: &str = "https://discord.com/oauth2/authorize?client_id=103070 pub async fn invite(ctx: Context<'_>) -> Result<(), Error> { ctx.defer_ephemeral().await?; ctx.say(format!( - "To add me to your server, click [this link]({}), or open it in the \ + "To add me to your server, click [this link]({INVITE_LINK}), or open it in the \ browser and enable all the requested permissions. Then select your \ server to add it.", - INVITE_LINK )) .await?; info!("Executed command `invite` successfully"); @@ -69,14 +68,11 @@ pub async fn add_channel( match config.channels.iter().find(|item| **item == channel_id) { None => { config.channels.push(channel_id); - ctx.say(format!( - "Successfully added <#{}> to the channel registry.", - channel_id - )) + ctx.say(format!("Successfully added <#{channel_id}> to the channel registry.")) .await?; } Some(_) => { - ctx.say(format!("Channel <#{}> is already in registry.", channel_id)) + ctx.say(format!("Channel <#{channel_id}> is already in registry.")) .await?; } } @@ -96,18 +92,12 @@ pub async fn remove_channel( let channel_id = { u64::from(channel.id()) }; match config.channels.iter().position(|item| *item == channel_id) { None => { - ctx.say(format!( - "Channel <#{}> was not in the channel registry.", - channel_id - )) + ctx.say(format!("Channel <#{channel_id}> was not in the channel registry.")) .await?; } Some(found) => { config.channels.remove(found); - ctx.say(format!( - "Successfully removed <#{}> from the channel registry.", - channel_id - )) + ctx.say(format!("Successfully removed <#{channel_id}> from the channel registry.")) .await?; } } @@ -155,12 +145,7 @@ pub async fn dice( } ) } - _ => { - format!( - "Rolled a random number from 1 to {}, got: {}", - sides, answer - ) - } + _ => format!("Rolled a random number from 1 to {sides}, got: {answer}") }; ctx.say(response).await?; info!("Executed command `dice` successfully"); diff --git a/src/main.rs b/src/main.rs index 0bf2647..a251cdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,9 +17,9 @@ extern crate pretty_env_logger; extern crate log; // For managing config storage -use serde::*; +use serde::{Deserialize, Serialize}; mod settings; -use crate::settings::*; +use crate::settings::Manager; // Bot commands mod command; @@ -34,7 +34,7 @@ use crate::command::{ // Data passed to every command (shared state) struct Data { - config_manager: Arc>>, + config_manager: Arc>>, } // Errors returnable by a command @@ -87,9 +87,9 @@ async fn main() { pretty_env_logger::init(); // Configure persistent options - let config_manager: Arc>> = Arc::new(Mutex::new( - SettingsManager::load(SETTINGS_PATH) - .unwrap_or(SettingsManager::manage(SETTINGS_PATH, Settings::default())), + let config_manager: Arc>> = Arc::new(Mutex::new( + Manager::load(SETTINGS_PATH) + .unwrap_or(Manager::manage(SETTINGS_PATH, Settings::default())), )); config_manager.lock().await.store(); diff --git a/src/settings.rs b/src/settings.rs index ca6947e..c3a7f33 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -5,12 +5,12 @@ use serde::de::Deserialize; use serde::ser::Serialize; /// A utility structure to manage a settings structure. -pub struct SettingsManager Deserialize<'a>> { +pub struct Manager Deserialize<'a>> { internal: T, path: String, } -impl Deserialize<'a>> SettingsManager { +impl Deserialize<'a>> Manager { /// Instantiate new self if the path contains a valid serialization of /// the settings structure. pub fn load(path: &str) -> Option { @@ -52,7 +52,7 @@ impl Deserialize<'a>> SettingsManager { } } -impl Deserialize<'a>> Deref for SettingsManager { +impl Deserialize<'a>> Deref for Manager { type Target = T; fn deref(&self) -> &Self::Target { @@ -60,7 +60,7 @@ impl Deserialize<'a>> Deref for SettingsManager } } -impl Deserialize<'a>> DerefMut for SettingsManager { +impl Deserialize<'a>> DerefMut for Manager { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.internal }