diff --git a/cipher_discord_bot/src/app/mod.rs b/cipher_discord_bot/src/app/mod.rs index 2d5e8be..8b77f3a 100644 --- a/cipher_discord_bot/src/app/mod.rs +++ b/cipher_discord_bot/src/app/mod.rs @@ -31,6 +31,8 @@ pub enum AppError { RepositoryError(#[from] RepositoryError), #[error("staff-only command used by non-staff user")] StaffOnly { command_name: String }, + #[error("unknown cache or http error")] + UnknownCacheOrHttpError, } pub type AppContext<'a, R, E> = poise::ApplicationContext<'a, AppData, AppError>; diff --git a/cipher_discord_bot/src/app/on_error.rs b/cipher_discord_bot/src/app/on_error.rs index 18a98d9..82eb73a 100644 --- a/cipher_discord_bot/src/app/on_error.rs +++ b/cipher_discord_bot/src/app/on_error.rs @@ -299,6 +299,12 @@ where format!("`/{}` can only be used by staff.", command_name), format!("staff-only command `{}` cannot be run by non-staff users", command_name), log::Level::Info, + ), + A::UnknownCacheOrHttpError => ErrorMessage::new( + "Unknown Cache or Http Error", + "Failed to get resource.", + "cache lookup or http request failed", + log::Level::Warn, ) } } diff --git a/cipher_discord_bot/src/commands/about.rs b/cipher_discord_bot/src/commands/about.rs index 10e61c2..87cdc02 100644 --- a/cipher_discord_bot/src/commands/about.rs +++ b/cipher_discord_bot/src/commands/about.rs @@ -7,7 +7,7 @@ use crate::app::AppError; use crate::utils; /// Show information about the bot. -#[poise::command(slash_command)] +#[poise::command(slash_command, guild_only)] pub async fn about( ctx: AppContext<'_, R, R::BackendError>, #[description = "Hide reply from other users. Defaults to True."] ephemeral: Option, diff --git a/cipher_discord_bot/src/commands/help.rs b/cipher_discord_bot/src/commands/help.rs index f020741..1594b57 100644 --- a/cipher_discord_bot/src/commands/help.rs +++ b/cipher_discord_bot/src/commands/help.rs @@ -22,7 +22,7 @@ where } /// Show help message. -#[poise::command(slash_command)] +#[poise::command(slash_command, guild_only)] pub async fn help( ctx: AppContext<'_, R, R::BackendError>, #[rename = "command"] diff --git a/cipher_discord_bot/src/commands/profile/codes.rs b/cipher_discord_bot/src/commands/profile/codes.rs index d0fc485..26dc8d1 100644 --- a/cipher_discord_bot/src/commands/profile/codes.rs +++ b/cipher_discord_bot/src/commands/profile/codes.rs @@ -15,6 +15,7 @@ use crate::app::AppError; /// Manage friend codes. #[poise::command( slash_command, + guild_only, subcommands( "edit", "overwrite", @@ -220,7 +221,7 @@ where } /// Edit your friend codes. -#[poise::command(slash_command)] +#[poise::command(slash_command, guild_only)] async fn edit(ctx: AppContext<'_, R, R::BackendError>) -> Result<(), AppError> { let author_id = ctx.author().id.get(); @@ -249,6 +250,7 @@ async fn edit(ctx: AppContext<'_, R, R::Bac /// Edit any user's friend codes. #[poise::command( slash_command, + guild_only, hide_in_help, check = "crate::checks::is_staff", )] diff --git a/cipher_discord_bot/src/commands/profile/mod.rs b/cipher_discord_bot/src/commands/profile/mod.rs index 28e07f7..c28968c 100644 --- a/cipher_discord_bot/src/commands/profile/mod.rs +++ b/cipher_discord_bot/src/commands/profile/mod.rs @@ -1,7 +1,6 @@ use cipher_core::repository::user_repository::UserRepository; use cipher_core::repository::RepositoryProvider; use poise::CreateReply; -use serenity::all::Color; use serenity::all::CreateEmbed; use crate::app::AppContext; @@ -24,7 +23,7 @@ pub async fn profile( } /// Show your profile or someone else's. -#[poise::command(slash_command)] +#[poise::command(slash_command, guild_only)] async fn show( ctx: AppContext<'_, R, R::BackendError>, #[rename = "member"] @@ -37,23 +36,7 @@ async fn show( let member = match option_member { Some(member) => member, - None => match ctx.author_member().await { - Some(member) => member.into_owned(), - None => { - let embed = CreateEmbed::new() - .title("Error") - .description("This command can only be used in server.") - .color(Color::RED); - - let reply = CreateReply::default() - .embed(embed) - .ephemeral(true); - - ctx.send(reply).await?; - - return Ok(()) - }, - }, + None => ctx.author_member().await.ok_or(AppError::UnknownCacheOrHttpError)?.into_owned(), }; let avatar_url = crate::utils::member_avatar_url(&member);