Make mask command not toggle the mask status when neither on nor off are passed

This commit is contained in:
2025-08-24 03:42:37 -03:00
parent 14a6037101
commit bd09a55a74
3 changed files with 56 additions and 69 deletions
Generated
+1 -1
View File
@@ -1437,7 +1437,7 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
[[package]] [[package]]
name = "payphone" name = "payphone"
version = "4.3.0" version = "4.3.2"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "payphone" name = "payphone"
version = "4.3.0" version = "4.3.2"
edition = "2024" edition = "2024"
default-run = "payphone" default-run = "payphone"
+38 -51
View File
@@ -8,7 +8,7 @@ use crate::{
extras::Extras, extras::Extras,
framework::commands::{ framework::commands::{
Command, CommandError, Command, CommandError,
arguments::{Arg, ParseArguments}, arguments::{Arg, Argument, ParseArguments},
context::CommandContext, context::CommandContext,
permissions::Permission, permissions::Permission,
}, },
@@ -467,7 +467,15 @@ impl Command<State, Extras> for MaskCommand {
} }
fn description(&self) -> &'static str { 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( async fn execute(
@@ -478,49 +486,42 @@ impl Command<State, Extras> for MaskCommand {
let Arg(toggle) = match Arg::<Option<bool>>::parse(args, &ctx).await { let Arg(toggle) = match Arg::<Option<bool>>::parse(args, &ctx).await {
Ok(v) => v, Ok(v) => v,
Err(_) => { Err(_) => {
ctx ctx.send()
.send() .content(format!(
.content(
format!(
"❓ Are you sure that's correct? Use `{}mask on` and `{}mask off`, or just `{}mask` to toggle it.", "❓ 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.prefix, ctx.prefix, ctx.prefix
) ))
)
.await?; .await?;
return Ok(()); return Ok(());
} }
}; };
let mask_verb: &'static str;
// If toggle is Some, update user mask preference
if let Some(toggle) = toggle { if let Some(toggle) = toggle {
ctx.extras.user.is_masked = toggle; ctx.extras.user.is_masked = toggle;
} else {
ctx.extras.user.is_masked = !ctx.extras.user.is_masked;
}
ctx.extras.user.insert(&ctx.rt.state.db).await?; ctx.extras.user.insert(&ctx.rt.state.db).await?;
let Some(channel) = mask_verb = "was";
Channel::get_by_id(ctx.event.channel_id.get(), &ctx.rt.state.db).await? } else {
else { mask_verb = "is";
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..."); 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
);
if let Some(channel) = channel {
if let Some(call_id) = channel.call_id { 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( if let Some(mut participant) = Participant::get_for_user_and_channel_in_call(
ctx.extras.user.id, ctx.extras.user.id,
ctx.event.channel_id.get(), ctx.event.channel_id.get(),
@@ -529,38 +530,24 @@ impl Command<State, Extras> for MaskCommand {
) )
.await? .await?
{ {
log::trace!(
"Participant's is_masked is being set to {}",
ctx.extras.user.is_masked
);
participant.is_masked = ctx.extras.user.is_masked; participant.is_masked = ctx.extras.user.is_masked;
participant.upsert(&ctx.rt.state.db).await?; participant.upsert(&ctx.rt.state.db).await?;
if ctx.extras.user.is_masked { 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`.", mask_message = format!(
get_mask_emoji(&participant.user_mask).expect("User's mask did not exist"), "🎭 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), get_mask_display_name(&participant.user_mask),
ctx.prefix, ctx.prefix,
ctx.prefix ctx.prefix
)).await?; );
}
return Ok(());
} }
} }
} }
ctx ctx.send().content(mask_message).await?;
.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?;
Ok(()) Ok(())
} }