mirror of
https://github.com/arthur-pbty/shadowbot.git
synced 2026-06-05 13:52:37 +02:00
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.
This commit is contained in:
@@ -1,10 +1,86 @@
|
||||
use serenity::builder::CreateEmbed;
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
use crate::commands::advanced_tools;
|
||||
use crate::commands::common::{send_embed, theme_color};
|
||||
|
||||
fn emoji_url_from_source(msg: &Message, source: &str) -> String {
|
||||
if source.starts_with("http://") || source.starts_with("https://") {
|
||||
return source.to_string();
|
||||
}
|
||||
|
||||
if source.starts_with("<:") || source.starts_with("<a:") {
|
||||
let cleaned = source.trim_matches(|c| c == '<' || c == '>');
|
||||
let parts = cleaned.split(':').collect::<Vec<_>>();
|
||||
if parts.len() == 3 {
|
||||
let animated = parts[0] == "a";
|
||||
return format!(
|
||||
"https://cdn.discordapp.com/emojis/{}.{}",
|
||||
parts[2],
|
||||
if animated { "gif" } else { "png" }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(att) = msg.attachments.first() {
|
||||
return att.url.clone();
|
||||
}
|
||||
|
||||
String::new()
|
||||
}
|
||||
|
||||
pub async fn handle_create(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
advanced_tools::handle_create(ctx, msg, args).await;
|
||||
let Some(guild_id) = msg.guild_id else {
|
||||
return;
|
||||
};
|
||||
|
||||
if args.len() < 2 {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Create Emoji")
|
||||
.description("Usage: +create <emoji/url> <nom>")
|
||||
.color(0xED4245),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
let image_url = emoji_url_from_source(msg, args[0]);
|
||||
if image_url.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let response = match reqwest::get(&image_url).await {
|
||||
Ok(r) => r,
|
||||
Err(_) => return,
|
||||
};
|
||||
let bytes = match response.bytes().await {
|
||||
Ok(b) => b,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
let data_uri = format!("data:image/png;base64,{}", {
|
||||
use base64::Engine;
|
||||
base64::engine::general_purpose::STANDARD.encode(bytes)
|
||||
});
|
||||
|
||||
let result = guild_id.create_emoji(&ctx.http, args[1], &data_uri).await;
|
||||
|
||||
let embed = if let Ok(emoji) = result {
|
||||
CreateEmbed::new()
|
||||
.title("Emoji")
|
||||
.description(format!("Emoji cree: {}", emoji))
|
||||
.color(theme_color(ctx).await)
|
||||
} else {
|
||||
CreateEmbed::new()
|
||||
.title("Emoji")
|
||||
.description("Impossible de creer l'emoji.")
|
||||
.color(0xED4245)
|
||||
};
|
||||
|
||||
send_embed(ctx, msg, embed).await;
|
||||
}
|
||||
|
||||
pub struct CreateCommand;
|
||||
@@ -13,8 +89,7 @@ pub static COMMAND_DESCRIPTOR: CreateCommand = CreateCommand;
|
||||
impl crate::commands::command_contract::CommandSpec for CreateCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
key: "create",
|
||||
command: "create",
|
||||
name: "create",
|
||||
category: "admin",
|
||||
params: "[emoji/url] [nom]",
|
||||
summary: "Cree un emoji custom",
|
||||
@@ -23,7 +98,6 @@ impl crate::commands::command_contract::CommandSpec for CreateCommand {
|
||||
"+create <:blob:123456789012345678> blobcopy",
|
||||
"+create https://... logo",
|
||||
],
|
||||
alias_source_key: "create",
|
||||
default_aliases: &["mkemoji", "ce"],
|
||||
default_permission: 8,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user