From 2b1a738379e74d7ca8ca4eeeb4559c66e64ca0cc Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Thu, 21 Aug 2025 18:57:30 -0300 Subject: [PATCH] Add strings to call commands --- Cargo.lock | 5 +- Cargo.toml | 1 + src/groups/calls/commands.rs | 61 ++++++-- .../lists/casual-insults-and-teasing.txt | 5 +- .../calls/lists/explicit-sexual-language.txt | 3 - src/groups/calls/lists/mild-swear-words.txt | 5 +- .../calls/lists/threats-and-self-harm.txt | 1 - src/groups/calls/mod.rs | 1 + src/groups/calls/strings.rs | 141 ++++++++++++++++++ ...call-starting.json => call-searching.json} | 0 src/groups/calls/strings/tips.json | 10 +- 11 files changed, 208 insertions(+), 25 deletions(-) create mode 100644 src/groups/calls/strings.rs rename src/groups/calls/strings/{call-starting.json => call-searching.json} (100%) diff --git a/Cargo.lock b/Cargo.lock index aa6c11e..985bb47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1458,6 +1458,7 @@ dependencies = [ "regex", "scc", "scylla", + "serde_json", "thiserror 2.0.12", "time", "tokio", @@ -1943,9 +1944,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.142" +version = "1.0.143" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7" +checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" dependencies = [ "itoa", "memchr", diff --git a/Cargo.toml b/Cargo.toml index d6fa8fe..7313c8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ rand_chacha = { version = "0.9.0", features = ["os_rng"] } regex = "1.11.1" scc = "2.3.4" scylla = { version = "1.3.1", features = ["time-03"] } +serde_json = "1.0.143" thiserror = "2.0.12" time = { version = "0.3.41", features = ["formatting", "local-offset", "macros"] } tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] } diff --git a/src/groups/calls/commands.rs b/src/groups/calls/commands.rs index ccb77fb..a864372 100644 --- a/src/groups/calls/commands.rs +++ b/src/groups/calls/commands.rs @@ -8,7 +8,15 @@ use crate::{ framework::commands::{ Command, CommandError, context::CommandContext, permissions::Permission, }, - groups::calls::{get_display_profile, permissions::NotBannedPermission}, + groups::calls::{ + get_display_profile, + permissions::NotBannedPermission, + strings::{ + get_string_call_answered, get_string_call_hangup_other_party, + get_string_call_hangup_this_party, get_string_call_no_answer, + get_string_call_searching, get_string_tips, + }, + }, state::State, utils::Bye, }; @@ -99,16 +107,28 @@ impl Command for CallCommand { .await; if let Some(call) = call { - ctx.send().content("☎️ Call connected. Say hi!").await.bye(); + ctx.send() + .content(format!( + "**TIP:** {}\n☎️ {}\n☎️ {}", + get_string_tips(ctx.prefix), + get_string_call_searching(ctx.prefix), + get_string_call_answered(ctx.prefix) + )) + .await + .bye(); ctx.rt .http .create_message(Id::new(call.other_party_channel_id(channel.id))) - .content("☎️ Call connected. Say hi!") + .content(&format!("☎️ {}", get_string_call_answered(ctx.prefix))) .await .bye(); } else { ctx.send() - .content("☎️ Searching for a call...") + .content(format!( + "**TIP:** {}\n☎️ {}", + get_string_tips(ctx.prefix), + get_string_call_searching(ctx.prefix) + )) .await .map_err(|_| CommandError::MessageSendingFailed)?; } @@ -190,7 +210,10 @@ impl Command for SkipCommand { ctx.rt .http .create_message(Id::new(other_channel_id)) - .content("☎️ The other party hung up the phone.") + .content(&format!( + "☎️ {}", + get_string_call_hangup_other_party(ctx.prefix) + )) .await .inspect_err(|e| { log::error!("Failed to send message to other party: {e:?}"); @@ -205,11 +228,20 @@ impl Command for SkipCommand { .map_err(|_| CommandError::DatabaseQueryFailed)?; if let Some(call) = call { - ctx.send().content("☎️ Call connected. Say hi!").await.bye(); + ctx.send() + .content(format!( + "☎️ {}", + get_string_call_hangup_this_party(ctx.prefix) + )) + .await + .bye(); ctx.rt .http .create_message(Id::new(call.other_party_channel_id(channel.id))) - .content("☎️ Call connected. Say hi!") + .content(&format!( + "☎️ {}", + get_string_call_hangup_other_party(ctx.prefix) + )) .await .bye(); } else { @@ -271,7 +303,7 @@ impl Command for HangupCommand { .map_err(|_| CommandError::DatabaseQueryFailed)?; ctx.send() - .content("☎️ The phone was hung up.") + .content(format!("☎️ {}", get_string_call_no_answer(ctx.prefix))) .await .map_err(|_| CommandError::MessageSendingFailed)?; @@ -297,12 +329,21 @@ impl Command for HangupCommand { .inspect_err(|e| log::error!("Failed to hang up call: {e:?}")) .map_err(|_| CommandError::DatabaseQueryFailed)?; - ctx.send().content("☎️ You hung up the phone.").await.bye(); + ctx.send() + .content(format!( + "☎️ {}", + get_string_call_hangup_this_party(ctx.prefix) + )) + .await + .bye(); ctx.rt .http .create_message(Id::new(call.other_party_channel_id(channel.id))) - .content("☎️ The other party hung up the phone.") + .content(&format!( + "☎️ {}", + get_string_call_hangup_other_party(ctx.prefix) + )) .await .map_err(|_| CommandError::MessageSendingFailed)?; } else { diff --git a/src/groups/calls/lists/casual-insults-and-teasing.txt b/src/groups/calls/lists/casual-insults-and-teasing.txt index d5963de..0b511cf 100644 --- a/src/groups/calls/lists/casual-insults-and-teasing.txt +++ b/src/groups/calls/lists/casual-insults-and-teasing.txt @@ -7,4 +7,7 @@ fool stfu syfm sybau -gtfo \ No newline at end of file +gtfo +// Keys is only censored because there have been many genuine conversations about piano keys, keys, +// and other stuff. +keys \ No newline at end of file diff --git a/src/groups/calls/lists/explicit-sexual-language.txt b/src/groups/calls/lists/explicit-sexual-language.txt index 4d97380..f16f7dc 100644 --- a/src/groups/calls/lists/explicit-sexual-language.txt +++ b/src/groups/calls/lists/explicit-sexual-language.txt @@ -56,9 +56,6 @@ gang bang squirt squirting squirts -bitch -bih -bich hoe // ho is in "explicit sexual language typos" because it's usually also a typo of "hi". it gets // censored instead of banned. diff --git a/src/groups/calls/lists/mild-swear-words.txt b/src/groups/calls/lists/mild-swear-words.txt index fcb230b..cc72613 100644 --- a/src/groups/calls/lists/mild-swear-words.txt +++ b/src/groups/calls/lists/mild-swear-words.txt @@ -12,4 +12,7 @@ fuck u shit sht ass -huz \ No newline at end of file +huz +bitch +bih +bich \ No newline at end of file diff --git a/src/groups/calls/lists/threats-and-self-harm.txt b/src/groups/calls/lists/threats-and-self-harm.txt index 159d95a..131bdf0 100644 --- a/src/groups/calls/lists/threats-and-self-harm.txt +++ b/src/groups/calls/lists/threats-and-self-harm.txt @@ -5,7 +5,6 @@ hang urself hang yourself gkys gokys -keys get raped rape you rape u diff --git a/src/groups/calls/mod.rs b/src/groups/calls/mod.rs index 1b42859..096e9c1 100644 --- a/src/groups/calls/mod.rs +++ b/src/groups/calls/mod.rs @@ -11,6 +11,7 @@ pub(super) mod embeds; pub mod events; pub(super) mod moderation; pub(super) mod permissions; +pub(super) mod strings; #[derive(Debug, Clone)] pub struct DisplayProfile { diff --git a/src/groups/calls/strings.rs b/src/groups/calls/strings.rs new file mode 100644 index 0000000..b3c4196 --- /dev/null +++ b/src/groups/calls/strings.rs @@ -0,0 +1,141 @@ +use once_cell::sync::Lazy; +use rand::{SeedableRng, seq::IndexedRandom}; +use rand_chacha::ChaCha20Rng; + +static STRINGS_TIPS: Lazy> = Lazy::new(|| { + let json = include_str!("strings/tips.json"); + let strings: Vec = + serde_json::from_str(json).expect("Failed to parse strings/tips.json strings"); + + assert_ne!(strings.len(), 0, "No strings found in strings/tips.json"); + + strings +}); + +pub fn get_string_tips(prefix: &str) -> String { + let mut rng = ChaCha20Rng::from_os_rng(); + let message = STRINGS_TIPS + .choose(&mut rng) + .expect("Failed to choose a random string from tips"); + + message.replace("{prefix}", prefix) +} + +static STRINGS_CALL_ANSWERED: Lazy> = Lazy::new(|| { + let json = include_str!("strings/call-answered.json"); + let strings: Vec = + serde_json::from_str(json).expect("Failed to parse strings/call-answered.json strings"); + + assert_ne!( + strings.len(), + 0, + "No strings found in strings/call-answered.json" + ); + + strings +}); + +pub fn get_string_call_answered(prefix: &str) -> String { + let mut rng = ChaCha20Rng::from_os_rng(); + let message = STRINGS_CALL_ANSWERED + .choose(&mut rng) + .expect("Failed to choose a random string from call answered strings"); + + message.replace("{prefix}", prefix) +} + +static STRINGS_CALL_SEARCHING: Lazy> = Lazy::new(|| { + let json = include_str!("strings/call-searching.json"); + + let strings: Vec = + serde_json::from_str(json).expect("Failed to parse strings/call-searching.json strings"); + + assert_ne!( + strings.len(), + 0, + "No strings found in strings/call-searching.json" + ); + + strings +}); + +pub fn get_string_call_searching(prefix: &str) -> String { + let mut rng = ChaCha20Rng::from_os_rng(); + let message = STRINGS_CALL_SEARCHING + .choose(&mut rng) + .expect("Failed to choose a random string from call starting strings"); + + message.replace("{prefix}", prefix) +} + +static STRINGS_CALL_NO_ANSWER: Lazy> = Lazy::new(|| { + let json = include_str!("strings/call-no-answer.json"); + + let strings: Vec = + serde_json::from_str(json).expect("Failed to parse strings/call-no-answer.json strings"); + + assert_ne!( + strings.len(), + 0, + "No strings found in strings/call-no-answer.json" + ); + + strings +}); + +pub fn get_string_call_no_answer(prefix: &str) -> String { + let mut rng = ChaCha20Rng::from_os_rng(); + let message = STRINGS_CALL_NO_ANSWER + .choose(&mut rng) + .expect("Failed to choose a random string from call no answer strings"); + + message.replace("{prefix}", prefix) +} + +static STRINGS_CALL_HANGUP_THIS_PARTY: Lazy> = Lazy::new(|| { + let json = include_str!("strings/call-hangup-this-party.json"); + + let strings: Vec = serde_json::from_str(json) + .expect("Failed to parse strings/call-hangup-this-party.json strings"); + + assert_ne!( + strings.len(), + 0, + "No strings found in strings/call-hangup-this-party.json" + ); + + strings +}); + +pub fn get_string_call_hangup_this_party(prefix: &str) -> String { + let mut rng = ChaCha20Rng::from_os_rng(); + let message = STRINGS_CALL_HANGUP_THIS_PARTY + .choose(&mut rng) + .expect("Failed to choose a random string from call hangup this party strings"); + + message.replace("{prefix}", prefix) +} + +static STRINGS_CALL_HANGUP_OTHER_PARTY: Lazy> = Lazy::new(|| { + let json = include_str!("strings/call-hangup-other-party.json"); + + let strings: Vec = serde_json::from_str(json) + .expect("Failed to parse strings/call-hangup-other-party.json strings"); + + assert_ne!( + strings.len(), + 0, + "No strings found in strings/call-hangup-other-party.json" + ); + + strings +}); + +pub fn get_string_call_hangup_other_party(prefix: &str) -> String { + let mut rng = ChaCha20Rng::from_os_rng(); + let message = STRINGS_CALL_HANGUP_OTHER_PARTY + .choose(&mut rng) + .expect("Failed to choose a random string from call hangup other party strings"); + + message.replace("{prefix}", prefix) +} diff --git a/src/groups/calls/strings/call-starting.json b/src/groups/calls/strings/call-searching.json similarity index 100% rename from src/groups/calls/strings/call-starting.json rename to src/groups/calls/strings/call-searching.json diff --git a/src/groups/calls/strings/tips.json b/src/groups/calls/strings/tips.json index 934316d..c551f6e 100644 --- a/src/groups/calls/strings/tips.json +++ b/src/groups/calls/strings/tips.json @@ -1,23 +1,19 @@ [ - "You can report calls using `Apps > Report Message`.", + "You can report messages using `Message > Apps > Report Message`.", "Help us sharing Payphone to make it more active!", - "You can check your stats with `{prefix}me`.", "Emojis will only show if they're from a server Payphone's in.", "You cannot send links.", "[Vote for Payphone on top.gg]() to help us reach more users!", "[Write a review]() to tell everyone your opinion about Payphone!", "Calls will be automatically hung up after 15 minutes if nobody talks.", - "You can change Payphone's prefix with `{prefix}config prefix`.", - "Do you have any suggestions? Use `{prefix}suggest`!", + "You can change Payphone's prefix with `{prefix}prefix`.", "You can use `{prefix}skip` to directly search for a new call.", - "The links from `{prefix}history` will take you to that call.", "Want to stay hidden? Use `{prefix}mask on`!", "Did you know you can check your mask with `{prefix}mask`?", "Do you like Payphone? Consider [making a donation]() to help us grow Payphone (and keep it running)!", "Using `{prefix}friendreq` is the best way to ask the other party to add you.", - "Enable and disable channels using `{prefix}config enable` and `{prefix}config disable`!", "There's a secret easter egg command. Try to find it! (Hint: cat)", "Make sure to read Payphone's [Code of Conduct](). Let's keep Payphone safe and fun for everyone!", "Did you join [Payphone's new official server]() yet? We have a lot of fun stuff there!", - "How high are you on the leaderboard? Use `{prefix}me`, `{prefix}leaderboard`, and `{prefix}leaderboard servers` to check it out!" + "How high are you on the leaderboard? Use `{prefix}leaderboard` to check it out!" ] \ No newline at end of file