diff --git a/discord/src/commands/social.rs b/discord/src/commands/social.rs index cf24086..9b3578b 100644 --- a/discord/src/commands/social.rs +++ b/discord/src/commands/social.rs @@ -7,7 +7,7 @@ use crate::{Context, Error}; slash_command, required_permissions = "ADMINISTRATOR", guild_only, - subcommands("msg", "edit"), + subcommands("msg", "edit", "undo"), )] pub async fn social( _ctx: Context<'_> ) -> Result<(), Error> { Ok(()) @@ -155,3 +155,44 @@ pub async fn edit ( Ok(()) } + +#[poise::command( + prefix_command, + slash_command, + required_permissions = "ADMINISTRATOR", + guild_only, +)] +pub async fn undo( + ctx: Context<'_>, + #[rename = "message"] + message_id: MessageId, + channel: Option, + user: Option, +) -> Result<(), Error> { + + if channel.is_none() && user.is_none() { + let reply_string = "Please specify channel **or** user".to_string(); + ctx.reply(reply_string).await?; + return Ok(()); + } + + if channel.is_some() && user.is_some() { + let reply_string = "Please specify **only** channel or **only** user, not both".to_string(); + ctx.reply(reply_string).await?; + return Ok(()); + } + + if let Some(channel) = channel { + let message = channel.message(ctx, message_id).await?; + message.delete(ctx).await?; + } else if let Some(user) = user { + let channel = user.create_dm_channel(ctx).await?; + let message = channel.message(ctx, message_id).await?; + message.delete(ctx).await?; + } + + let reply_string = "Successfully deleted message".to_string(); + ctx.reply(reply_string).await?; + + Ok(()) +}