feat(discord): Added /social undo command

This commit is contained in:
Alexey 2025-12-11 15:19:06 +03:00
commit 78e7d9bf23

View file

@ -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<ChannelId>,
user: Option<UserId>,
) -> 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(())
}