From 497d1806696c918301c67eef5e11220c55546187 Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Sun, 24 Aug 2025 03:51:08 -0300 Subject: [PATCH] Add hidden feature to not send messages when they're preceeded by an X --- .../migrations/0006_add_findings_to_users.cql | 1 + src/database/models.rs | 17 +++++++++--- src/groups/calls/events.rs | 27 +++++++++++++++---- src/main.rs | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 src/database/migrations/0006_add_findings_to_users.cql diff --git a/src/database/migrations/0006_add_findings_to_users.cql b/src/database/migrations/0006_add_findings_to_users.cql new file mode 100644 index 0000000..c68b965 --- /dev/null +++ b/src/database/migrations/0006_add_findings_to_users.cql @@ -0,0 +1 @@ +ALTER TABLE payphone.users ADD findings SET; diff --git a/src/database/models.rs b/src/database/models.rs index 30d70e0..0a2e37d 100644 --- a/src/database/models.rs +++ b/src/database/models.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use scylla::{ DeserializeValue, SerializeValue, client::session::Session, @@ -102,6 +104,7 @@ pub struct User { pub supporter_since: Option, pub supporter_until: Option, pub is_banned_from_leaderboard: Option, + pub findings: HashSet, } impl<'a> Object<'a> for User { @@ -116,6 +119,7 @@ impl<'a> Object<'a> for User { Option, Option, Option, + HashSet, ); fn from_row(row: Self::Row) -> Self { @@ -130,6 +134,7 @@ impl<'a> Object<'a> for User { supporter_since: row.7.map(|i| i.into()), supporter_until: row.8.map(|i| i.into()), is_banned_from_leaderboard: row.9, + findings: row.10, } } @@ -145,6 +150,7 @@ impl<'a> Object<'a> for User { value.supporter_since.map(|i| i.into()), value.supporter_until.map(|i| i.into()), Some(value.is_banned_from_leaderboard.unwrap_or(false)), + value.findings, ) } } @@ -171,7 +177,8 @@ impl User { last_seen_at, supporter_since, supporter_until, - is_banned_from_leaderboard + is_banned_from_leaderboard, + findings FROM payphone.users WHERE @@ -208,7 +215,7 @@ impl User { /// Returns: /// [`Result`] - The user from the database or a new user created from /// Discord. - pub async fn get_or_create_and_set_last_seen( + pub async fn create_or_update( user: TwilightUser, session: &Session, ) -> Result { @@ -241,8 +248,9 @@ impl User { last_seen_at, supporter_since, supporter_until, - is_banned_from_leaderboard - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?); + is_banned_from_leaderboard, + findings + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); "#, Self::to_row(self.clone()), ) @@ -329,6 +337,7 @@ impl From for User { supporter_since: None, supporter_until: None, is_banned_from_leaderboard: None, + findings: HashSet::new(), } } } diff --git a/src/groups/calls/events.rs b/src/groups/calls/events.rs index 82c47e2..4ab4225 100644 --- a/src/groups/calls/events.rs +++ b/src/groups/calls/events.rs @@ -160,8 +160,7 @@ impl OnMessageHandler for CallMessageHandler { return Ok(()); }; - let user = - User::get_or_create_and_set_last_seen(event.author.clone(), &rt.state.db).await?; + let mut user = User::create_or_update(event.author.clone(), &rt.state.db).await?; let user_incidents = UserIncident::get_for_user(event.author.id.get(), &rt.state.db) .await? @@ -173,6 +172,26 @@ impl OnMessageHandler for CallMessageHandler { return Ok(()); } + if event.content.to_ascii_lowercase().starts_with("x ") { + if !user.findings.contains("feature:hide-message") { + user.findings.insert("feature:hide-message".into()); + user.insert(&rt.state.db).await?; + + rt + .http + .create_message( + event.channel_id + ) + .content( + "✨ You found a hidden feature! Messages starting with `x` followed by a space will not be sent to the other party (nor moderated, i.e. you won't get banned for what you say in them)." + ) + .reply(event.id) + .await?; + } + + return Ok(()); + } + let Some(mut opposite_channel) = Channel::get_by_id( call.other_party_channel_id(event.channel_id.get()), &rt.state.db, @@ -462,9 +481,7 @@ impl OnMessageEditHandler for CallMessageEditHandler { .reply(event.id) .await?; - let user = - User::get_or_create_and_set_last_seen(event.author.clone(), &rt.state.db) - .await?; + let user = User::create_or_update(event.author.clone(), &rt.state.db).await?; penalize_user(user, message, rules, &rt).await?; diff --git a/src/main.rs b/src/main.rs index c922709..c88c082 100644 --- a/src/main.rs +++ b/src/main.rs @@ -241,7 +241,7 @@ impl ExtrasGetter for PayphoneExtrasGetter { ) -> Result> { log::trace!("Getting extras!"); - let user = User::get_or_create_and_set_last_seen(user.clone(), &rt.state.db).await?; + let user = User::create_or_update(user.clone(), &rt.state.db).await?; Ok(Extras { user }) }