block commands in DM

This commit is contained in:
jude 2022-05-21 17:04:04 +01:00
parent 651ad9dffe
commit f3c6db036e
5 changed files with 57 additions and 20 deletions

View File

@ -13,7 +13,8 @@ use crate::{
slash_command, slash_command,
rename = "upload", rename = "upload",
category = "Manage", category = "Manage",
default_member_permissions = "MANAGE_GUILD" default_member_permissions = "MANAGE_GUILD",
guild_only = true
)] )]
pub async fn upload_new_sound( pub async fn upload_new_sound(
ctx: Context<'_>, ctx: Context<'_>,
@ -100,7 +101,12 @@ pub async fn upload_new_sound(
} }
/// Delete a sound you have uploaded /// 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( pub async fn delete_sound(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Name or ID of sound to delete"] #[description = "Name or ID of sound to delete"]
@ -153,7 +159,12 @@ pub async fn delete_sound(
} }
/// Change a sound between public and private /// 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( pub async fn change_public(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Name or ID of sound to change privacy setting of"] #[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 /// 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( pub async fn download_file(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Name or ID of sound to download"] #[description = "Name or ID of sound to download"]

View File

@ -10,7 +10,7 @@ use crate::{
}; };
/// Play a sound in your current voice channel /// 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( pub async fn play(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Name or ID of sound to play"] #[description = "Name or ID of sound to play"]
@ -38,7 +38,12 @@ pub async fn play(
} }
/// Play up to 25 sounds on queue /// 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( pub async fn queue_play(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Name or ID for queue position 1"] #[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 /// 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( pub async fn loop_play(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Name or ID of sound to loop"] #[description = "Name or ID of sound to loop"]
@ -231,7 +241,8 @@ pub async fn loop_play(
slash_command, slash_command,
rename = "soundboard", rename = "soundboard",
category = "Play", category = "Play",
default_member_permissions = "SPEAK" default_member_permissions = "SPEAK",
guild_only = true
)] )]
pub async fn soundboard( pub async fn soundboard(
ctx: Context<'_>, ctx: Context<'_>,

View File

@ -27,13 +27,13 @@ fn format_search_results<'a>(search_results: Vec<Sound>) -> CreateReply<'a> {
} }
/// Show uploaded sounds /// 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> { pub async fn list_sounds(_ctx: Context<'_>) -> Result<(), Error> {
Ok(()) Ok(())
} }
/// Show the sounds uploaded to this server /// 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> { pub async fn list_guild_sounds(ctx: Context<'_>) -> Result<(), Error> {
let sounds; let sounds;
let mut message_buffer; let mut message_buffer;
@ -68,7 +68,7 @@ pub async fn list_guild_sounds(ctx: Context<'_>) -> Result<(), Error> {
} }
/// Show all sounds you have uploaded /// 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> { pub async fn list_user_sounds(ctx: Context<'_>) -> Result<(), Error> {
let sounds; let sounds;
let mut message_buffer; let mut message_buffer;
@ -103,7 +103,12 @@ pub async fn list_user_sounds(ctx: Context<'_>) -> Result<(), Error> {
} }
/// Search for sounds /// 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( pub async fn search_sounds(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Sound name to search for"] query: String, #[description = "Sound name to search for"] query: String,
@ -123,7 +128,7 @@ pub async fn search_sounds(
} }
/// Show a page of random 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> { pub async fn show_random_sounds(ctx: Context<'_>) -> Result<(), Error> {
let search_results = sqlx::query_as_unchecked!( let search_results = sqlx::query_as_unchecked!(
Sound, Sound,

View File

@ -4,7 +4,7 @@ use crate::{
}; };
/// Change the bot's volume in this server /// 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( pub async fn change_volume(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "New volume as a percentage"] volume: Option<usize>, #[description = "New volume as a percentage"] volume: Option<usize>,
@ -32,7 +32,7 @@ pub async fn change_volume(
} }
/// Manage greet sounds on this server /// 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> { pub async fn greet_sound(_ctx: Context<'_>) -> Result<(), Error> {
Ok(()) Ok(())
} }
@ -70,7 +70,7 @@ pub async fn set_greet_sound(
} }
/// Set a join 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> { pub async fn unset_greet_sound(ctx: Context<'_>) -> Result<(), Error> {
ctx.data().update_join_sound(ctx.author().id, None).await; 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 /// 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> { pub async fn disable_greet_sound(ctx: Context<'_>) -> Result<(), Error> {
let guild_data_opt = ctx.guild_data(ctx.guild_id().unwrap()).await; 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 /// 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> { pub async fn enable_greet_sound(ctx: Context<'_>) -> Result<(), Error> {
let guild_data_opt = ctx.guild_data(ctx.guild_id().unwrap()).await; let guild_data_opt = ctx.guild_data(ctx.guild_id().unwrap()).await;

View File

@ -3,7 +3,12 @@ use songbird;
use crate::{Context, Error}; use crate::{Context, Error};
/// Stop the bot from playing and clear the play queue /// 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> { pub async fn stop_playing(ctx: Context<'_>) -> Result<(), Error> {
let songbird = songbird::get(ctx.discord()).await.unwrap(); let songbird = songbird::get(ctx.discord()).await.unwrap();
let call_opt = songbird.get(ctx.guild_id().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 /// 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> { pub async fn disconnect(ctx: Context<'_>) -> Result<(), Error> {
let songbird = songbird::get(ctx.discord()).await.unwrap(); let songbird = songbird::get(ctx.discord()).await.unwrap();
let _ = songbird.leave(ctx.guild_id().unwrap()).await; let _ = songbird.leave(ctx.guild_id().unwrap()).await;