netoyage des commands

This commit is contained in:
Puechberty Arthur
2026-04-10 16:41:03 +02:00
parent 1b5e51c428
commit 9a47588cdf
45 changed files with 1381 additions and 710 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ impl crate::commands::command_contract::CommandSpec for ClearAllSanctionsCommand
category: "mod",
params: "aucun",
description: "Efface toutes les sanctions de tous les membres du serveur.",
examples: &["+clear all sanctions"],
examples: &["+clearallsanctions"],
default_aliases: &["casanctions"],
allow_in_dm: false,
default_permission: 8,
+1 -1
View File
@@ -41,7 +41,7 @@ impl crate::commands::command_contract::CommandSpec for ClearBadwordsCommand {
category: "mod",
params: "badwords",
description: "Supprime l ensemble des mots interdits enregistres.",
examples: &["+clear badwords", "+help clear badwords"],
examples: &["+clearbadwords", "+help clearbadwords"],
default_aliases: &["cbw"],
allow_in_dm: false,
default_permission: 7,
+2 -2
View File
@@ -17,7 +17,7 @@ pub async fn handle_clear_limit(ctx: &Context, msg: &Message, args: &[&str]) {
msg,
CreateEmbed::new()
.title("Clear Limit")
.description("Usage: +clear limit <nombre>")
.description("Usage: +clearlimit <nombre>")
.color(0xED4245),
)
.await;
@@ -65,7 +65,7 @@ impl crate::commands::command_contract::CommandSpec for ClearLimitCommand {
category: "mod",
params: "limit <nombre>",
description: "Definit la limite max de messages supprimables avec +clear.",
examples: &["+clear limit 100", "+help clear limit"],
examples: &["+clearlimit 100", "+help clearlimit"],
default_aliases: &["climit"],
allow_in_dm: false,
default_permission: 7,
+1 -1
View File
@@ -67,7 +67,7 @@ impl crate::commands::command_contract::CommandSpec for ClearSanctionsCommand {
category: "mod",
params: "<@membre/ID>",
description: "Efface completement les sanctions d un membre cible.",
examples: &["+clear sanctions @User"],
examples: &["+clearsanctions @User"],
default_aliases: &["csanctions"],
allow_in_dm: false,
default_permission: 6,
+66
View File
@@ -0,0 +1,66 @@
use serenity::builder::CreateEmbed;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::common::{send_embed, theme_color};
use crate::db::DbPoolKey;
pub async fn handle_clear_all_sanctions(ctx: &Context, msg: &Message) {
let Some(guild_id) = msg.guild_id else {
return;
};
let pool = {
let data = ctx.data.read().await;
data.get::<DbPoolKey>().cloned()
};
let Some(pool) = pool else {
return;
};
let bot_id = ctx.cache.current_user().id;
let removed = sqlx::query(
r#"
DELETE FROM bot_sanctions
WHERE bot_id = $1 AND guild_id = $2;
"#,
)
.bind(bot_id.get() as i64)
.bind(guild_id.get() as i64)
.execute(&pool)
.await
.ok()
.map(|r| r.rows_affected())
.unwrap_or(0);
send_embed(
ctx,
msg,
CreateEmbed::new()
.title("Sanctions")
.description(format!(
"{} sanction(s) supprimée(s) sur le serveur.",
removed
))
.color(theme_color(ctx).await),
)
.await;
}
pub struct ClearAllSanctionsCommand;
pub static COMMAND_DESCRIPTOR: ClearAllSanctionsCommand = ClearAllSanctionsCommand;
impl crate::commands::command_contract::CommandSpec for ClearAllSanctionsCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "clearallsanctions",
category: "mod",
params: "aucun",
description: "Efface toutes les sanctions de tous les membres du serveur.",
examples: &["+clearallsanctions"],
default_aliases: &["casanctions"],
allow_in_dm: false,
default_permission: 8,
}
}
}
+50
View File
@@ -0,0 +1,50 @@
use serenity::builder::CreateEmbed;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::automod_service::pool;
use crate::commands::common::send_embed;
use crate::db;
pub async fn handle_clear_badwords(ctx: &Context, msg: &Message, _args: &[&str]) {
let Some(guild_id) = msg.guild_id else {
return;
};
let Some(pool) = pool(ctx).await else {
return;
};
let bot_id = ctx.cache.current_user().id.get() as i64;
let cleared = db::clear_badwords(&pool, bot_id, guild_id.get() as i64)
.await
.unwrap_or(0);
send_embed(
ctx,
msg,
CreateEmbed::new()
.title("Clear BadWords")
.description(format!("{} mot(s) interdit(s) supprime(s).", cleared))
.color(0x57F287),
)
.await;
}
pub struct ClearBadwordsCommand;
pub static COMMAND_DESCRIPTOR: ClearBadwordsCommand = ClearBadwordsCommand;
impl crate::commands::command_contract::CommandSpec for ClearBadwordsCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "clearbadwords",
category: "mod",
params: "badwords",
description: "Supprime l ensemble des mots interdits enregistres.",
examples: &["+clearbadwords", "+help clearbadwords"],
default_aliases: &["cbw"],
allow_in_dm: false,
default_permission: 7,
}
}
}
+74
View File
@@ -0,0 +1,74 @@
use serenity::builder::CreateEmbed;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::automod_service::pool;
use crate::commands::common::send_embed;
use crate::db;
pub async fn handle_clear_limit(ctx: &Context, msg: &Message, args: &[&str]) {
let Some(guild_id) = msg.guild_id else {
return;
};
let Some(raw_value) = args.get(1) else {
send_embed(
ctx,
msg,
CreateEmbed::new()
.title("Clear Limit")
.description("Usage: +clearlimit <nombre>")
.color(0xED4245),
)
.await;
return;
};
let Ok(value) = raw_value.parse::<i32>() else {
return;
};
let clamped = value.clamp(1, 1_000);
let Some(pool) = pool(ctx).await else {
return;
};
let bot_id = ctx.cache.current_user().id.get() as i64;
if db::set_clear_limit(&pool, bot_id, guild_id.get() as i64, clamped)
.await
.is_err()
{
return;
}
send_embed(
ctx,
msg,
CreateEmbed::new()
.title("Clear Limit")
.description(format!(
"Limite de suppression definie a **{}** message(s) par commande clear.",
clamped
))
.color(0x57F287),
)
.await;
}
pub struct ClearLimitCommand;
pub static COMMAND_DESCRIPTOR: ClearLimitCommand = ClearLimitCommand;
impl crate::commands::command_contract::CommandSpec for ClearLimitCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "clearlimit",
category: "mod",
params: "limit <nombre>",
description: "Definit la limite max de messages supprimables avec +clear.",
examples: &["+clearlimit 100", "+help clearlimit"],
default_aliases: &["climit"],
allow_in_dm: false,
default_permission: 7,
}
}
}
@@ -76,11 +76,11 @@ pub static COMMAND_DESCRIPTOR: ClearMessagesCommand = ClearMessagesCommand;
impl crate::commands::command_contract::CommandSpec for ClearMessagesCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "clear_messages",
name: "clearmessages",
category: "mod",
params: "<nombre> [@membre/ID]",
description: "Supprime un nombre de messages, optionnellement filtres par membre.",
examples: &["+clear 20", "+clear 20 @User"],
examples: &["+clearmessages 20", "+clearmessages 20 @User"],
default_aliases: &["purge"],
allow_in_dm: false,
default_permission: 5,
+76
View File
@@ -0,0 +1,76 @@
use serenity::builder::CreateEmbed;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::admin_common::parse_user_id;
use crate::commands::common::{send_embed, theme_color};
use crate::db::DbPoolKey;
pub async fn handle_clear_sanctions(ctx: &Context, msg: &Message, args: &[&str]) {
let Some(guild_id) = msg.guild_id else {
return;
};
if args.len() < 2 {
return;
}
let Some(target) = parse_user_id(args[1]) else {
return;
};
let pool = {
let data = ctx.data.read().await;
data.get::<DbPoolKey>().cloned()
};
let Some(pool) = pool else {
return;
};
let bot_id = ctx.cache.current_user().id;
let removed = sqlx::query(
r#"
DELETE FROM bot_sanctions
WHERE bot_id = $1 AND guild_id = $2 AND user_id = $3;
"#,
)
.bind(bot_id.get() as i64)
.bind(guild_id.get() as i64)
.bind(target.get() as i64)
.execute(&pool)
.await
.ok()
.map(|r| r.rows_affected())
.unwrap_or(0);
send_embed(
ctx,
msg,
CreateEmbed::new()
.title("Sanctions")
.description(format!(
"{} sanction(s) supprimée(s) pour <@{}>.",
removed,
target.get()
))
.color(theme_color(ctx).await),
)
.await;
}
pub struct ClearSanctionsCommand;
pub static COMMAND_DESCRIPTOR: ClearSanctionsCommand = ClearSanctionsCommand;
impl crate::commands::command_contract::CommandSpec for ClearSanctionsCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "clearsanctions",
category: "mod",
params: "<@membre/ID>",
description: "Efface completement les sanctions d un membre cible.",
examples: &["+clearsanctions @User"],
default_aliases: &["csanctions"],
allow_in_dm: false,
default_permission: 6,
}
}
}
+1 -1
View File
@@ -89,7 +89,7 @@ impl crate::commands::command_contract::CommandSpec for DelSanctionCommand {
category: "mod",
params: "<@membre/ID> <nombre>",
description: "Supprime une sanction specifique dans l historique d un membre.",
examples: &["+del sanction @User 1"],
examples: &["+delsanction @User 1"],
default_aliases: &["delsanction"],
allow_in_dm: false,
default_permission: 6,
+98
View File
@@ -0,0 +1,98 @@
use serenity::builder::CreateEmbed;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::admin_common::parse_user_id;
use crate::commands::common::{send_embed, theme_color};
use crate::db::DbPoolKey;
pub async fn handle_del_sanction(ctx: &Context, msg: &Message, args: &[&str]) {
let Some(guild_id) = msg.guild_id else {
return;
};
if args.len() < 3 {
return;
}
let Some(target) = parse_user_id(args[1]) else {
return;
};
let Ok(index) = args[2].parse::<usize>() else {
return;
};
if index == 0 {
return;
}
let pool = {
let data = ctx.data.read().await;
data.get::<DbPoolKey>().cloned()
};
let Some(pool) = pool else {
return;
};
let bot_id = ctx.cache.current_user().id;
let rows = sqlx::query_as::<_, (i64,)>(
r#"
SELECT id
FROM bot_sanctions
WHERE bot_id = $1 AND guild_id = $2 AND user_id = $3
ORDER BY created_at DESC;
"#,
)
.bind(bot_id.get() as i64)
.bind(guild_id.get() as i64)
.bind(target.get() as i64)
.fetch_all(&pool)
.await
.unwrap_or_default();
let Some((sanction_id,)) = rows.get(index - 1).copied() else {
return;
};
let _ = sqlx::query(
r#"
DELETE FROM bot_sanctions
WHERE id = $1 AND bot_id = $2 AND guild_id = $3;
"#,
)
.bind(sanction_id)
.bind(bot_id.get() as i64)
.bind(guild_id.get() as i64)
.execute(&pool)
.await;
send_embed(
ctx,
msg,
CreateEmbed::new()
.title("Sanctions")
.description(format!(
"Sanction #{} supprimée pour <@{}>.",
sanction_id,
target.get()
))
.color(theme_color(ctx).await),
)
.await;
}
pub struct DelSanctionCommand;
pub static COMMAND_DESCRIPTOR: DelSanctionCommand = DelSanctionCommand;
impl crate::commands::command_contract::CommandSpec for DelSanctionCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "delsanction",
category: "mod",
params: "<@membre/ID> <nombre>",
description: "Supprime une sanction specifique dans l historique d un membre.",
examples: &["+delsanction @User 1"],
default_aliases: &["delsanction"],
allow_in_dm: false,
default_permission: 6,
}
}
}
+2 -2
View File
@@ -17,7 +17,7 @@ pub async fn handle_set_muterole(ctx: &Context, msg: &Message, args: &[&str]) {
msg,
CreateEmbed::new()
.title("Set MuteRole")
.description("Usage: +set muterole <@role/ID/nom>")
.description("Usage: +setmuterole <@role/ID/nom>")
.color(0xED4245),
)
.await;
@@ -70,7 +70,7 @@ impl crate::commands::command_contract::CommandSpec for SetMuteRoleCommand {
category: "mod",
params: "muterole <@role/ID/nom>",
description: "Definit le role utilise pour le mute lorsque le mode timeout est desactive.",
examples: &["+set muterole @Muted", "+help set muterole"],
examples: &["+setmuterole @Muted", "+help setmuterole"],
default_aliases: &["smr"],
allow_in_dm: false,
default_permission: 7,
+79
View File
@@ -0,0 +1,79 @@
use serenity::builder::CreateEmbed;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::automod_service::pool;
use crate::commands::common::{parse_role, send_embed};
use crate::db;
pub async fn handle_set_muterole(ctx: &Context, msg: &Message, args: &[&str]) {
let Some(guild_id) = msg.guild_id else {
return;
};
let Some(raw_role) = args.get(1) else {
send_embed(
ctx,
msg,
CreateEmbed::new()
.title("Set MuteRole")
.description("Usage: +setmuterole <@role/ID/nom>")
.color(0xED4245),
)
.await;
return;
};
let Ok(guild) = guild_id.to_partial_guild(&ctx.http).await else {
return;
};
let Some(role) = parse_role(&guild, raw_role) else {
return;
};
let Some(pool) = pool(ctx).await else {
return;
};
let bot_id = ctx.cache.current_user().id.get() as i64;
if db::set_mute_role(
&pool,
bot_id,
guild_id.get() as i64,
Some(role.id.get() as i64),
)
.await
.is_err()
{
return;
}
send_embed(
ctx,
msg,
CreateEmbed::new()
.title("MuteRole")
.description(format!("Role muet defini sur <@&{}>.", role.id.get()))
.color(0x57F287),
)
.await;
}
pub struct SetMuteRoleCommand;
pub static COMMAND_DESCRIPTOR: SetMuteRoleCommand = SetMuteRoleCommand;
impl crate::commands::command_contract::CommandSpec for SetMuteRoleCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "setmuterole",
category: "mod",
params: "muterole <@role/ID/nom>",
description: "Definit le role utilise pour le mute lorsque le mode timeout est desactive.",
examples: &["+setmuterole @Muted", "+help setmuterole"],
default_aliases: &["smr"],
allow_in_dm: false,
default_permission: 7,
}
}
}