From bd09a55a74c3f3f38defd91c3c4a170e79ebb51f Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 24 Aug 2025 03:42:37 -0300 Subject: [PATCH] Make mask command not toggle the mask status when neither on nor off are passed --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/groups/calls/commands.rs | 121 ++++++++++++++++------------------- 3 files changed, 56 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d72d529..05a3464 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1437,7 +1437,7 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" [[package]] name = "payphone" -version = "4.3.0" +version = "4.3.2" dependencies = [ "async-trait", "axum", diff --git a/Cargo.toml b/Cargo.toml index ef694d7..c9800a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "payphone" -version = "4.3.0" +version = "4.3.2" edition = "2024" default-run = "payphone" diff --git a/src/groups/calls/commands.rs b/src/groups/calls/commands.rs index 62e94d0..0f7e908 100644 --- a/src/groups/calls/commands.rs +++ b/src/groups/calls/commands.rs @@ -8,7 +8,7 @@ use crate::{ extras::Extras, framework::commands::{ Command, CommandError, - arguments::{Arg, ParseArguments}, + arguments::{Arg, Argument, ParseArguments}, context::CommandContext, permissions::Permission, }, @@ -467,7 +467,15 @@ impl Command for MaskCommand { } fn description(&self) -> &'static str { - "Masks your profile from the other party and updates your preferences for future calls." + "Hides your profile from the other party by replacing your profile with a random animal. This command's preferences persist across calls.\n\nNote: Using this command without `on/off` will display your current mask status, without making any changes to it." + } + + fn arguments(&self) -> &'static [Argument] { + &[Argument { + name: "on/off", + is_optional: true, + is_greedy: false, + }] } async fn execute( @@ -478,89 +486,68 @@ impl Command for MaskCommand { let Arg(toggle) = match Arg::>::parse(args, &ctx).await { Ok(v) => v, Err(_) => { - ctx - .send() - .content( - format!( - "❓ Are you sure that's correct? Use `{}mask on` and `{}mask off`, or just `{}mask` to toggle it.", - ctx.prefix, ctx.prefix, ctx.prefix - ) - ) + ctx.send() + .content(format!( + "❓ Are you sure that's correct? Use `{}mask on` and `{}mask off`, or just `{}mask` to toggle it.", + ctx.prefix, ctx.prefix, ctx.prefix + )) .await?; - return Ok(()); } }; + let mask_verb: &'static str; + + // If toggle is Some, update user mask preference if let Some(toggle) = toggle { ctx.extras.user.is_masked = toggle; + ctx.extras.user.insert(&ctx.rt.state.db).await?; + + mask_verb = "was"; } else { - ctx.extras.user.is_masked = !ctx.extras.user.is_masked; + mask_verb = "is"; } - ctx.extras.user.insert(&ctx.rt.state.db).await?; - - let Some(channel) = - Channel::get_by_id(ctx.event.channel_id.get(), &ctx.rt.state.db).await? - else { - ctx - .send() - .content( - format!( - "🎭 Your mask was set to `{}`. You can toggle your mask on or off using `{}mask on` and `{}mask off`.", - if ctx.extras.user.is_masked { "on" } else { "off" }, - ctx.prefix, - ctx.prefix - ) - ) - .await?; - - return Ok(()); + let mask_status = if ctx.extras.user.is_masked { + "on" + } else { + "off" }; - log::trace!("User is masked, checking for call..."); - if let Some(call_id) = channel.call_id { - log::trace!("Found call ID: {call_id}"); - if let Some(mut participant) = Participant::get_for_user_and_channel_in_call( - ctx.extras.user.id, - ctx.event.channel_id.get(), - call_id, - &ctx.rt.state.db, - ) - .await? - { - log::trace!( - "Participant's is_masked is being set to {}", - ctx.extras.user.is_masked - ); + let channel = Channel::get_by_id(ctx.event.channel_id.get(), &ctx.rt.state.db).await?; + let mut mask_message = format!( + "🎭 Your mask {mask_verb} set to `{}`. You can toggle your mask on or off using `{}mask on` and `{}mask off`.", + mask_status, ctx.prefix, ctx.prefix + ); - participant.is_masked = ctx.extras.user.is_masked; - participant.upsert(&ctx.rt.state.db).await?; + if let Some(channel) = channel { + if let Some(call_id) = channel.call_id { + if let Some(mut participant) = Participant::get_for_user_and_channel_in_call( + ctx.extras.user.id, + ctx.event.channel_id.get(), + call_id, + &ctx.rt.state.db, + ) + .await? + { + participant.is_masked = ctx.extras.user.is_masked; + participant.upsert(&ctx.rt.state.db).await?; - if ctx.extras.user.is_masked { - ctx.send().content(format!("🎭 Your mask was set to on. You're currently being displayed as **{} {}**. You can toggle your mask on or off using `{}mask on` and `{}mask off`.", - get_mask_emoji(&participant.user_mask).expect("User's mask did not exist"), - get_mask_display_name(&participant.user_mask), - ctx.prefix, - ctx.prefix - )).await?; - - return Ok(()); + if ctx.extras.user.is_masked { + mask_message = format!( + "🎭 Your mask {mask_verb} set to `on`. You're currently being displayed as **{} {}**. You can toggle your mask on or off using `{}mask on` and `{}mask off`.", + get_mask_emoji(&participant.user_mask) + .expect("User's mask did not exist"), + get_mask_display_name(&participant.user_mask), + ctx.prefix, + ctx.prefix + ); + } } } } - ctx - .send() - .content( - format!( - "🎭 Your mask was set to `{}`. You can toggle your mask on or off using `{}mask on` and `{}mask off`.", - if ctx.extras.user.is_masked { "on" } else { "off" }, - ctx.prefix, - ctx.prefix - ) - ) - .await?; + ctx.send().content(mask_message).await?; Ok(()) }