From f3c6db036eebc885d14a0af0657a95b6fd63effc Mon Sep 17 00:00:00 2001 From: jude Date: Sat, 21 May 2022 17:04:04 +0100 Subject: [PATCH] block commands in DM --- src/cmds/manage.rs | 24 ++++++++++++++++++++---- src/cmds/play.rs | 19 +++++++++++++++---- src/cmds/search.rs | 15 ++++++++++----- src/cmds/settings.rs | 10 +++++----- src/cmds/stop.rs | 9 +++++++-- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/cmds/manage.rs b/src/cmds/manage.rs index d708f36..ef7d9d7 100644 --- a/src/cmds/manage.rs +++ b/src/cmds/manage.rs @@ -13,7 +13,8 @@ use crate::{ slash_command, rename = "upload", category = "Manage", - default_member_permissions = "MANAGE_GUILD" + default_member_permissions = "MANAGE_GUILD", + guild_only = true )] pub async fn upload_new_sound( ctx: Context<'_>, @@ -100,7 +101,12 @@ pub async fn upload_new_sound( } /// Delete a sound you have uploaded -#[poise::command(slash_command, rename = "delete", category = "Manage")] +#[poise::command( + slash_command, + rename = "delete", + category = "Manage", + guild_only = true +)] pub async fn delete_sound( ctx: Context<'_>, #[description = "Name or ID of sound to delete"] @@ -153,7 +159,12 @@ pub async fn delete_sound( } /// Change a sound between public and private -#[poise::command(slash_command, rename = "public", category = "Manage")] +#[poise::command( + slash_command, + rename = "public", + category = "Manage", + guild_only = true +)] pub async fn change_public( ctx: Context<'_>, #[description = "Name or ID of sound to change privacy setting of"] @@ -196,7 +207,12 @@ pub async fn change_public( } /// Download a sound file from the bot -#[poise::command(slash_command, rename = "download", category = "Manage")] +#[poise::command( + slash_command, + rename = "download", + category = "Manage", + guild_only = true +)] pub async fn download_file( ctx: Context<'_>, #[description = "Name or ID of sound to download"] diff --git a/src/cmds/play.rs b/src/cmds/play.rs index 17197c6..6897d39 100644 --- a/src/cmds/play.rs +++ b/src/cmds/play.rs @@ -10,7 +10,7 @@ use crate::{ }; /// Play a sound in your current voice channel -#[poise::command(slash_command, default_member_permissions = "SPEAK")] +#[poise::command(slash_command, default_member_permissions = "SPEAK", guild_only = true)] pub async fn play( ctx: Context<'_>, #[description = "Name or ID of sound to play"] @@ -38,7 +38,12 @@ pub async fn play( } /// Play up to 25 sounds on queue -#[poise::command(slash_command, rename = "queue", default_member_permissions = "SPEAK")] +#[poise::command( + slash_command, + rename = "queue", + default_member_permissions = "SPEAK", + guild_only = true +)] pub async fn queue_play( ctx: Context<'_>, #[description = "Name or ID for queue position 1"] @@ -199,7 +204,12 @@ pub async fn queue_play( } /// Loop a sound in your current voice channel -#[poise::command(slash_command, rename = "loop", default_member_permissions = "SPEAK")] +#[poise::command( + slash_command, + rename = "loop", + default_member_permissions = "SPEAK", + guild_only = true +)] pub async fn loop_play( ctx: Context<'_>, #[description = "Name or ID of sound to loop"] @@ -231,7 +241,8 @@ pub async fn loop_play( slash_command, rename = "soundboard", category = "Play", - default_member_permissions = "SPEAK" + default_member_permissions = "SPEAK", + guild_only = true )] pub async fn soundboard( ctx: Context<'_>, diff --git a/src/cmds/search.rs b/src/cmds/search.rs index 8920be3..a352b14 100644 --- a/src/cmds/search.rs +++ b/src/cmds/search.rs @@ -27,13 +27,13 @@ fn format_search_results<'a>(search_results: Vec) -> CreateReply<'a> { } /// Show uploaded sounds -#[poise::command(slash_command, rename = "list")] +#[poise::command(slash_command, rename = "list", guild_only = true)] pub async fn list_sounds(_ctx: Context<'_>) -> Result<(), Error> { Ok(()) } /// Show the sounds uploaded to this server -#[poise::command(slash_command, rename = "server")] +#[poise::command(slash_command, rename = "server", guild_only = true)] pub async fn list_guild_sounds(ctx: Context<'_>) -> Result<(), Error> { let sounds; let mut message_buffer; @@ -68,7 +68,7 @@ pub async fn list_guild_sounds(ctx: Context<'_>) -> Result<(), Error> { } /// Show all sounds you have uploaded -#[poise::command(slash_command, rename = "user")] +#[poise::command(slash_command, rename = "user", guild_only = true)] pub async fn list_user_sounds(ctx: Context<'_>) -> Result<(), Error> { let sounds; let mut message_buffer; @@ -103,7 +103,12 @@ pub async fn list_user_sounds(ctx: Context<'_>) -> Result<(), Error> { } /// Search for sounds -#[poise::command(slash_command, rename = "search", category = "Search")] +#[poise::command( + slash_command, + rename = "search", + category = "Search", + guild_only = true +)] pub async fn search_sounds( ctx: Context<'_>, #[description = "Sound name to search for"] query: String, @@ -123,7 +128,7 @@ pub async fn search_sounds( } /// Show a page of random sounds -#[poise::command(slash_command, rename = "random")] +#[poise::command(slash_command, rename = "random", guild_only = true)] pub async fn show_random_sounds(ctx: Context<'_>) -> Result<(), Error> { let search_results = sqlx::query_as_unchecked!( Sound, diff --git a/src/cmds/settings.rs b/src/cmds/settings.rs index 04da24b..c6efc0a 100644 --- a/src/cmds/settings.rs +++ b/src/cmds/settings.rs @@ -4,7 +4,7 @@ use crate::{ }; /// Change the bot's volume in this server -#[poise::command(slash_command, rename = "volume")] +#[poise::command(slash_command, rename = "volume", guild_only = true)] pub async fn change_volume( ctx: Context<'_>, #[description = "New volume as a percentage"] volume: Option, @@ -32,7 +32,7 @@ pub async fn change_volume( } /// Manage greet sounds on this server -#[poise::command(slash_command, rename = "greet")] +#[poise::command(slash_command, rename = "greet", guild_only = true)] pub async fn greet_sound(_ctx: Context<'_>) -> Result<(), Error> { Ok(()) } @@ -70,7 +70,7 @@ pub async fn set_greet_sound( } /// Set a join sound -#[poise::command(slash_command, rename = "unset")] +#[poise::command(slash_command, rename = "unset", guild_only = true)] pub async fn unset_greet_sound(ctx: Context<'_>) -> Result<(), Error> { ctx.data().update_join_sound(ctx.author().id, None).await; @@ -80,7 +80,7 @@ pub async fn unset_greet_sound(ctx: Context<'_>) -> Result<(), Error> { } /// Disable greet sounds on this server -#[poise::command(slash_command, rename = "disable")] +#[poise::command(slash_command, rename = "disable", guild_only = true)] pub async fn disable_greet_sound(ctx: Context<'_>) -> Result<(), Error> { let guild_data_opt = ctx.guild_data(ctx.guild_id().unwrap()).await; @@ -97,7 +97,7 @@ pub async fn disable_greet_sound(ctx: Context<'_>) -> Result<(), Error> { } /// Enable greet sounds on this server -#[poise::command(slash_command, rename = "enable")] +#[poise::command(slash_command, rename = "enable", guild_only = true)] pub async fn enable_greet_sound(ctx: Context<'_>) -> Result<(), Error> { let guild_data_opt = ctx.guild_data(ctx.guild_id().unwrap()).await; diff --git a/src/cmds/stop.rs b/src/cmds/stop.rs index dd15e31..fc8b4ca 100644 --- a/src/cmds/stop.rs +++ b/src/cmds/stop.rs @@ -3,7 +3,12 @@ use songbird; use crate::{Context, Error}; /// Stop the bot from playing and clear the play queue -#[poise::command(slash_command, rename = "stop", default_member_permissions = "SPEAK")] +#[poise::command( + slash_command, + rename = "stop", + default_member_permissions = "SPEAK", + guild_only = true +)] pub async fn stop_playing(ctx: Context<'_>) -> Result<(), Error> { let songbird = songbird::get(ctx.discord()).await.unwrap(); let call_opt = songbird.get(ctx.guild_id().unwrap()); @@ -20,7 +25,7 @@ pub async fn stop_playing(ctx: Context<'_>) -> Result<(), Error> { } /// Disconnect the bot -#[poise::command(slash_command, default_member_permissions = "SPEAK")] +#[poise::command(slash_command, default_member_permissions = "SPEAK", guild_only = true)] pub async fn disconnect(ctx: Context<'_>) -> Result<(), Error> { let songbird = songbird::get(ctx.discord()).await.unwrap(); let _ = songbird.leave(ctx.guild_id().unwrap()).await;