From 442b55c09f542122e6a3f3cb6921163d053bb187 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 15 Feb 2026 19:20:40 +0100 Subject: [PATCH] feat(commands/moderation): adding the clear start --- src/commands/moderation/clear.rs | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/commands/moderation/clear.rs diff --git a/src/commands/moderation/clear.rs b/src/commands/moderation/clear.rs new file mode 100644 index 0000000..c062f6d --- /dev/null +++ b/src/commands/moderation/clear.rs @@ -0,0 +1,64 @@ +use std::time::Instant; + +use crate::commands::{CommandEntry, SlashCommand}; + +use serenity::all::{ + ChannelType, CommandInteraction, CommandOption, CommandOptionType, Context, CreateCommand, CreateCommandOption, CreateInteractionResponse, CreateInteractionResponseMessage, EditInteractionResponse, GetMessages, MessageId, Permissions +}; +use sqlx::PgPool; + +pub struct Clear; + +#[serenity::async_trait] +impl SlashCommand for Clear { + fn name(&self) -> &'static str { + "clear" + } + + fn description(&self) -> &'static str { + "Clear X message (X given in the parameters)" + } + + fn register(&self) -> CreateCommand { + println!("\t✅ | {}", self.name()); + let mut options: Vec = Vec::new(); + + let mut amount: CreateCommandOption = CreateCommandOption::new(CommandOptionType::Unknown((u8)), "amount", "Amount of messages to clear") + .min_int_value(1) + .max_int_value(100) + .required(true); + + options.push(amount); + CreateCommand::new(self.name()) + .description(self.description()) + .default_member_permissions(Permissions::MANAGE_MESSAGES) + .set_options(options) + } + + async fn run( + &self, + ctx: &Context, + command: &CommandInteraction, + _database: &PgPool, + ) -> Result<(), serenity::Error> { + let amount: u8 = command.data.options.get(0).unwrap().value.as_u8().expect("REASON"); + let message: CreateInteractionResponseMessage = CreateInteractionResponseMessage::new() + .content("| Start to clear") + .ephemeral(true); + let response: CreateInteractionResponse = CreateInteractionResponse::Message(message); + command.create_response(&ctx.http, response).await?; + + let builder: GetMessages = GetMessages::new().after(command.channel_id.limit(amount); + + let edit_msg: EditInteractionResponse = + EditInteractionResponse::new().content(format!(": **{delta_time}**ms")); + + command.edit_response(&ctx.http, edit_msg).await?; + + Ok(()) + } +} + +inventory::submit! { + CommandEntry { create: || Box::new(Clear) } +}