From e0711a2a1325b6f060bbcf35283b47e7526b0ea7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 25 Feb 2026 21:53:27 +0100 Subject: [PATCH] feat(commands/moderation): adding the anyhow result return --- src/commands/moderation/clear.rs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/commands/moderation/clear.rs b/src/commands/moderation/clear.rs index 68761fb..1fadbfd 100644 --- a/src/commands/moderation/clear.rs +++ b/src/commands/moderation/clear.rs @@ -1,5 +1,3 @@ -use std::sync::atomic::AtomicU64; - use crate::commands::{CommandCategory, CommandEntry, SlashCommand}; use crate::config::EmojiConfig; @@ -7,19 +5,10 @@ use serenity::all::{ CommandInteraction, CommandOptionType, Context, CreateCommand, CreateCommandOption, CreateInteractionResponse, CreateInteractionResponseMessage, EditInteractionResponse, GetMessages, InteractionContext, Message, MessageId, Permissions }; use sqlx::PgPool; -use tracing::info; +use tracing::{debug, info}; +use anyhow::Result; -pub struct Clear { - pub command_id: AtomicU64, -} - -impl Clear { - pub fn new() -> Self { - Self { - command_id: AtomicU64::new(0), - } - } -} +pub struct Clear; #[serenity::async_trait] impl SlashCommand for Clear { @@ -35,10 +24,6 @@ impl SlashCommand for Clear { &CommandCategory::Moderation } - fn command_id_ref(&self) -> &AtomicU64 { - &self.command_id - } - fn register(&self) -> CreateCommand { info!("\t✅ | {}", self.name()); let mut options: Vec = Vec::new(); @@ -64,8 +49,10 @@ impl SlashCommand for Clear { command: &CommandInteraction, _database: &PgPool, _emoji: &EmojiConfig, - ) -> Result<(), serenity::Error> { - let amount: u8 = command.data.options.get(0).unwrap().value.as_i64().expect("REASON") as u8; + ) -> Result<()> { + debug!("Clear command called"); + let amount: u8 = command.data.options.iter().find(|opt | opt.kind() == CommandOptionType::Integer) + .unwrap().value.as_i64().expect("REASON") as u8; let message: CreateInteractionResponseMessage = CreateInteractionResponseMessage::new() .content(format!("{} | Start to clear", _emoji.answer.loading)) .ephemeral(true); @@ -102,5 +89,5 @@ impl SlashCommand for Clear { } inventory::submit! { - CommandEntry { create: || Box::new(Clear::new()) } + CommandEntry { create: || Box::new(Clear) } }