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
+54 -67
View File
@@ -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<State, Extras> 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<State, Extras> for MaskCommand {
let Arg(toggle) = match Arg::<Option<bool>>::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(())
}