style(command/moderation): adding the format_sanction_reason function

This commit is contained in:
Raphael 2026-03-16 14:05:05 +01:00
parent 83d0c0dace
commit e7a7c0c578
No known key found for this signature in database

View file

@ -1,5 +1,6 @@
use crate::commands::{CommandCategory, CommandEntry, SlashCommand}; use crate::commands::{CommandCategory, CommandEntry, SlashCommand};
use crate::config::EmojiConfig; use crate::config::EmojiConfig;
use crate::utils::format::format_sanction_reason;
use serenity::all::{ use serenity::all::{
CommandInteraction, CommandOptionType, Context, CreateCommand, CreateCommandOption, CreateInteractionResponse, CreateInteractionResponseMessage, EditInteractionResponse, GetMessages, Guild, GuildId, InteractionContext, Member, Message, MessageId, Permissions, Role, User, UserId CommandInteraction, CommandOptionType, Context, CreateCommand, CreateCommandOption, CreateInteractionResponse, CreateInteractionResponseMessage, EditInteractionResponse, GetMessages, Guild, GuildId, InteractionContext, Member, Message, MessageId, Permissions, Role, User, UserId
@ -10,13 +11,6 @@ use anyhow::Result;
pub struct Kick; pub struct Kick;
fn format_reason(reason: Option<&str>, executor: &str) -> String {
match reason {
Some(s) => format!("[TTY kick] {} by {}", s, executor),
None => format!("[TTY kick] by {}", executor)
}
}
#[serenity::async_trait] #[serenity::async_trait]
impl SlashCommand for Kick { impl SlashCommand for Kick {
fn name(&self) -> &'static str { fn name(&self) -> &'static str {
@ -68,7 +62,7 @@ impl SlashCommand for Kick {
.ok_or_else(|| anyhow::anyhow!("Utilisateur introuvable"))? .ok_or_else(|| anyhow::anyhow!("Utilisateur introuvable"))?
.clone(); .clone();
let reason_provided: Option<&str> = command.data.options.iter().find(|opt | opt.kind() == CommandOptionType::String).and_then(|opt| opt.value.as_str()); let reason_provided: Option<&str> = command.data.options.iter().find(|opt | opt.kind() == CommandOptionType::String).and_then(|opt| opt.value.as_str());
let reason_formatted: String = format_reason(reason_provided, &command.user.name); let reason_formatted: String = format_sanction_reason("kick", reason_provided, &command.user.name);
let guild_id: GuildId = command.guild_id.ok_or(anyhow::anyhow!("Kick command executed in DM"))?; let guild_id: GuildId = command.guild_id.ok_or(anyhow::anyhow!("Kick command executed in DM"))?;
let guild: Guild = ctx.cache.guild(guild_id) let guild: Guild = ctx.cache.guild(guild_id)