diff --git a/build.rs b/build.rs index 5cd6329..9331c6d 100644 --- a/build.rs +++ b/build.rs @@ -54,7 +54,7 @@ fn main() { r#" #[allow(non_camel_case_types, clippy::upper_case_acronyms)] #[derive(Clone, Debug, poise::ChoiceParameter)] - pub enum TagChoice {{ + pub enum Choice {{ {} }}"#, formatted_names.join(",\n") @@ -62,7 +62,7 @@ fn main() { let to_str = format!( r#" - impl TagChoice {{ + impl Choice {{ fn as_str(&self) -> &str {{ match &self {{ {} diff --git a/src/api/dadjoke.rs b/src/api/dadjoke.rs index c0eed87..aecbb5e 100644 --- a/src/api/dadjoke.rs +++ b/src/api/dadjoke.rs @@ -1,7 +1,7 @@ use crate::api::REQWEST_CLIENT; use color_eyre::eyre::{eyre, Result}; -use log::*; +use log::debug; use reqwest::StatusCode; const DADJOKE: &str = "https://icanhazdadjoke.com"; diff --git a/src/api/pluralkit.rs b/src/api/pluralkit.rs index 439670a..9370418 100644 --- a/src/api/pluralkit.rs +++ b/src/api/pluralkit.rs @@ -1,7 +1,7 @@ use crate::api::REQWEST_CLIENT; use color_eyre::eyre::{eyre, Context, Result}; -use log::*; +use log::debug; use poise::serenity_prelude::{MessageId, UserId}; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/prism_meta.rs b/src/api/prism_meta.rs index 7e24d08..aaa21ea 100644 --- a/src/api/prism_meta.rs +++ b/src/api/prism_meta.rs @@ -1,7 +1,7 @@ use crate::api::REQWEST_CLIENT; use color_eyre::eyre::{eyre, Context, Result}; -use log::*; +use log::debug; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; diff --git a/src/api/rory.rs b/src/api/rory.rs index e527bba..7dd95c5 100644 --- a/src/api/rory.rs +++ b/src/api/rory.rs @@ -1,12 +1,12 @@ use crate::api::REQWEST_CLIENT; use color_eyre::eyre::{eyre, Context, Result}; -use log::*; +use log::debug; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] -pub struct RoryResponse { +pub struct Response { pub id: u64, pub url: String, pub error: Option, @@ -15,7 +15,7 @@ pub struct RoryResponse { const RORY: &str = "https://rory.cat"; const ENDPOINT: &str = "/purr"; -pub async fn get_rory(id: Option) -> Result { +pub async fn get(id: Option) -> Result { let target = id.map(|id| id.to_string()).unwrap_or_default(); let req = REQWEST_CLIENT @@ -33,7 +33,7 @@ pub async fn get_rory(id: Option) -> Result { if let StatusCode::OK = status { let data = resp - .json::() + .json::() .await .wrap_err_with(|| "Couldn't parse the rory response!")?; diff --git a/src/commands/general/rory.rs b/src/commands/general/rory.rs index 6bddc5f..5047a83 100644 --- a/src/commands/general/rory.rs +++ b/src/commands/general/rory.rs @@ -1,4 +1,4 @@ -use crate::api::rory::get_rory; +use crate::api::rory; use crate::Context; use color_eyre::eyre::Result; @@ -11,7 +11,7 @@ pub async fn rory( ctx: Context<'_>, #[description = "specify a Rory ID"] id: Option, ) -> Result<()> { - let rory = get_rory(id).await?; + let rory = rory::get(id).await?; let embed = { let embed = CreateEmbed::new(); diff --git a/src/commands/general/tag.rs b/src/commands/general/tag.rs index 4273d03..d07c821 100644 --- a/src/commands/general/tag.rs +++ b/src/commands/general/tag.rs @@ -15,7 +15,7 @@ static TAGS: Lazy> = Lazy::new(|| serde_json::from_str(env!("TAGS")).un #[poise::command(slash_command, prefix_command)] pub async fn tag( ctx: Context<'_>, - #[description = "the copypasta you want to send"] name: TagChoice, + #[description = "the copypasta you want to send"] name: Choice, user: Option, ) -> Result<()> { let tag_file = name.as_str(); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 0a2293f..c13691d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -5,7 +5,7 @@ use poise::Command; mod general; -pub fn to_global_commands() -> Vec> { +pub fn get() -> Vec> { vec![ general::joke(), general::members(), diff --git a/src/config/discord.rs b/src/config/discord.rs index 1201c83..0e1ea7e 100644 --- a/src/config/discord.rs +++ b/src/config/discord.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use log::*; +use log::{info, warn}; use poise::serenity_prelude::ChannelId; #[derive(Debug, Clone, Default)] @@ -9,7 +9,7 @@ pub struct RefractionChannels { } #[derive(Debug, Clone, Default)] -pub struct DiscordConfig { +pub struct Config { pub channels: RefractionChannels, } @@ -33,7 +33,7 @@ impl RefractionChannels { } } -impl DiscordConfig { +impl Config { pub fn new_from_env() -> Self { let channels = RefractionChannels::new_from_env(); diff --git a/src/config/mod.rs b/src/config/mod.rs index 156da9a..11bcf09 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,16 +1,15 @@ mod discord; -use discord::DiscordConfig; #[derive(Debug, Clone)] pub struct Config { - pub discord: DiscordConfig, + pub discord: discord::Config, pub redis_url: String, } impl Default for Config { fn default() -> Self { Self { - discord: DiscordConfig::default(), + discord: discord::Config::default(), redis_url: "redis://localhost:6379".to_string(), } } @@ -18,7 +17,7 @@ impl Default for Config { impl Config { pub fn new_from_env() -> Self { - let discord = DiscordConfig::new_from_env(); + let discord = discord::Config::new_from_env(); Self { discord, diff --git a/src/handlers/error.rs b/src/handlers/error.rs index 1d0cc2c..2884ed9 100644 --- a/src/handlers/error.rs +++ b/src/handlers/error.rs @@ -2,7 +2,7 @@ use crate::consts::COLORS; use crate::Data; use color_eyre::eyre::Report; -use log::*; +use log::error; use poise::serenity_prelude::{CreateEmbed, Timestamp}; use poise::{CreateReply, FrameworkError}; diff --git a/src/handlers/event/analyze_logs/issues.rs b/src/handlers/event/analyze_logs/issues.rs index 191e597..79968dd 100644 --- a/src/handlers/event/analyze_logs/issues.rs +++ b/src/handlers/event/analyze_logs/issues.rs @@ -6,7 +6,7 @@ use regex::Regex; pub type Issue = Option<(String, String)>; -pub async fn find_issues(log: &str, data: &Data) -> Result> { +pub async fn find(log: &str, data: &Data) -> Result> { let issues = [ fabric_internal, flatpak_nvidia, @@ -24,7 +24,7 @@ pub async fn find_issues(log: &str, data: &Data) -> Result let mut res: Vec<(String, String)> = issues.iter().filter_map(|issue| issue(log)).collect(); if let Some(issues) = outdated_launcher(log, data).await? { - res.push(issues) + res.push(issues); } Ok(res) diff --git a/src/handlers/event/analyze_logs/mod.rs b/src/handlers/event/analyze_logs/mod.rs index d8823d2..aa25679 100644 --- a/src/handlers/event/analyze_logs/mod.rs +++ b/src/handlers/event/analyze_logs/mod.rs @@ -2,7 +2,7 @@ use crate::consts::COLORS; use crate::Data; use color_eyre::eyre::Result; -use log::*; +use log::debug; use poise::serenity_prelude::{ Context, CreateAllowedMentions, CreateEmbed, CreateMessage, Message, }; @@ -10,7 +10,6 @@ use poise::serenity_prelude::{ mod issues; mod providers; -use issues::find_issues; use providers::find_log; pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()> { @@ -38,7 +37,7 @@ pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()> return Ok(()); }; - let issues = find_issues(&log, data).await?; + let issues = issues::find(&log, data).await?; let embed = { let mut e = CreateEmbed::new().title("Log analysis"); diff --git a/src/handlers/event/mod.rs b/src/handlers/event/mod.rs index a916ed0..5ad4baa 100644 --- a/src/handlers/event/mod.rs +++ b/src/handlers/event/mod.rs @@ -1,7 +1,7 @@ use crate::{api, Data}; use color_eyre::eyre::{Report, Result}; -use log::*; +use log::{debug, info}; use poise::serenity_prelude::{ActivityData, Context, FullEvent, OnlineStatus}; use poise::FrameworkContext; @@ -23,7 +23,7 @@ pub async fn handle( info!("Logged in as {}!", data_about_bot.user.name); let latest_minecraft_version = api::prism_meta::get_latest_minecraft_version().await?; - let activity = ActivityData::playing(format!("Minecraft {}", latest_minecraft_version)); + let activity = ActivityData::playing(format!("Minecraft {latest_minecraft_version}")); info!("Setting presence to activity {activity:#?}"); ctx.set_presence(Some(activity), OnlineStatus::Online); diff --git a/src/handlers/event/pluralkit.rs b/src/handlers/event/pluralkit.rs index 0fdaf3c..12f3fc7 100644 --- a/src/handlers/event/pluralkit.rs +++ b/src/handlers/event/pluralkit.rs @@ -2,7 +2,7 @@ use crate::{api, Data}; use std::time::Duration; use color_eyre::eyre::Result; -use log::*; +use log::debug; use poise::serenity_prelude::{Context, Message}; use tokio::time::sleep; diff --git a/src/handlers/event/support_onboard.rs b/src/handlers/event/support_onboard.rs index be08309..3c7a6a1 100644 --- a/src/handlers/event/support_onboard.rs +++ b/src/handlers/event/support_onboard.rs @@ -1,5 +1,5 @@ use color_eyre::eyre::{eyre, Result}; -use log::*; +use log::debug; use poise::serenity_prelude::{ ChannelType, Context, CreateAllowedMentions, CreateMessage, GuildChannel, }; @@ -15,7 +15,7 @@ pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> { .ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))? .name(ctx) .await - .unwrap_or("".to_string()) + .unwrap_or(String::new()) != "support" { debug!("Not posting onboarding message to threads outside of support"); diff --git a/src/main.rs b/src/main.rs index 9cf8bd6..31051ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,14 @@ +#![warn(clippy::all, clippy::pedantic, clippy::perf)] +#![allow(clippy::missing_errors_doc)] +#![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 as serenity, EditTracker, Framework, FrameworkOptions, PrefixFrameworkOptions, @@ -78,7 +82,7 @@ async fn setup( async fn handle_shutdown(shard_manager: Arc, reason: &str) { warn!("{reason}! Shutting down bot..."); shard_manager.shutdown_all().await; - println!("{}", "Everything is shutdown. Goodbye!".green()) + println!("{}", "Everything is shutdown. Goodbye!".green()); } #[tokio::main] @@ -94,7 +98,7 @@ async fn main() -> Result<()> { serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT; let options = FrameworkOptions { - commands: commands::to_global_commands(), + commands: commands::get(), on_error: |error| Box::pin(handlers::handle_error(error)), diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 313aebc..ab2c63a 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, info}; use poise::serenity_prelude::UserId; use redis::{AsyncCommands as _, Client, FromRedisValue, ToRedisArgs}; diff --git a/src/utils/resolve_message.rs b/src/utils/resolve_message.rs index b29de97..f20d337 100644 --- a/src/utils/resolve_message.rs +++ b/src/utils/resolve_message.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use color_eyre::eyre::{eyre, Context as _, Result}; -use log::*; +use log::debug; use once_cell::sync::Lazy; use poise::serenity_prelude::{ ChannelId, ChannelType, Colour, Context, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, @@ -19,7 +19,7 @@ pub fn find_first_image(msg: &Message) -> Option { .find(|a| { a.content_type .as_ref() - .unwrap_or(&"".to_string()) + .unwrap_or(&String::new()) .starts_with("image/") }) .map(|res| res.url.clone())