Files
shadowbot/src/commands/general/banner.rs
T
Puechberty Arthur e1016e0af1 Refactor profile commands to improve status handling and embed responses
- Updated `handle_idle`, `handle_invisible`, `handle_online`, `handle_listen`, `handle_playto`, `handle_stream`, `handle_watch`, and `handle_remove_activity` functions to use a unified approach for setting bot status and sending embed messages.
- Removed dependency on `botconfig_common` and replaced it with direct database interactions for status management.
- Added new helper functions for logging and moderation channel management.
- Introduced permission handling improvements in `set` command with better error messages and user feedback.
- Created new utility functions for parsing user and role IDs, ensuring better command access control.
2026-04-10 06:42:46 +02:00

78 lines
2.4 KiB
Rust

use serenity::builder::CreateEmbed;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::common::send_embed;
pub async fn handle_banner(ctx: &Context, msg: &Message, args: &[&str]) {
let user = if args.is_empty() {
msg.author.clone()
} else {
let user_id = args[0]
.trim_start_matches('<')
.trim_end_matches('>')
.trim_start_matches('@')
.trim_start_matches('!')
.parse::<u64>()
.ok()
.map(UserId::new);
if let Some(uid) = user_id {
match ctx.http.get_user(uid).await {
Ok(u) => u,
Err(_) => {
let embed = CreateEmbed::new()
.title("Erreur")
.description("Utilisateur non trouvé.")
.color(0xED4245);
send_embed(ctx, msg, embed).await;
return;
}
}
} else {
let embed = CreateEmbed::new()
.title("Erreur")
.description("Impossible de parser l'utilisateur.")
.color(0xED4245);
send_embed(ctx, msg, embed).await;
return;
}
};
let banner_url = user.banner_url().unwrap_or_default();
if banner_url.is_empty() {
let embed = CreateEmbed::new()
.title("Erreur")
.description(format!("{} n'a pas de bannière.", user.name))
.color(0xED4245);
send_embed(ctx, msg, embed).await;
return;
}
let embed = CreateEmbed::new()
.title(format!("Bannière de {}", user.name))
.image(banner_url)
.color(0x5865F2);
send_embed(ctx, msg, embed).await;
}
pub struct BannerCommand;
pub static COMMAND_DESCRIPTOR: BannerCommand = BannerCommand;
impl crate::commands::command_contract::CommandSpec for BannerCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "banner",
category: "general",
params: "<@membre/ID>",
summary: "Affiche la banniere utilisateur",
description: "Affiche la banniere de profil dun utilisateur cible ou de lauteur.",
examples: &["+banner", "+br", "+help banner"],
default_aliases: &["bnr"],
default_permission: 0,
}
}
}