mirror of
https://github.com/arthur-pbty/shadowbot.git
synced 2026-06-10 19:04:31 +02:00
netoyage et optimisation des commande pour que elle soit trier correctement
This commit is contained in:
+44
-26
@@ -18,7 +18,7 @@ pub async fn handle_alias(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
};
|
||||
|
||||
if args.len() == 1 {
|
||||
if args.is_empty() {
|
||||
let aliases = list_command_aliases(&pool, bot_id)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
@@ -44,28 +44,6 @@ pub async fn handle_alias(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if args[0].eq_ignore_ascii_case("remove") || args[0].eq_ignore_ascii_case("delete") {
|
||||
let alias_name = args[1].trim_start_matches('+').to_lowercase();
|
||||
if alias_name.is_empty() {
|
||||
let embed = serenity::builder::CreateEmbed::new()
|
||||
.title("Erreur")
|
||||
.description("Alias invalide.")
|
||||
.color(0xED4245);
|
||||
send_embed(ctx, msg, embed).await;
|
||||
return;
|
||||
}
|
||||
|
||||
let removed = remove_command_alias(&pool, bot_id, &alias_name)
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
let embed = serenity::builder::CreateEmbed::new()
|
||||
.title("Alias supprimé")
|
||||
.description(format!("`{}` : {} suppression(s).", alias_name, removed))
|
||||
.color(0x57F287);
|
||||
send_embed(ctx, msg, embed).await;
|
||||
return;
|
||||
}
|
||||
|
||||
let command = args[0].trim_start_matches('+').to_lowercase();
|
||||
let is_known = all_command_keys().iter().any(|candidate| candidate == &command)
|
||||
|| crate::commands::command_metadata_by_key(&command).is_some();
|
||||
@@ -99,6 +77,46 @@ pub async fn handle_alias(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
send_embed(ctx, msg, embed).await;
|
||||
}
|
||||
|
||||
pub async fn handle_unalias(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
let bot_id = ctx.cache.current_user().id;
|
||||
let Some(pool) = pool(ctx).await else {
|
||||
let embed = serenity::builder::CreateEmbed::new()
|
||||
.title("Erreur")
|
||||
.description("DB indisponible.")
|
||||
.color(0xED4245);
|
||||
send_embed(ctx, msg, embed).await;
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(raw_alias) = args.first() else {
|
||||
let embed = serenity::builder::CreateEmbed::new()
|
||||
.title("Erreur")
|
||||
.description("Usage: `+unalias <alias>`")
|
||||
.color(0xED4245);
|
||||
send_embed(ctx, msg, embed).await;
|
||||
return;
|
||||
};
|
||||
|
||||
let alias_name = raw_alias.trim_start_matches('+').to_lowercase();
|
||||
if alias_name.is_empty() {
|
||||
let embed = serenity::builder::CreateEmbed::new()
|
||||
.title("Erreur")
|
||||
.description("Alias invalide.")
|
||||
.color(0xED4245);
|
||||
send_embed(ctx, msg, embed).await;
|
||||
return;
|
||||
}
|
||||
|
||||
let removed = remove_command_alias(&pool, bot_id, &alias_name)
|
||||
.await
|
||||
.unwrap_or(0);
|
||||
let embed = serenity::builder::CreateEmbed::new()
|
||||
.title("Alias supprimé")
|
||||
.description(format!("`{}` : {} suppression(s).", alias_name, removed))
|
||||
.color(0x57F287);
|
||||
send_embed(ctx, msg, embed).await;
|
||||
}
|
||||
|
||||
async fn pool(ctx: &Context) -> Option<sqlx::PgPool> {
|
||||
let data = ctx.data.read().await;
|
||||
data.get::<DbPoolKey>().cloned()
|
||||
@@ -124,9 +142,9 @@ impl crate::commands::command_contract::CommandSpec for AliasCommand {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "alias",
|
||||
category: "perms",
|
||||
params: "<commande> <alias> | remove <alias> | list",
|
||||
description: "Liste, ajoute ou supprime des aliases de commandes stockes en base.",
|
||||
examples: &["+alias", "+as", "+help alias"],
|
||||
params: "[<commande> <alias>]",
|
||||
description: "Liste les aliases (sans argument) ou ajoute un alias de commande.",
|
||||
examples: &["+alias", "+alias mute m", "+help alias"],
|
||||
default_aliases: &["als"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 6,
|
||||
|
||||
@@ -11,16 +11,16 @@ pub async fn handle_del(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if args.len() < 2 || !args[0].eq_ignore_ascii_case("perm") {
|
||||
if args.is_empty() {
|
||||
let embed = CreateEmbed::new()
|
||||
.title("Erreur")
|
||||
.description("Usage: `+delperm <role>`")
|
||||
.description("Usage: `+delperm <role/membre>`")
|
||||
.color(0xED4245);
|
||||
send_embed(ctx, msg, embed).await;
|
||||
return;
|
||||
}
|
||||
|
||||
let Some((scope_type, scope_id)) = parse_user_or_role(args[1]) else {
|
||||
let Some((scope_type, scope_id)) = parse_user_or_role(args[0]) else {
|
||||
let embed = CreateEmbed::new()
|
||||
.title("Erreur")
|
||||
.description("Role/membre invalide.")
|
||||
@@ -50,20 +50,3 @@ pub async fn handle_del(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
send_embed(ctx, msg, embed).await;
|
||||
}
|
||||
|
||||
pub struct DelCommand;
|
||||
pub static COMMAND_DESCRIPTOR: DelCommand = DelCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for DelCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "del",
|
||||
category: "perms",
|
||||
params: "perm <@&rôle/@membre/ID>",
|
||||
description: "Supprime les permissions ACL associees a un role ou utilisateur.",
|
||||
examples: &["+del", "+dl", "+help del"],
|
||||
default_aliases: &["dlp"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 7,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_delperm_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::del::handle_del(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct DelpermCommand;
|
||||
pub static COMMAND_DESCRIPTOR: DelpermCommand = DelpermCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for DelpermCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "delperm",
|
||||
category: "perms",
|
||||
params: "<@&role/@membre/ID>",
|
||||
description: "Supprime les permissions ACL associees a un role ou utilisateur.",
|
||||
examples: &["+delperm @Role", "+help delperm"],
|
||||
default_aliases: &["dlp"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 7,
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
-52
@@ -133,8 +133,8 @@ fn help_page_for_command(
|
||||
) -> &'static str {
|
||||
match meta.name {
|
||||
"modlog" | "messagelog" | "voicelog" | "boostlog" | "rolelog" | "raidlog"
|
||||
| "autoconfiglog" | "nolog" | "join" | "boostembed" | "setmodlogs" | "setboostembed"
|
||||
| "leavesettings" | "viewlogs" => "logs",
|
||||
| "autoconfiglog" | "nolog" | "joinsettings" | "boostembed" | "setmodlogs"
|
||||
| "setboostembed" | "leavesettings" | "viewlogs" => "logs",
|
||||
"warn"
|
||||
| "mute"
|
||||
| "tempmute"
|
||||
@@ -164,14 +164,19 @@ fn help_page_for_command(
|
||||
"giveaway" | "end" | "reroll" | "choose" | "calc" | "emoji" | "embed" | "say"
|
||||
| "create" | "newsticker" | "button" | "autoreact" | "snipe" | "loading" | "backup"
|
||||
| "autobackup" => "outils",
|
||||
"shadowbot" | "set" | "theme" | "playto" | "listen" | "watch" | "compet" | "stream"
|
||||
| "removeactivity" | "online" | "idle" | "dnd" | "invisible" | "change" | "changeall" => {
|
||||
"shadowbot" | "setname" | "setpic" | "setbanner" | "setprofil" | "setperm"
|
||||
| "theme" | "playto" | "listen" | "watch" | "compet" | "stream"
|
||||
| "removeactivity" | "online" | "idle" | "dnd" | "invisible" | "change"
|
||||
| "changereset" | "changeall" => {
|
||||
"bot"
|
||||
}
|
||||
"owner" | "unowner" | "clearowners" | "bl" | "unbl" | "blinfo" | "clearbl"
|
||||
| "allbots" | "alladmins" | "botadmins" | "mainprefix" | "prefix" | "mp" | "invite"
|
||||
| "leave" | "discussion" => "administration",
|
||||
"perms" | "del" | "clearperms" | "allperms" | "alias" | "help" | "helpsetting" => {
|
||||
| "allbots" | "alladmins" | "botadmins" | "mainprefix" | "prefix" | "mp"
|
||||
| "mpsettings" | "mpsent" | "mpdelete" | "invite" | "leave" | "discussion" => {
|
||||
"administration"
|
||||
}
|
||||
"perms" | "delperm" | "clearperms" | "allperms" | "alias" | "help"
|
||||
| "helpsetting" => {
|
||||
"permissions"
|
||||
}
|
||||
_ => match meta.category {
|
||||
@@ -193,6 +198,7 @@ fn help_page_for_command(
|
||||
"administration" => "administration",
|
||||
"permissions" => "permissions",
|
||||
"general" => "infos",
|
||||
"automation" => "outils",
|
||||
"profile" => "bot",
|
||||
"admin" => "administration",
|
||||
_ => "infos",
|
||||
@@ -332,48 +338,6 @@ async fn aliases_map(ctx: &Context) -> BTreeMap<String, Vec<String>> {
|
||||
|
||||
fn command_doc(key: &str) -> Option<CommandDoc> {
|
||||
let (meta, command, acl_key, alias_source_key) = match key {
|
||||
"mpsettings" => (
|
||||
crate::commands::command_metadata_by_key("mp")?,
|
||||
"mpsettings",
|
||||
"mpsettings",
|
||||
Some("mp"),
|
||||
),
|
||||
"mpsent" => (
|
||||
crate::commands::command_metadata_by_key("mp")?,
|
||||
"mpsent",
|
||||
"mpsent",
|
||||
Some("mp"),
|
||||
),
|
||||
"mpdelete" => (
|
||||
crate::commands::command_metadata_by_key("mp")?,
|
||||
"mpdelete",
|
||||
"mpdelete",
|
||||
Some("mp"),
|
||||
),
|
||||
"serverlist" => (
|
||||
crate::commands::command_metadata_by_key("server")?,
|
||||
"serverlist",
|
||||
"serverlist",
|
||||
Some("server"),
|
||||
),
|
||||
"changereset" => (
|
||||
crate::commands::command_metadata_by_key("change")?,
|
||||
"changereset",
|
||||
"changereset",
|
||||
Some("change"),
|
||||
),
|
||||
"setperm" => (
|
||||
crate::commands::command_metadata_by_key("set")?,
|
||||
"setperm",
|
||||
"setperm",
|
||||
Some("set"),
|
||||
),
|
||||
"delperm" => (
|
||||
crate::commands::command_metadata_by_key("del")?,
|
||||
"delperm",
|
||||
"delperm",
|
||||
Some("del"),
|
||||
),
|
||||
other => {
|
||||
let meta = crate::commands::command_metadata_by_key(other)?;
|
||||
(meta, meta.name, meta.name, Some(meta.name))
|
||||
@@ -423,22 +387,37 @@ fn help_lookup_to_key(input: &str) -> Option<&'static str> {
|
||||
"member" => Some("member"),
|
||||
"pic" => Some("pic"),
|
||||
"banner" => Some("banner"),
|
||||
"server" => Some("server"),
|
||||
"server" | "server list" => Some("serverlist"),
|
||||
"server pic" | "serverpic" => Some("serverpic"),
|
||||
"server banner" | "serverbanner" => Some("serverbanner"),
|
||||
"serverlist" => Some("serverlist"),
|
||||
"suggestion settings" | "suggestionsettings" => Some("suggestionsettings"),
|
||||
"snipe" => Some("snipe"),
|
||||
"emoji" => Some("emoji"),
|
||||
"giveaway" => Some("giveaway"),
|
||||
"end" | "endgiveaway" => Some("end"),
|
||||
"end" => Some("end"),
|
||||
"end giveaway" | "endgiveaway" => Some("endgiveaway"),
|
||||
"reroll" => Some("reroll"),
|
||||
"choose" => Some("choose"),
|
||||
"embed" => Some("embed"),
|
||||
"backup" | "backup list" | "backup delete" | "backup load" => Some("backup"),
|
||||
"autopublish" => Some("autopublish"),
|
||||
"autopublish on" | "autopublishon" => Some("autopublishon"),
|
||||
"autopublish off" | "autopublishoff" => Some("autopublishoff"),
|
||||
"autobackup" => Some("autobackup"),
|
||||
"loading" => Some("loading"),
|
||||
"create" => Some("create"),
|
||||
"newsticker" => Some("newsticker"),
|
||||
"piconly" => Some("piconly"),
|
||||
"piconly add" | "piconlyadd" => Some("piconlyadd"),
|
||||
"piconly del" | "piconly remove" | "piconly delete" | "piconlydel" => {
|
||||
Some("piconlydel")
|
||||
}
|
||||
"massiverole" => Some("massiverole"),
|
||||
"unmassiverole" => Some("unmassiverole"),
|
||||
"noderank" => Some("noderank"),
|
||||
"noderank add" | "noderankadd" => Some("noderankadd"),
|
||||
"noderank del" | "noderank remove" | "noderankdel" => Some("noderankdel"),
|
||||
"voicemove" => Some("voicemove"),
|
||||
"voicekick" => Some("voicekick"),
|
||||
"cleanup" => Some("cleanup"),
|
||||
@@ -452,7 +431,10 @@ fn help_lookup_to_key(input: &str) -> Option<&'static str> {
|
||||
"autoreact" => Some("autoreact"),
|
||||
"calc" => Some("calc"),
|
||||
"shadowbot" => Some("shadowbot"),
|
||||
"set" => Some("set"),
|
||||
"set" | "set name" | "setname" => Some("setname"),
|
||||
"set pic" | "setpic" => Some("setpic"),
|
||||
"set banner" | "setbanner" => Some("setbanner"),
|
||||
"set profil" | "setprofil" => Some("setprofil"),
|
||||
"theme" => Some("theme"),
|
||||
"playto" => Some("playto"),
|
||||
"listen" => Some("listen"),
|
||||
@@ -479,6 +461,7 @@ fn help_lookup_to_key(input: &str) -> Option<&'static str> {
|
||||
"say" => Some("say"),
|
||||
"invite" => Some("invite"),
|
||||
"leave" => Some("leave"),
|
||||
"join" | "join settings" | "joinsettings" => Some("joinsettings"),
|
||||
"change" => Some("change"),
|
||||
"changereset" => Some("changereset"),
|
||||
"changeall" => Some("changeall"),
|
||||
@@ -488,8 +471,13 @@ fn help_lookup_to_key(input: &str) -> Option<&'static str> {
|
||||
"allperms" => Some("allperms"),
|
||||
"setperm" => Some("setperm"),
|
||||
"delperm" => Some("delperm"),
|
||||
"punish" => Some("punish"),
|
||||
"punish setup" | "punishsetup" => Some("punishsetup"),
|
||||
"punish add" | "punishadd" => Some("punishadd"),
|
||||
"punish del" | "punishdel" => Some("punishdel"),
|
||||
"clearperms" => Some("clearperms"),
|
||||
"alias" => Some("alias"),
|
||||
"alias remove" | "alias delete" | "unalias" => Some("unalias"),
|
||||
"helpsetting" | "helpetting" => Some("helpsetting"),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_unalias_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::alias::handle_unalias(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct UnaliasCommand;
|
||||
pub static COMMAND_DESCRIPTOR: UnaliasCommand = UnaliasCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for UnaliasCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "unalias",
|
||||
category: "perms",
|
||||
params: "<alias>",
|
||||
description: "Supprime un alias de commande en base.",
|
||||
examples: &["+unalias m", "+help unalias"],
|
||||
default_aliases: &["uals"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 6,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user