mirror of
https://github.com/arthur-pbty/shadowbot.git
synced 2026-06-03 23:36:25 +02:00
netoyage et optimisation des commande pour que elle soit trier correctement
This commit is contained in:
@@ -39,7 +39,7 @@ impl crate::commands::command_contract::CommandSpec for ClearBadwordsCommand {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "clearbadwords",
|
||||
category: "mod",
|
||||
params: "badwords",
|
||||
params: "aucun",
|
||||
description: "Supprime l ensemble des mots interdits enregistres.",
|
||||
examples: &["+clearbadwords", "+help clearbadwords"],
|
||||
default_aliases: &["cbw"],
|
||||
|
||||
@@ -11,7 +11,7 @@ pub async fn handle_clear_limit(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(raw_value) = args.get(1) else {
|
||||
let Some(raw_value) = args.first() else {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
@@ -63,7 +63,7 @@ impl crate::commands::command_contract::CommandSpec for ClearLimitCommand {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "clearlimit",
|
||||
category: "mod",
|
||||
params: "limit <nombre>",
|
||||
params: "<nombre>",
|
||||
description: "Definit la limite max de messages supprimables avec +clear.",
|
||||
examples: &["+clearlimit 100", "+help clearlimit"],
|
||||
default_aliases: &["climit"],
|
||||
|
||||
@@ -10,11 +10,11 @@ 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 {
|
||||
if args.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(target) = parse_user_id(args[1]) else {
|
||||
let Some(target) = parse_user_id(args[0]) else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@ 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 {
|
||||
if args.len() < 2 {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(target) = parse_user_id(args[1]) else {
|
||||
let Some(target) = parse_user_id(args[0]) else {
|
||||
return;
|
||||
};
|
||||
let Ok(index) = args[2].parse::<usize>() else {
|
||||
let Ok(index) = args[1].parse::<usize>() else {
|
||||
return;
|
||||
};
|
||||
if index == 0 {
|
||||
|
||||
+149
-104
@@ -35,124 +35,169 @@ pub async fn handle_punish(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
let bot_id = ctx.cache.current_user().id.get() as i64;
|
||||
let guild_id_raw = guild_id.get() as i64;
|
||||
|
||||
if args.is_empty() {
|
||||
let rules = db::list_punish_rules(&pool, bot_id, guild_id_raw)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
let description = if rules.is_empty() {
|
||||
"Aucune regle.".to_string()
|
||||
} else {
|
||||
rules
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, rule)| describe_rule(idx + 1, rule))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
};
|
||||
|
||||
if !args.is_empty() {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description(description)
|
||||
.color(0x5865F2),
|
||||
.description("Usage: +punish")
|
||||
.color(0xED4245),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
if args[0].eq_ignore_ascii_case("setup") {
|
||||
let _ = db::setup_default_punish_rules(&pool, bot_id, guild_id_raw).await;
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description("Regles par defaut restaurees.")
|
||||
.color(0x57F287),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
let rules = db::list_punish_rules(&pool, bot_id, guild_id_raw)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
if args[0].eq_ignore_ascii_case("add") {
|
||||
if args.len() < 4 {
|
||||
return;
|
||||
}
|
||||
|
||||
let Ok(threshold) = args[1].parse::<i32>() else {
|
||||
return;
|
||||
};
|
||||
let Some(window_seconds) = parse_duration_to_seconds(args[2]) else {
|
||||
return;
|
||||
};
|
||||
let Some(sanction) = parse_sanction(args[3]) else {
|
||||
return;
|
||||
};
|
||||
let sanction_seconds = args.get(4).and_then(|raw| parse_duration_to_seconds(raw));
|
||||
|
||||
let _ = db::upsert_punish_rule(
|
||||
&pool,
|
||||
bot_id,
|
||||
guild_id_raw,
|
||||
threshold.clamp(1, 200),
|
||||
window_seconds,
|
||||
sanction,
|
||||
sanction_seconds,
|
||||
)
|
||||
.await;
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description("Regle ajoutee ou mise a jour.")
|
||||
.color(0x57F287),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
if args[0].eq_ignore_ascii_case("del") {
|
||||
let Some(raw_index) = args.get(1) else {
|
||||
return;
|
||||
};
|
||||
let Ok(index) = raw_index.parse::<usize>() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let rules = db::list_punish_rules(&pool, bot_id, guild_id_raw)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
if index == 0 || index > rules.len() {
|
||||
return;
|
||||
}
|
||||
|
||||
let rule = &rules[index - 1];
|
||||
let _ = db::delete_punish_rule_by_id(&pool, bot_id, guild_id_raw, rule.id).await;
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description(format!("Regle {} supprimee.", index))
|
||||
.color(0x57F287),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
let description = if rules.is_empty() {
|
||||
"Aucune regle.".to_string()
|
||||
} else {
|
||||
rules
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, rule)| describe_rule(idx + 1, rule))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
};
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description("Usage: +punish | +punish add <nombre> <duree> <sanction> [duree] | +punish del <numero> | +punish setup")
|
||||
.color(0xED4245),
|
||||
.description(description)
|
||||
.color(0x5865F2),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn handle_punishsetup(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 guild_id_raw = guild_id.get() as i64;
|
||||
|
||||
let _ = db::setup_default_punish_rules(&pool, bot_id, guild_id_raw).await;
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description("Regles par defaut restaurees.")
|
||||
.color(0x57F287),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn handle_punishadd(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 guild_id_raw = guild_id.get() as i64;
|
||||
|
||||
if args.len() < 3 {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description("Usage: +punishadd <nombre> <duree> <sanction> [duree]")
|
||||
.color(0xED4245),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
let Ok(threshold) = args[0].parse::<i32>() else {
|
||||
return;
|
||||
};
|
||||
let Some(window_seconds) = parse_duration_to_seconds(args[1]) else {
|
||||
return;
|
||||
};
|
||||
let Some(sanction) = parse_sanction(args[2]) else {
|
||||
return;
|
||||
};
|
||||
let sanction_seconds = args.get(3).and_then(|raw| parse_duration_to_seconds(raw));
|
||||
|
||||
let _ = db::upsert_punish_rule(
|
||||
&pool,
|
||||
bot_id,
|
||||
guild_id_raw,
|
||||
threshold.clamp(1, 200),
|
||||
window_seconds,
|
||||
sanction,
|
||||
sanction_seconds,
|
||||
)
|
||||
.await;
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description("Regle ajoutee ou mise a jour.")
|
||||
.color(0x57F287),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn handle_punishdel(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 guild_id_raw = guild_id.get() as i64;
|
||||
|
||||
let Some(raw_index) = args.first() else {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description("Usage: +punishdel <numero>")
|
||||
.color(0xED4245),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
};
|
||||
let Ok(index) = raw_index.parse::<usize>() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let rules = db::list_punish_rules(&pool, bot_id, guild_id_raw)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
if index == 0 || index > rules.len() {
|
||||
return;
|
||||
}
|
||||
|
||||
let rule = &rules[index - 1];
|
||||
let _ = db::delete_punish_rule_by_id(&pool, bot_id, guild_id_raw, rule.id).await;
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Punish")
|
||||
.description(format!("Regle {} supprimee.", index))
|
||||
.color(0x57F287),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -165,9 +210,9 @@ impl crate::commands::command_contract::CommandSpec for PunishCommand {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "punish",
|
||||
category: "mod",
|
||||
params: "[add <nombre> <duree> <sanction> [duree] | del <numero> | setup]",
|
||||
description: "Affiche et gere les sanctions automatiques appliquees selon les strikes.",
|
||||
examples: &["+punish", "+punish add 8 1h mute 30m", "+punish setup"],
|
||||
params: "aucun",
|
||||
description: "Affiche les sanctions automatiques appliquees selon les strikes.",
|
||||
examples: &["+punish", "+help punish"],
|
||||
default_aliases: &["pn"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 7,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_punishadd_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::punish::handle_punishadd(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct PunishaddCommand;
|
||||
pub static COMMAND_DESCRIPTOR: PunishaddCommand = PunishaddCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for PunishaddCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "punishadd",
|
||||
category: "mod",
|
||||
params: "<nombre> <duree> <sanction> [duree]",
|
||||
description: "Ajoute ou met a jour une regle Punish.",
|
||||
examples: &["+punishadd 8 1h mute 30m", "+help punishadd"],
|
||||
default_aliases: &["pna"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 7,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_punishdel_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::punish::handle_punishdel(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct PunishdelCommand;
|
||||
pub static COMMAND_DESCRIPTOR: PunishdelCommand = PunishdelCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for PunishdelCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "punishdel",
|
||||
category: "mod",
|
||||
params: "<numero>",
|
||||
description: "Supprime une regle Punish par son index.",
|
||||
examples: &["+punishdel 2", "+help punishdel"],
|
||||
default_aliases: &["pnd"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 7,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_punishsetup_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::punish::handle_punishsetup(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct PunishsetupCommand;
|
||||
pub static COMMAND_DESCRIPTOR: PunishsetupCommand = PunishsetupCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for PunishsetupCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "punishsetup",
|
||||
category: "mod",
|
||||
params: "aucun",
|
||||
description: "Recharge les regles Punish par defaut.",
|
||||
examples: &["+punishsetup", "+help punishsetup"],
|
||||
default_aliases: &["pnsetup"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 7,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ pub async fn handle_set_muterole(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(raw_role) = args.get(1) else {
|
||||
let Some(raw_role) = args.first() else {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
@@ -68,7 +68,7 @@ impl crate::commands::command_contract::CommandSpec for SetMuteRoleCommand {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "setmuterole",
|
||||
category: "mod",
|
||||
params: "muterole <@role/ID/nom>",
|
||||
params: "<@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"],
|
||||
|
||||
Reference in New Issue
Block a user