mirror of
https://github.com/arthur-pbty/shadowbot.git
synced 2026-06-03 15:07:37 +02:00
refactor: réorganiser les modules et améliorer la lisibilité du code
This commit is contained in:
+4
-4
@@ -186,12 +186,12 @@ pub mod renew;
|
||||
pub mod reroll;
|
||||
#[path = "infos/role.rs"]
|
||||
pub mod role;
|
||||
#[path = "roles/rolemenu.rs"]
|
||||
pub mod rolemenu;
|
||||
#[path = "logs/rolelog.rs"]
|
||||
pub mod rolelog;
|
||||
#[path = "infos/rolemembers.rs"]
|
||||
pub mod rolemembers;
|
||||
#[path = "roles/rolemenu.rs"]
|
||||
pub mod rolemenu;
|
||||
#[path = "moderation/sanctions.rs"]
|
||||
pub mod sanctions;
|
||||
#[path = "outils/say.rs"]
|
||||
@@ -210,14 +210,14 @@ pub mod set_modlogs;
|
||||
pub mod shadowbot;
|
||||
#[path = "infos/showpics.rs"]
|
||||
pub mod showpics;
|
||||
#[path = "salons_vocal/slowmode.rs"]
|
||||
pub mod slowmode;
|
||||
#[path = "outils/snipe.rs"]
|
||||
pub mod snipe;
|
||||
#[path = "bot/stream.rs"]
|
||||
pub mod stream;
|
||||
#[path = "outils/suggestion.rs"]
|
||||
pub mod suggestion;
|
||||
#[path = "salons_vocal/slowmode.rs"]
|
||||
pub mod slowmode;
|
||||
#[path = "roles/sync.rs"]
|
||||
pub mod sync;
|
||||
#[path = "moderation/tempban.rs"]
|
||||
|
||||
@@ -12,7 +12,7 @@ use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
use crate::commands::alias::resolve_alias;
|
||||
use crate::commands::common::{add_list_fields, truncate_text};
|
||||
use crate::commands::common::truncate_text;
|
||||
use crate::db::{
|
||||
DbPoolKey, get_help_aliases_enabled, get_help_perms_enabled, get_help_type,
|
||||
list_command_aliases,
|
||||
@@ -529,29 +529,34 @@ fn build_help_embed(
|
||||
let page = &HELP_PAGES[page_index];
|
||||
let lines = help_page_content(page, alias_map, state.aliases_enabled, state.perms_enabled);
|
||||
|
||||
let mut embed = CreateEmbed::new()
|
||||
.title(format!("Aide · {}", page.title))
|
||||
.description(format!(
|
||||
"Page {}/{} · mode `{}` · aliases {} · perms {}\n{}",
|
||||
page_index + 1,
|
||||
HELP_PAGES.len(),
|
||||
state.layout.as_str(),
|
||||
if state.aliases_enabled {
|
||||
"activés"
|
||||
} else {
|
||||
"désactivés"
|
||||
},
|
||||
if state.perms_enabled {
|
||||
"activées"
|
||||
} else {
|
||||
"désactivées"
|
||||
},
|
||||
page.description,
|
||||
))
|
||||
.color(0x5865F2);
|
||||
let header = format!(
|
||||
"Page {}/{} · mode `{}` · aliases {} · perms {}\n{}",
|
||||
page_index + 1,
|
||||
HELP_PAGES.len(),
|
||||
state.layout.as_str(),
|
||||
if state.aliases_enabled {
|
||||
"activés"
|
||||
} else {
|
||||
"désactivés"
|
||||
},
|
||||
if state.perms_enabled {
|
||||
"activées"
|
||||
} else {
|
||||
"désactivées"
|
||||
},
|
||||
page.description,
|
||||
);
|
||||
|
||||
embed = add_list_fields(embed, &lines, "Commandes");
|
||||
embed
|
||||
let commands_intro = "\n\n**Commandes**\n";
|
||||
let available = 4096usize
|
||||
.saturating_sub(header.chars().count())
|
||||
.saturating_sub(commands_intro.chars().count());
|
||||
let commands_block = truncate_text(&lines.join("\n"), available);
|
||||
|
||||
CreateEmbed::new()
|
||||
.title(format!("Aide · {}", page.title))
|
||||
.description(format!("{}{}{}", header, commands_intro, commands_block))
|
||||
.color(0x5865F2)
|
||||
}
|
||||
|
||||
fn help_components(owner_id: UserId, page_index: usize, state: &HelpState) -> Vec<CreateActionRow> {
|
||||
|
||||
@@ -83,10 +83,7 @@ fn parse_toggle_role_id(custom_id: &str) -> Option<RoleId> {
|
||||
}
|
||||
|
||||
fn parse_role_id_input(raw: &str) -> Option<RoleId> {
|
||||
let cleaned = raw
|
||||
.trim()
|
||||
.trim_start_matches("<@&")
|
||||
.trim_end_matches('>');
|
||||
let cleaned = raw.trim().trim_start_matches("<@&").trim_end_matches('>');
|
||||
cleaned.parse::<u64>().ok().map(RoleId::new)
|
||||
}
|
||||
|
||||
@@ -183,10 +180,7 @@ fn message_has_role_button(message: &Message, role_id: RoleId) -> bool {
|
||||
for row in &message.components {
|
||||
for component in &row.components {
|
||||
if let ActionRowComponent::Button(button) = component {
|
||||
if let ButtonKind::NonLink {
|
||||
custom_id, ..
|
||||
} = &button.data
|
||||
{
|
||||
if let ButtonKind::NonLink { custom_id, .. } = &button.data {
|
||||
if custom_id == &wanted {
|
||||
return true;
|
||||
}
|
||||
@@ -406,24 +400,23 @@ pub async fn handle_component_interaction(ctx: &Context, component: &ComponentIn
|
||||
}
|
||||
|
||||
if action == "addrole" {
|
||||
let modal =
|
||||
CreateModal::new(modal_custom_id("addrole", target), "Ajouter un bouton role")
|
||||
.components(vec![
|
||||
CreateActionRow::InputText(
|
||||
CreateInputText::new(InputTextStyle::Short, "Label du bouton", "label")
|
||||
.required(true)
|
||||
.max_length(80),
|
||||
),
|
||||
CreateActionRow::InputText(
|
||||
CreateInputText::new(InputTextStyle::Short, "Role ID ou mention", "role_id")
|
||||
.required(true),
|
||||
),
|
||||
CreateActionRow::InputText(
|
||||
CreateInputText::new(InputTextStyle::Short, "Style", "style")
|
||||
.required(false)
|
||||
.placeholder("secondary | primary | success | danger"),
|
||||
),
|
||||
]);
|
||||
let modal = CreateModal::new(modal_custom_id("addrole", target), "Ajouter un bouton role")
|
||||
.components(vec![
|
||||
CreateActionRow::InputText(
|
||||
CreateInputText::new(InputTextStyle::Short, "Label du bouton", "label")
|
||||
.required(true)
|
||||
.max_length(80),
|
||||
),
|
||||
CreateActionRow::InputText(
|
||||
CreateInputText::new(InputTextStyle::Short, "Role ID ou mention", "role_id")
|
||||
.required(true),
|
||||
),
|
||||
CreateActionRow::InputText(
|
||||
CreateInputText::new(InputTextStyle::Short, "Style", "style")
|
||||
.required(false)
|
||||
.placeholder("secondary | primary | success | danger"),
|
||||
),
|
||||
]);
|
||||
|
||||
let _ = component
|
||||
.create_response(&ctx.http, CreateInteractionResponse::Modal(modal))
|
||||
@@ -444,8 +437,12 @@ pub async fn handle_modal_interaction(ctx: &Context, modal: &ModalInteraction) -
|
||||
};
|
||||
|
||||
if modal.user.id.get() != target.owner_id {
|
||||
respond_modal_ephemeral(ctx, modal, "Seul l'auteur du panneau peut soumettre ce formulaire.")
|
||||
.await;
|
||||
respond_modal_ephemeral(
|
||||
ctx,
|
||||
modal,
|
||||
"Seul l'auteur du panneau peut soumettre ce formulaire.",
|
||||
)
|
||||
.await;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -508,8 +505,7 @@ pub async fn handle_modal_interaction(ctx: &Context, modal: &ModalInteraction) -
|
||||
if edited {
|
||||
respond_modal_ephemeral(ctx, modal, "Embed du rolemenu mis a jour.").await;
|
||||
} else {
|
||||
respond_modal_ephemeral(ctx, modal, "Impossible de mettre a jour l'embed cible.")
|
||||
.await;
|
||||
respond_modal_ephemeral(ctx, modal, "Impossible de mettre a jour l'embed cible.").await;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -589,10 +585,14 @@ impl crate::commands::command_contract::CommandSpec for RolemenuCommand {
|
||||
params: "[message_id]",
|
||||
summary: "Cree ou modifie un menu de roles",
|
||||
description: "Ouvre un panneau interactif (boutons + modales) pour construire un embed de roles et des boutons auto-roles.",
|
||||
examples: &["+rolemenu", "+rolemenu 123456789012345678", "+help rolemenu"],
|
||||
examples: &[
|
||||
"+rolemenu",
|
||||
"+rolemenu 123456789012345678",
|
||||
"+help rolemenu",
|
||||
],
|
||||
default_aliases: &["rmenu"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 8,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,11 @@ pub async fn handle_slowmode(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
if seconds == 0 {
|
||||
format!("Mode lent desactive sur <#{}>.", target.get())
|
||||
} else {
|
||||
format!("Mode lent de {}s applique sur <#{}>.", seconds, target.get())
|
||||
format!(
|
||||
"Mode lent de {}s applique sur <#{}>.",
|
||||
seconds,
|
||||
target.get()
|
||||
)
|
||||
}
|
||||
} else {
|
||||
"Echec de mise a jour du mode lent (verifie le type de salon et les permissions)."
|
||||
@@ -114,14 +118,10 @@ impl crate::commands::command_contract::CommandSpec for SlowmodeCommand {
|
||||
params: "<duree> [salon]",
|
||||
summary: "Change le mode lent d'un salon",
|
||||
description: "Modifie la duree du mode lent sur un salon texte (maximum 6 heures).",
|
||||
examples: &[
|
||||
"+slowmode 10s",
|
||||
"+slowmode 2m #general",
|
||||
"+slowmode off",
|
||||
],
|
||||
examples: &["+slowmode 10s", "+slowmode 2m #general", "+slowmode off"],
|
||||
default_aliases: &["sm"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 8,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,9 @@ use crate::commands::{
|
||||
online, owner, perms, pic, ping, playto, prefix, raidlog, rename, renew, reroll, role, rolelog,
|
||||
rolemembers, rolemenu, sanctions, say, server, serverinfo, set, set_boostembed, set_modlogs,
|
||||
shadowbot, showpics, slowmode, snipe, stream, suggestion, sync, tempban, tempcmute, tempmute,
|
||||
temprole, tempvoc,
|
||||
tempvoc_cmd, theme, ticket, ticket_member, tickets, unban, unbanall, unbl, uncmute, unhide,
|
||||
unhideall, unlock, unlockall, unmassiverole, unmute, unmuteall, unowner, untemprole, user,
|
||||
viewlogs, vocinfo, voicekick, voicelog, voicemove, warn, watch,
|
||||
temprole, tempvoc, tempvoc_cmd, theme, ticket, ticket_member, tickets, unban, unbanall, unbl,
|
||||
uncmute, unhide, unhideall, unlock, unlockall, unmassiverole, unmute, unmuteall, unowner,
|
||||
untemprole, user, viewlogs, vocinfo, voicekick, voicelog, voicemove, warn, watch,
|
||||
};
|
||||
use crate::commands::{alladmins, allbots, allperms, botadmins};
|
||||
use crate::db::{DbPoolKey, upsert_message_observed};
|
||||
|
||||
Reference in New Issue
Block a user