Files
shadowbot/src/commands/admin/blinfo.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

97 lines
3.0 KiB
Rust

use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::admin_common::{ensure_owner, parse_user_id};
use crate::commands::common::{send_embed, truncate_text};
use crate::db::{DbPoolKey, get_blacklist_info};
pub async fn handle_blinfo(ctx: &Context, msg: &Message, args: &[&str]) {
if ensure_owner(ctx, msg).await.is_err() {
return;
}
if args.is_empty() {
let embed = serenity::builder::CreateEmbed::new()
.title("Erreur")
.description("Usage: `+blinfo <@membre/ID>`")
.color(0xED4245);
send_embed(ctx, msg, embed).await;
return;
}
let Some(target) = parse_user_id(args[0]) else {
let embed = serenity::builder::CreateEmbed::new()
.title("Erreur")
.description("Membre invalide.")
.color(0xED4245);
send_embed(ctx, msg, embed).await;
return;
};
let bot_id = ctx.cache.current_user().id;
let pool = {
let data = ctx.data.read().await;
data.get::<DbPoolKey>().cloned()
};
let Some(pool) = pool else {
let embed = serenity::builder::CreateEmbed::new()
.title("Erreur")
.description("DB indisponible.")
.color(0xED4245);
send_embed(ctx, msg, embed).await;
return;
};
let info = get_blacklist_info(&pool, bot_id, target)
.await
.ok()
.flatten();
let Some(info) = info else {
let embed = serenity::builder::CreateEmbed::new()
.title("Blacklist")
.description("Ce membre n'est pas blacklisté.")
.color(0xFF0000);
send_embed(ctx, msg, embed).await;
return;
};
let added_at = crate::commands::common::discord_ts(
Timestamp::from_unix_timestamp(info.added_at.timestamp())
.unwrap_or_else(|_| Timestamp::now()),
"F",
);
let by = info
.added_by
.map(|id| format!("<@{}>", id))
.unwrap_or_else(|| "Inconnu".to_string());
let embed = serenity::builder::CreateEmbed::new()
.title("Informations blacklist")
.field("Membre", format!("<@{}>", info.user_id), true)
.field("Ajouté par", by, true)
.field("Ajouté le", added_at, true)
.field("Raison", truncate_text(&info.reason, 1024), false)
.color(0xFF0000);
send_embed(ctx, msg, embed).await;
}
pub struct BlinfoCommand;
pub static COMMAND_DESCRIPTOR: BlinfoCommand = BlinfoCommand;
impl crate::commands::command_contract::CommandSpec for BlinfoCommand {
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
crate::commands::command_contract::CommandMetadata {
name: "blinfo",
category: "admin",
params: "<@membre/ID>",
summary: "Affiche les details blacklist",
description: "Affiche les details de blacklist pour un utilisateur donne.",
examples: &["+blinfo", "+bo", "+help blinfo"],
default_aliases: &["bli"],
default_permission: 9,
}
}
}