From 410215633d95fa3ded47d96b9207923671de5874 Mon Sep 17 00:00:00 2001 From: Cycle Five Date: Thu, 29 Feb 2024 23:01:06 -0500 Subject: [PATCH] user authorized message --- crack-core/src/commands/admin/authorize.rs | 33 ++++++++++++++++------ crack-core/src/messaging/message.rs | 15 ++++++++++ crack-core/src/messaging/messages.rs | 3 +- crack-core/src/utils.rs | 2 ++ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/crack-core/src/commands/admin/authorize.rs b/crack-core/src/commands/admin/authorize.rs index 328738b1b..4191c4891 100644 --- a/crack-core/src/commands/admin/authorize.rs +++ b/crack-core/src/commands/admin/authorize.rs @@ -1,9 +1,10 @@ use crate::errors::CrackedError; use crate::guild::settings::GuildSettings; -use crate::utils::check_reply; +use crate::messaging::message::CrackedMessage; +use crate::utils::send_response_poise; use crate::Context; use crate::Error; -use poise::CreateReply; +use poise::serenity_prelude::UserId; /// Authorize a user to use the bot. #[poise::command(prefix_command, owners_only, ephemeral)] @@ -41,13 +42,27 @@ pub async fn authorize( })?; guild_settings.save(&pool).await?; - check_reply( - ctx.send( - CreateReply::default() - .content("User authorized.") - .reply(true), - ) - .await, + let user_id = UserId::new(id); + let user_name = ctx + .http() + .get_user(user_id) + .await + .map(|u| u.name) + .unwrap_or_else(|_| "Unknown".to_string()); + let guild_name = guild_id + .to_partial_guild(ctx.http()) + .await + .map(|g| g.name) + .unwrap_or_else(|_| "Unknown".to_string()); + send_response_poise( + ctx, + CrackedMessage::UserAuthorized { + user_id, + user_name, + guild_id, + guild_name, + }, + true, ); Ok(()) diff --git a/crack-core/src/messaging/message.rs b/crack-core/src/messaging/message.rs index dc48f77d5..f299bd83a 100644 --- a/crack-core/src/messaging/message.rs +++ b/crack-core/src/messaging/message.rs @@ -90,6 +90,12 @@ pub enum CrackedMessage { channel_id: serenity::ChannelId, channel_name: String, }, + UserAuthorized { + user_id: UserId, + user_name: String, + guild_id: serenity::GuildId, + guild_name: String, + }, UserTimeout { user: String, user_id: String, @@ -224,6 +230,15 @@ impl Display for CrackedMessage { CATEGORY_CREATED, channel_id, channel_name )), Self::WaybackSnapshot { url } => f.write_str(&format!("{} {}", WAYBACK_SNAPSHOT, url)), + Self::UserAuthorized { + user_id, + user_name, + guild_id, + guild_name, + } => f.write_str(&format!( + "{}\n User: {} ({}) Guild: {} ({})", + AUTHORIZED, user_name, user_id, guild_name, guild_id + )), Self::UserTimeout { user: _, user_id, diff --git a/crack-core/src/messaging/messages.rs b/crack-core/src/messaging/messages.rs index 8021a6ab6..2c0dc0762 100644 --- a/crack-core/src/messaging/messages.rs +++ b/crack-core/src/messaging/messages.rs @@ -7,6 +7,7 @@ pub const CLEARED: &str = "🗑️ Cleared!"; pub const CLEANED: &str = "🗑️ Messages Cleaned: "; pub const CHANNEL_DELETED: &str = "🗑️ Deleted channel!"; +pub const AUTHORIZED: &str = "✅ User has been authorized."; pub const BANNED: &str = "Banned"; pub const UNBANNED: &str = "Unbanned"; pub const DEAFENED: &str = "Deafened"; @@ -40,7 +41,7 @@ pub const FAIL_PARSE_TIME: &str = "⚠️ Failed to parse time, speak English pub const FAIL_PLAYLIST_FETCH: &str = "⚠️ Failed to fetch playlist!"; pub const FAIL_INVALID_IP: &str = "⚠️ Invalid IP address!"; pub const GUILD_ONLY: &str = "⚠️ This command can only be used in a server!"; -pub const IDLE_ALERT: &str = "⚠️ I've been idle for a while, pay for premium if you want me to idle indefinitely plus better audio and more!\n[CrackTunes Patreon](https://patreon.com/CrackTunes)"; +pub const IDLE_ALERT: &str = "⚠️ I've been idle for a while, pay for premium if you want to stay, plus better audio and more!\n[CrackTunes Patreon](https://patreon.com/CrackTunes)"; pub const IP_DETAILS: &str = "🌐 IP details for"; pub const JOINING: &str = "Joining"; pub const LEAVING: &str = "👋 See you soon!"; diff --git a/crack-core/src/utils.rs b/crack-core/src/utils.rs index 6bb0417fd..cfa2a6fde 100644 --- a/crack-core/src/utils.rs +++ b/crack-core/src/utils.rs @@ -814,6 +814,8 @@ pub fn check_msg(result: Result) { } } +#[cfg(not(tarpaulin_include))] +/// Takes a Result ReplyHandle and logs the error if it's an Err. pub fn check_reply(result: Result) { if let Err(why) = result { tracing::error!("Error sending message: {:?}", why);