diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/guzzle.rs | 2 | ||||
| -rw-r--r-- | src/api/shiggy.rs | 3 | ||||
| -rw-r--r-- | src/commands/general/ask.rs | 4 | ||||
| -rw-r--r-- | src/commands/general/config.rs | 43 | ||||
| -rw-r--r-- | src/commands/general/convert.rs | 1 | ||||
| -rw-r--r-- | src/commands/general/random.rs | 1 | ||||
| -rw-r--r-- | src/commands/mod.rs | 4 | ||||
| -rw-r--r-- | src/commands/optional/copypasta.rs | 8 | ||||
| -rw-r--r-- | src/commands/optional/teawiespam.rs | 2 | ||||
| -rw-r--r-- | src/handlers/error.rs | 2 | ||||
| -rw-r--r-- | src/handlers/event/guild.rs | 2 | ||||
| -rw-r--r-- | src/handlers/event/message.rs | 2 | ||||
| -rw-r--r-- | src/handlers/event/mod.rs | 4 | ||||
| -rw-r--r-- | src/handlers/event/pinboard.rs | 6 | ||||
| -rw-r--r-- | src/handlers/event/reactboard.rs | 6 | ||||
| -rw-r--r-- | src/main.rs | 12 | ||||
| -rw-r--r-- | src/storage/mod.rs | 4 | ||||
| -rw-r--r-- | src/storage/settings.rs | 2 | ||||
| -rw-r--r-- | src/utils.rs | 3 |
19 files changed, 55 insertions, 56 deletions
diff --git a/src/api/guzzle.rs b/src/api/guzzle.rs index 2f2571a..9365151 100644 --- a/src/api/guzzle.rs +++ b/src/api/guzzle.rs @@ -1,7 +1,7 @@ use crate::api::REQWEST_CLIENT; use color_eyre::eyre::{eyre, Result}; -use log::*; +use log::debug; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/shiggy.rs b/src/api/shiggy.rs index fb955bb..d69f32b 100644 --- a/src/api/shiggy.rs +++ b/src/api/shiggy.rs @@ -1,7 +1,7 @@ use crate::api::REQWEST_CLIENT; use color_eyre::eyre::{eyre, Result}; -use log::*; +use log::debug; use reqwest::StatusCode; use serde::Deserialize; @@ -13,6 +13,7 @@ struct SafebooruResponse { file_url: String, } +#[allow(clippy::module_name_repetitions)] pub async fn get_random_shiggy() -> Result<String> { let req = REQWEST_CLIENT .get(format!("{SHIGGY}{RANDOM_SHIGGY}")) diff --git a/src/commands/general/ask.rs b/src/commands/general/ask.rs index 3f225bb..ba18bdd 100644 --- a/src/commands/general/ask.rs +++ b/src/commands/general/ask.rs @@ -6,9 +6,7 @@ use color_eyre::eyre::{Context as _, Result}; #[poise::command(prefix_command, slash_command)] pub async fn ask( ctx: Context<'_>, - #[description = "The question you want to ask teawie"] - #[rename = "Question"] - _question: String, + #[description = "The question you want to ask teawie"] _question: String, ) -> Result<()> { let resp = utils::random_choice(consts::RESPONSES) .wrap_err("Couldn't choose from random responses!")?; diff --git a/src/commands/general/config.rs b/src/commands/general/config.rs index f308f31..358ee69 100644 --- a/src/commands/general/config.rs +++ b/src/commands/general/config.rs @@ -1,13 +1,13 @@ use std::str::FromStr; use crate::{storage, Context}; -use storage::{Settings, SettingsProperties}; +use storage::{Properties, Settings}; use color_eyre::eyre::{eyre, Result}; -use log::*; +use log::debug; use poise::serenity_prelude::{GuildChannel, ReactionType}; -fn split_argument<T>(list: String) -> Vec<T> +fn split_argument<T>(list: &str) -> Vec<T> where T: FromStr, { @@ -16,24 +16,23 @@ where .collect() } -fn prop_to_val(setting: &SettingsProperties, settings: &Settings) -> String { +fn prop_to_val(setting: &Properties, settings: &Settings) -> String { match setting { - SettingsProperties::GuildId => settings.guild_id.to_string(), - SettingsProperties::PinBoardChannel => format!("{:#?}", settings.pinboard_channel), - SettingsProperties::PinBoardWatch => format!("{:#?}", settings.pinboard_watch), - SettingsProperties::PinBoardEnabled => settings.pinboard_enabled.to_string(), - SettingsProperties::ReactBoardChannel => format!("{:#?}", settings.reactboard_channel), - SettingsProperties::ReactBoardRequirement => { + Properties::GuildId => settings.guild_id.to_string(), + Properties::PinBoardChannel => format!("{:#?}", settings.pinboard_channel), + Properties::PinBoardWatch => format!("{:#?}", settings.pinboard_watch), + Properties::PinBoardEnabled => settings.pinboard_enabled.to_string(), + Properties::ReactBoardChannel => format!("{:#?}", settings.reactboard_channel), + Properties::ReactBoardRequirement => { format!("{:?}", settings.reactboard_requirement) } - SettingsProperties::ReactBoardReactions => format!("{:?}", settings.reactboard_reactions), - SettingsProperties::ReactBoardEnabled => settings.reactboard_enabled.to_string(), - SettingsProperties::OptionalCommandsEnabled => { - settings.optional_commands_enabled.to_string() - } + Properties::ReactBoardReactions => format!("{:?}", settings.reactboard_reactions), + Properties::ReactBoardEnabled => settings.reactboard_enabled.to_string(), + Properties::OptionalCommandsEnabled => settings.optional_commands_enabled.to_string(), } } +#[allow(clippy::unused_async)] #[poise::command( slash_command, prefix_command, @@ -84,7 +83,7 @@ pub async fn set( } if let Some(watch) = pinboard_watch { - let channels = split_argument(watch); + let channels = split_argument(&watch); debug!("Setting pinboard_watch to {channels:#?} for {gid}"); settings.pinboard_watch = Some(channels); @@ -123,14 +122,14 @@ pub async fn set( settings.optional_commands_enabled = enabled; } - if previous_settings != settings { - debug!("Updating settings key for {gid}"); - storage.create_guild_settings(settings).await?; - ctx.reply("Configuration updated!").await?; - } else { + if previous_settings == settings { debug!("Not updating settings key for {gid} since no changes were made"); ctx.reply("No changes made, so i'm not updating anything") .await?; + } else { + debug!("Updating settings key for {gid}"); + storage.create_guild_settings(settings).await?; + ctx.reply("Configuration updated!").await?; } Ok(()) @@ -146,7 +145,7 @@ pub async fn set( )] pub async fn get( ctx: Context<'_>, - #[description = "The setting you want to get"] setting: SettingsProperties, + #[description = "The setting you want to get"] setting: Properties, ) -> Result<()> { let gid = &ctx .guild_id() diff --git a/src/commands/general/convert.rs b/src/commands/general/convert.rs index c00b4b8..5c41dfd 100644 --- a/src/commands/general/convert.rs +++ b/src/commands/general/convert.rs @@ -3,6 +3,7 @@ use crate::Context; use bottomify::bottom; use color_eyre::eyre::Result; +#[allow(clippy::unused_async)] #[poise::command( slash_command, subcommands("to_fahrenheit", "to_celsius", "to_bottom", "from_bottom") diff --git a/src/commands/general/random.rs b/src/commands/general/random.rs index 286d04e..477001e 100644 --- a/src/commands/general/random.rs +++ b/src/commands/general/random.rs @@ -2,6 +2,7 @@ use crate::{api, consts, utils, Context}; use color_eyre::eyre::Result; +#[allow(clippy::unused_async)] #[poise::command(slash_command, subcommands("lore", "teawie", "shiggy"))] pub async fn random(_ctx: Context<'_>) -> Result<()> { Ok(()) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index df2d857..b20258c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -6,10 +6,10 @@ use poise::Command; mod general; mod optional; -pub fn to_global_commands() -> Vec<Command<Data, Report>> { +pub fn global() -> Vec<Command<Data, Report>> { general::to_comands() } -pub fn to_optional_commands() -> Vec<Command<Data, Report>> { +pub fn optional() -> Vec<Command<Data, Report>> { optional::to_commands() } diff --git a/src/commands/optional/copypasta.rs b/src/commands/optional/copypasta.rs index 54b6194..6ed4f95 100644 --- a/src/commands/optional/copypasta.rs +++ b/src/commands/optional/copypasta.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use color_eyre::eyre::{eyre, Result}; use include_dir::{include_dir, Dir}; -use log::*; +use log::debug; const FILES: Dir = include_dir!("src/copypastas"); @@ -34,7 +34,7 @@ impl Copypastas { } } -fn get_copypasta(name: Copypastas) -> Result<String> { +fn get_copypasta(name: &Copypastas) -> Result<String> { let mut files: HashMap<&str, &str> = HashMap::new(); for file in FILES.files() { @@ -66,8 +66,6 @@ pub async fn copypasta( ctx: Context<'_>, #[description = "the copypasta you want to send"] copypasta: Copypastas, ) -> Result<()> { - debug!("Running copypasta command with copypasta {copypasta}"); - let gid = ctx.guild_id().unwrap_or_default(); let settings = ctx.data().storage.get_guild_settings(&gid).await?; @@ -76,7 +74,7 @@ pub async fn copypasta( return Ok(()); } - ctx.say(get_copypasta(copypasta)?).await?; + ctx.say(get_copypasta(©pasta)?).await?; Ok(()) } diff --git a/src/commands/optional/teawiespam.rs b/src/commands/optional/teawiespam.rs index a876d09..fd635ff 100644 --- a/src/commands/optional/teawiespam.rs +++ b/src/commands/optional/teawiespam.rs @@ -1,7 +1,7 @@ use crate::Context; use color_eyre::eyre::Result; -use log::*; +use log::debug; /// teawie will spam you. #[poise::command(slash_command, prefix_command)] diff --git a/src/handlers/error.rs b/src/handlers/error.rs index 48cb421..034e870 100644 --- a/src/handlers/error.rs +++ b/src/handlers/error.rs @@ -2,7 +2,7 @@ use crate::colors::Colors; use crate::Data; use color_eyre::eyre::Report; -use log::*; +use log::error; use poise::serenity_prelude::Timestamp; use poise::FrameworkError; diff --git a/src/handlers/event/guild.rs b/src/handlers/event/guild.rs index 4583688..f8bd306 100644 --- a/src/handlers/event/guild.rs +++ b/src/handlers/event/guild.rs @@ -1,5 +1,5 @@ use color_eyre::eyre::Result; -use log::*; +use log::{debug, warn}; use poise::serenity_prelude::{Guild, UnavailableGuild}; use crate::{storage, Data}; diff --git a/src/handlers/event/message.rs b/src/handlers/event/message.rs index 4fd1323..946e596 100644 --- a/src/handlers/event/message.rs +++ b/src/handlers/event/message.rs @@ -1,7 +1,7 @@ use crate::{consts, Data}; use color_eyre::eyre::{eyre, Report, Result}; -use log::*; +use log::debug; use poise::serenity_prelude::{Context, Message}; use poise::FrameworkContext; diff --git a/src/handlers/event/mod.rs b/src/handlers/event/mod.rs index 5abbfb4..63060e5 100644 --- a/src/handlers/event/mod.rs +++ b/src/handlers/event/mod.rs @@ -1,7 +1,7 @@ use crate::Data; use color_eyre::eyre::{Report, Result}; -use log::*; +use log::info; use poise::serenity_prelude as serenity; use poise::{Event, FrameworkContext}; @@ -22,7 +22,7 @@ pub async fn handle( } Event::Message { new_message } => { - message::handle(ctx, framework, new_message, data).await? + message::handle(ctx, framework, new_message, data).await?; } Event::ChannelPinsUpdate { pin } => pinboard::handle(ctx, pin, data).await?, diff --git a/src/handlers/event/pinboard.rs b/src/handlers/event/pinboard.rs index 4a1dad7..4f09e3b 100644 --- a/src/handlers/event/pinboard.rs +++ b/src/handlers/event/pinboard.rs @@ -1,7 +1,7 @@ use crate::{utils, Data}; use color_eyre::eyre::{Context as _, Result}; -use log::*; +use log::{debug, warn}; use poise::serenity_prelude::model::prelude::*; use poise::serenity_prelude::Context; @@ -14,9 +14,7 @@ pub async fn handle(ctx: &Context, pin: &ChannelPinsUpdateEvent, data: &Data) -> return Ok(()); } - let target = if let Some(target) = settings.pinboard_channel { - target - } else { + let Some(target) = settings.pinboard_channel else { debug!("PinBoard is disabled in {gid}, ignoring"); return Ok(()); }; diff --git a/src/handlers/event/reactboard.rs b/src/handlers/event/reactboard.rs index 7550c6a..7341565 100644 --- a/src/handlers/event/reactboard.rs +++ b/src/handlers/event/reactboard.rs @@ -2,7 +2,7 @@ use crate::{storage, utils, Data}; use storage::ReactBoardEntry; use color_eyre::eyre::{eyre, Context as _, Result}; -use log::*; +use log::debug; use poise::serenity_prelude::{Context, GuildId, Message, MessageReaction, Reaction}; pub async fn handle(ctx: &Context, reaction: &Reaction, data: &Data) -> Result<()> { @@ -52,9 +52,7 @@ async fn send_to_reactboard( return Ok(()); } - let target = if let Some(target) = settings.reactboard_channel { - target - } else { + let Some(target) = settings.reactboard_channel else { debug!("ReactBoard is disabled in {guild_id}, ignoring"); return Ok(()); }; diff --git a/src/main.rs b/src/main.rs index 42d7c78..46fadfb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,13 @@ +#![warn(clippy::all, clippy::pedantic, clippy::perf)] +#![allow(clippy::missing_errors_doc, clippy::used_underscore_binding)] +#![forbid(unsafe_code)] + use std::sync::Arc; use std::time::Duration; use color_eyre::eyre::{eyre, Context as _, Report, Result}; use color_eyre::owo_colors::OwoColorize; -use log::*; +use log::{info, warn}; use poise::serenity_prelude::{self as serenity, ShardManager}; use poise::{EditTracker, Framework, FrameworkOptions, PrefixFrameworkOptions}; use redis::ConnectionLike; @@ -60,7 +64,7 @@ async fn setup( let guilds = data.storage.get_opted_guilds().await?; for guild in guilds { - poise::builtins::register_in_guild(ctx, &commands::to_optional_commands(), guild).await?; + poise::builtins::register_in_guild(ctx, &commands::optional(), guild).await?; info!("Registered guild commands to {}", guild); } @@ -87,8 +91,8 @@ async fn main() -> Result<()> { let options = FrameworkOptions { commands: { - let mut commands = commands::to_global_commands(); - commands.append(&mut commands::to_optional_commands()); + let mut commands = commands::global(); + commands.append(&mut commands::optional()); commands }, on_error: |error| Box::pin(handlers::handle_error(error)), diff --git a/src/storage/mod.rs b/src/storage/mod.rs index c179884..a013500 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -1,7 +1,7 @@ use std::fmt::Debug; use color_eyre::eyre::Result; -use log::*; +use log::debug; use poise::serenity_prelude::{GuildId, MessageId}; use redis::{AsyncCommands, Client, FromRedisValue, ToRedisArgs}; @@ -12,7 +12,7 @@ use reactboard::REACTBOARD_KEY; use settings::SETTINGS_KEY; pub use reactboard::ReactBoardEntry; -pub use settings::{Settings, SettingsProperties}; +pub use settings::{Properties, Settings}; #[derive(Clone, Debug)] pub struct Storage { diff --git a/src/storage/settings.rs b/src/storage/settings.rs index d60327f..76eacc7 100644 --- a/src/storage/settings.rs +++ b/src/storage/settings.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; pub const SETTINGS_KEY: &str = "settings-v1"; #[derive(poise::ChoiceParameter)] -pub enum SettingsProperties { +pub enum Properties { GuildId, PinBoardChannel, PinBoardWatch, diff --git a/src/utils.rs b/src/utils.rs index e4ac03e..1a96359 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,6 +19,7 @@ pub fn random_choice<const N: usize>(arr: [&str; N]) -> Result<String> { } // waiting for `round_char_boundary` to stabilize +#[allow(clippy::cast_possible_wrap)] pub fn floor_char_boundary(s: &str, index: usize) -> usize { if index >= s.len() { s.len() @@ -105,7 +106,7 @@ pub async fn resolve_message_to_embed(ctx: &serenity::Context, msg: &Message) -> if attachments_len > 1 { embed.footer(|footer| { // yes it will say '1 attachments' no i do not care - footer.text(format!("{} attachments", attachments_len)) + footer.text(format!("{attachments_len} attachments")) }); } |
