From 7d47a9eb355a0c0cfe2fc6ecb55304e31606ca08 Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sat, 23 Aug 2025 12:16:06 -0300 Subject: [PATCH] Start working on mask command --- Cargo.lock | 2 +- Cargo.toml | 2 +- .../migrations/0004_participant_is_masked.cql | 6 ++ src/groups/calls/commands.rs | 95 ++++++++++++++++++- 4 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 src/database/migrations/0004_participant_is_masked.cql diff --git a/Cargo.lock b/Cargo.lock index 00ceb06..bb62111 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1437,7 +1437,7 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" [[package]] name = "payphone" -version = "4.2.12" +version = "4.2.15" dependencies = [ "async-trait", "axum", diff --git a/Cargo.toml b/Cargo.toml index a5200af..80bea1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "payphone" -version = "4.2.12" +version = "4.2.15" edition = "2024" default-run = "payphone" diff --git a/src/database/migrations/0004_participant_is_masked.cql b/src/database/migrations/0004_participant_is_masked.cql new file mode 100644 index 0000000..8fb02b5 --- /dev/null +++ b/src/database/migrations/0004_participant_is_masked.cql @@ -0,0 +1,6 @@ +ALTER TABLE payphone.participants ADD is_masked BOOLEAN; + +CREATE MATERIALIZED VIEW IF NOT EXISTS payphone.participants_by_user_id AS + SELECT user_id, call_id, channel_id FROM payphone.participants + WHERE user_id IS NOT NULL AND call_id IS NOT NULL AND channel_id IS NOT NULL + PRIMARY KEY (user_id, call_id); diff --git a/src/groups/calls/commands.rs b/src/groups/calls/commands.rs index 2b4ac93..f3b6a91 100644 --- a/src/groups/calls/commands.rs +++ b/src/groups/calls/commands.rs @@ -7,7 +7,10 @@ use crate::{ discord::sanitizing::SanitizeDiscordMarkdown, extras::Extras, framework::commands::{ - Command, CommandError, context::CommandContext, permissions::Permission, + Command, CommandError, + arguments::{Arg, ParseArguments}, + context::CommandContext, + permissions::Permission, }, groups::calls::{ get_display_profile, @@ -224,10 +227,7 @@ impl Command for SkipCommand { ctx.rt .http .create_message(Id::new(call.other_party_channel_id(channel.id))) - .content(&format!( - "☎️ {}", - get_string_call_hangup_other_party(ctx.prefix) - )) + .content(&format!("☎️ {}", get_string_call_answered(ctx.prefix))) .await .bye(); } else { @@ -427,3 +427,88 @@ impl Command for FriendRequestCommand { Ok(()) } } + +#[derive(Debug)] +pub struct MaskCommand; + +#[async_trait] +impl Command for MaskCommand { + fn name(&self) -> &'static str { + "mask" + } + + fn aliases(&self) -> &'static [&'static str] { + &["m"] + } + + fn description(&self) -> &'static str { + "Masks your profile from the other party and updates your preferences for future calls." + } + + async fn execute( + &self, + mut ctx: CommandContext<'_, State, Extras>, + args: &str, + ) -> Result<(), CommandError> { + 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 + ) + ) + .await?; + + return Ok(()); + } + }; + + if let Some(toggle) = 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?; + + 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(()); + }; + + if let Some(call_id) = channel.call_id { + + } 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?; + } + + Ok(()) + } +}