From 358b16249efb08cc707898c4bf8112f847b7dd16 Mon Sep 17 00:00:00 2001 From: Byte Dice Date: Sat, 12 Jul 2025 12:04:53 +0200 Subject: [PATCH] added a WhoAmI command --- bk_week_help_re.md | 16 +++++++--------- data/lang/en.json | 1 + src/cmds/help.rs | 8 ++++---- src/cmds/whoami.rs | 20 ++++++++++++++++++++ src/gen.rs | 1 + src/main.rs | 1 + 6 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 src/cmds/whoami.rs diff --git a/bk_week_help_re.md b/bk_week_help_re.md index ae4c77e..3f7a834 100644 --- a/bk_week_help_re.md +++ b/bk_week_help_re.md @@ -1,12 +1,10 @@ # Reddit Commands -To execute a command on the Reddit bot, include `u/ByteDiceAssistant [cmd]` in a comment. -- **`[cmd]`**: The command you want to run and its arguments. -## `bk_week_add` -Adds the post to the list of posts. +To execute a command on the Reddit bot, include `u/{BOTNAME} [cmd]` in a comment. (Replace {BOTNAME} with the actual bot name, and [cmd] with any command listed below). + +## `add_post` +Adds a post to the bots database. - **Only moderators of a subreddit or the OP (Original Poster) can use this command.** ### **Examples** -``` -"u/ByteDiceAssistant bk_week_add" -"Cool art, let me add that. u/ByteDiceAssistant bk_week_add" -"Cool art. Just gonna u/ByteDiceAssistant bk_week_add so it can become featured." -``` \ No newline at end of file +* `u/{BOTNAME} add_post` +* `Cool art, let me add that. u/{BOTNAME} weekly_art` (weekly art is an alias for add_post that is enabled by default) +* `Cool art. Just gonna u/{BOTNAME} add_post so it can become featured.` \ No newline at end of file diff --git a/data/lang/en.json b/data/lang/en.json index 27e38b4..e7f6363 100644 --- a/data/lang/en.json +++ b/data/lang/en.json @@ -55,6 +55,7 @@ "dc_msg_update_removing_dupe": "{0}Removing duplicate posts...", "dc_msg_update_removing_old": "{0}Removing old posts (threshold: {1}d)...", "dc_msg_update_removing": "{0}Removing removed posts...", + "dc_msg_whoami": "**Bot \"owner\":** {0}\n**BK moderator:** {1}", "log_lang_load_success": "Successfully loaded the english language file!", "none": "None", "py_re_response_suffix": "^(I am not an AI, I am just a bot. This action was performed automatically by the way. You can report bugs and view my source code [here](https://github.com/ByteDice/ByteDiceAssistant)!)", diff --git a/src/cmds/help.rs b/src/cmds/help.rs index 2f93a57..7f00dfd 100644 --- a/src/cmds/help.rs +++ b/src/cmds/help.rs @@ -8,8 +8,8 @@ use crate::{lang, messages::send_msg, Context, Cmd, Error}; enum HelpOptions { Admin, All, - BkWeek, - BkWeekReddit, + Reddit, + RedditBot, Generic } @@ -97,8 +97,8 @@ async fn send_single_help(ctx: Context<'_>, mut cmd_name: String) { async fn send_category_help(ctx: Context<'_>, category: HelpOptions) { match category { - HelpOptions::BkWeekReddit => send_bk_week_help_re(ctx).await, - HelpOptions::BkWeek => send_bk_week_help (ctx).await, + HelpOptions::RedditBot => send_bk_week_help_re(ctx).await, + HelpOptions::Reddit => send_bk_week_help (ctx).await, HelpOptions::Generic => send_generic_help (ctx).await, HelpOptions::Admin => send_admin_help (ctx).await, HelpOptions::All => send_all_help (ctx).await diff --git a/src/cmds/whoami.rs b/src/cmds/whoami.rs new file mode 100644 index 0000000..0823104 --- /dev/null +++ b/src/cmds/whoami.rs @@ -0,0 +1,20 @@ +use crate::{lang, messages::send_msg, Context, Error}; + +#[poise::command( + slash_command, + prefix_command, + rename = "whoami", + category = "help", + required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL" +)] +pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> { + let data = ctx.data(); + let uid: u64 = ctx.author().id.into(); + + let is_owner = data.owners .contains(&uid); + let is_bk_mod = data.bk_mods.contains(&uid); + + send_msg(ctx, lang!("dc_msg_whoami", is_owner, is_bk_mod), true, true).await; + + return Ok(()); +} \ No newline at end of file diff --git a/src/gen.rs b/src/gen.rs index 00bcf49..eb3e2c7 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -79,6 +79,7 @@ async fn make_cmd_vec(data: &Data) -> Vec { let mut cmds = vec![ // GENERIC cmds::help::cmd(), + cmds::whoami::cmd(), cmds::ping::cmd(), cmds::eight_ball::cmd(), // REDDIT diff --git a/src/main.rs b/src/main.rs index 99712c7..588653b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ mod cmds { pub mod reload_cfg; pub mod send; pub mod stop; + pub mod whoami; } mod re_cmds { pub mod add;