From 7693dee45d999836788872eba17e6094a7f6372a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Brankovi=C4=87?= Date: Fri, 30 Aug 2024 16:15:29 +0200 Subject: [PATCH] refactor: rename RTP command --- .env.example | 2 +- README.md | 16 ++++++++-------- docker-compose.yaml | 2 +- src/commands/mod.rs | 2 +- src/commands/{rtp.rs => play.rs} | 22 +++++++++++----------- src/env.rs | 14 +++++++------- src/events/presence_update.rs | 14 +++++++------- src/main.rs | 2 +- src/util/mod.rs | 2 +- src/util/{rtp.rs => play.rs} | 20 ++++++++++---------- 10 files changed, 48 insertions(+), 48 deletions(-) rename src/commands/{rtp.rs => play.rs} (70%) rename src/util/{rtp.rs => play.rs} (57%) diff --git a/.env.example b/.env.example index 5cd6d82..8a94fe2 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ CLIENT_ID=1234567890987654321 CLIENT_TOKEN=U1Tr4.53cR3t.T0k3N HOME_GUILD_ID=1234567890987654321 -READY_ROLE_ID=1234567890987654321 +PLAYING_ROLE_ID=1234567890987654321 diff --git a/README.md b/README.md index 3857eca..f4d6e11 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ https://discord.com/api/oauth2/authorize?permissions=277293894656&scope=bot%20ap while inserting your client ID and keeping the scopes. Remember that the bot is designed to *only be active in 1 server at a time.* -Please also make sure the bot's personal role is ranked *above* the managed ready role! +Please also make sure the bot's personal role is ranked *above* the managed playing role! --- @@ -58,22 +58,22 @@ to this GitHub section. Check if Lunaro Manager is online and how long it took to receive the ping. This value is calculated from the system time, and may thus be inaccurate. -### `🟢 /rtp join` +### `🟢 /play now` -Adds the configured ready role to your profile. +Adds the configured playing role to your profile. -### `⭕ /rtp leave` +### `⭕ /play later` -Removes the configured ready role from your profile. +Removes the configured playing role from your profile. -### `👀 /rtp check` +### `👀 /play info` -Lists the number of members with the ready role. +Lists the number of members with the playing role. ### `⛔ /tracking pause` Disables activity tracking for your account. This is useful because the activity -tracker will otherwise override your manually set ready status. +tracker will otherwise override your manually set playing status. ### `💡 /about` diff --git a/docker-compose.yaml b/docker-compose.yaml index 88586cc..16fd35b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,4 +13,4 @@ services: CLIENT_ID: ${CLIENT_ID:-example} CLIENT_TOKEN: ${CLIENT_TOKEN:-example} HOME_GUILD_ID: ${HOME_GUILD_ID:-example} - READY_ROLE_ID: ${READY_ROLE_ID:-example} + PLAYING_ROLE_ID: ${PLAYING_ROLE_ID:-example} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 6a45c64..4b35f9c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2,5 +2,5 @@ pub mod about; pub mod contribute; pub mod help; pub mod ping; -pub mod rtp; +pub mod play; pub mod tracking; diff --git a/src/commands/rtp.rs b/src/commands/play.rs similarity index 70% rename from src/commands/rtp.rs rename to src/commands/play.rs index 5a12f6d..2b0ef65 100644 --- a/src/commands/rtp.rs +++ b/src/commands/play.rs @@ -3,11 +3,11 @@ use poise::{command, CreateReply}; use crate::{ env::Environment, types::{error::Error, poise::PoiseContext}, - util::rtp, + util::play, }; -/// 🥍 Manage your RTP status -#[command(slash_command, rename = "rtp", subcommands("join", "leave", "check"))] +/// 🥍 Manage your Lunaro status +#[command(slash_command, rename = "play", subcommands("join", "leave", "check"))] pub async fn run(_context: PoiseContext<'_>) -> Result<(), Error> { // Handled in subcommands Ok(()) @@ -15,7 +15,7 @@ pub async fn run(_context: PoiseContext<'_>) -> Result<(), Error> { /// 🟢 Equip your Arcata #[command(slash_command)] -async fn join(context: PoiseContext<'_>) -> Result<(), Error> { +async fn now(context: PoiseContext<'_>) -> Result<(), Error> { let env = Environment::instance(); let member = &mut context @@ -24,7 +24,7 @@ async fn join(context: PoiseContext<'_>) -> Result<(), Error> { .get_member(env.home_guild_id.into(), context.author().id) .await?; - rtp::add(member, context.serenity_context()).await?; + play::add(member, context.serenity_context()).await?; let display_name = match &member.nick { Some(nick) => nick, @@ -43,7 +43,7 @@ async fn join(context: PoiseContext<'_>) -> Result<(), Error> { /// ⭕ Unequip your Arcata #[command(slash_command)] -async fn leave(context: PoiseContext<'_>) -> Result<(), Error> { +async fn later(context: PoiseContext<'_>) -> Result<(), Error> { let env = Environment::instance(); let member = &mut context @@ -63,24 +63,24 @@ async fn leave(context: PoiseContext<'_>) -> Result<(), Error> { ))) .await?; - rtp::remove(member, context.serenity_context()).await?; + play::remove(member, context.serenity_context()).await?; Ok(()) } /// 👀 Check who's equipped their Arcata #[command(slash_command)] -async fn check(context: PoiseContext<'_>) -> Result<(), Error> { - let ready_member_count = rtp::count(context.serenity_context()).await?; +async fn info(context: PoiseContext<'_>) -> Result<(), Error> { + let playing_member_count = play::count(context.serenity_context()).await?; - let verb = match ready_member_count { + let verb = match playing_member_count { 1 => "is", _ => "are", }; context .send(CreateReply::default().content(format!( - "👀 There {verb} {ready_member_count} Tenno available for Lunaro" + "👀 There {verb} {playing_member_count} Tenno playing Lunaro" ))) .await?; diff --git a/src/env.rs b/src/env.rs index ef240b4..d629530 100644 --- a/src/env.rs +++ b/src/env.rs @@ -25,7 +25,7 @@ pub struct Environment { pub home_guild_id: GuildId, /// The role ID of the role to be given to users playing Lunaro. - pub ready_role_id: RoleId, + pub playing_role_id: RoleId, /// The bot's Cargo package information. pub cargo: Cargo, @@ -73,7 +73,7 @@ impl Environment { client_id: get_client_id()?.into(), client_token: get_client_token()?, home_guild_id: get_home_guild_id()?.into(), - ready_role_id: get_ready_role_id()?.into(), + playing_role_id: get_playing_role_id()?.into(), cargo: get_cargo()?, }) } @@ -132,12 +132,12 @@ fn get_home_guild_id() -> Result { parse_id(&home_guild_id_string, env_name) } -/// Fetches and validates the ready role ID environment variable. -fn get_ready_role_id() -> Result { - let env_name = "READY_ROLE_ID"; - let ready_role_id_string = read_variable(env_name)?; +/// Fetches and validates the playing role ID environment variable. +fn get_playing_role_id() -> Result { + let env_name = "PLAYING_ROLE_ID"; + let playing_role_id_string = read_variable(env_name)?; - parse_id(&ready_role_id_string, env_name) + parse_id(&playing_role_id_string, env_name) } /// Fetches and validates the Cargo package information. diff --git a/src/events/presence_update.rs b/src/events/presence_update.rs index 21e281c..a84e92f 100644 --- a/src/events/presence_update.rs +++ b/src/events/presence_update.rs @@ -4,7 +4,7 @@ use crate::{ env::Environment, traits::config_file::ConfigFile, types::error::Error, - util::{activity_tracking, rtp}, + util::{activity_tracking, play}, }; /// Handles the presence update event. @@ -21,17 +21,17 @@ pub async fn handle(context: Context, presence: &Presence) -> Result<(), Error> .get_member(presence.guild_id.unwrap(), presence.user.id) .await?; - let is_ready = member + let is_playing = member .user - .has_role(&context, env.home_guild_id, env.ready_role_id) + .has_role(&context, env.home_guild_id, env.playing_role_id) .await?; let is_playing_lunaro = activity_tracking::is_playing_lunaro(presence).is_ok_and(|value| value); - if is_playing_lunaro && !is_ready { - rtp::add(member, &context).await?; - } else if !is_playing_lunaro && is_ready { - rtp::remove(member, &context).await?; + if is_playing_lunaro && !is_playing { + play::add(member, &context).await?; + } else if !is_playing_lunaro && is_playing { + play::remove(member, &context).await?; } Ok(()) diff --git a/src/main.rs b/src/main.rs index 2c0d150..95c36be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ async fn main() { commands::contribute::run(), commands::help::run(), commands::ping::run(), - commands::rtp::run(), + commands::play::run(), commands::tracking::run(), ], diff --git a/src/util/mod.rs b/src/util/mod.rs index 3e49a2f..5063877 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,3 +1,3 @@ pub mod activity_tracking; pub mod data; -pub mod rtp; +pub mod play; diff --git a/src/util/rtp.rs b/src/util/play.rs similarity index 57% rename from src/util/rtp.rs rename to src/util/play.rs index 9d079fc..85d0851 100644 --- a/src/util/rtp.rs +++ b/src/util/play.rs @@ -2,7 +2,7 @@ use poise::serenity_prelude::{Context, Member}; use crate::{env::Environment, types::error::Error}; -/// Count how many members have the ready role. +/// Count how many members have the playing role. pub async fn count(context: &Context) -> Result { let env = Environment::instance(); @@ -11,37 +11,37 @@ pub async fn count(context: &Context) -> Result { .get_guild_members(env.home_guild_id, None, None) .await?; - let ready_member_count = members + let playing_member_count = members .iter() .filter(|member| { member .roles .iter() - .any(|role_id| role_id == &env.ready_role_id) + .any(|role_id| role_id == &env.playing_role_id) }) .count(); - Ok(ready_member_count) + Ok(playing_member_count) } -/// Add the ready role to a member. +/// Add the playing role to a member. pub async fn add(member: &mut Member, context: &Context) -> Result<(), Error> { member - .add_role(context, Environment::instance().ready_role_id) + .add_role(context, Environment::instance().playing_role_id) .await?; - log::debug!("Added {} to ready role", member.user.tag()); + log::debug!("Added {} to playing role", member.user.tag()); Ok(()) } -/// Remove the ready role from a member. +/// Remove the playing role from a member. pub async fn remove(member: &mut Member, context: &Context) -> Result<(), Error> { member - .remove_role(context, Environment::instance().ready_role_id) + .remove_role(context, Environment::instance().playing_role_id) .await?; - log::debug!("Removed {} from ready role", member.user.tag()); + log::debug!("Removed {} from playing role", member.user.tag()); Ok(()) }