From d0b5f86740ecce02b79e201aef6fd7f176f28b2c Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Thu, 26 Feb 2026 01:55:07 -0300 Subject: [PATCH] Checkpoint --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/framework/bot.rs | 2 +- src/framework/runtime.rs | 4 +-- src/groups/about/tasks.rs | 64 +++++++++++++++++++--------------- src/groups/calls/events.rs | 6 ++-- src/groups/calls/moderation.rs | 22 ++++++++---- 7 files changed, 59 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2deca46..b821baf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2013,7 +2013,7 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" [[package]] name = "payphone" -version = "4.4.32" +version = "4.4.35" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 7f51cfd..819d8c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "payphone" -version = "4.4.32" +version = "4.4.35" edition = "2024" default-run = "payphone" diff --git a/src/framework/bot.rs b/src/framework/bot.rs index bf32e69..26cea17 100644 --- a/src/framework/bot.rs +++ b/src/framework/bot.rs @@ -494,7 +494,7 @@ where }); } Some(json) = gateway_rx.recv() => { - gateway.send(json) + gateway.command(&json); } } } diff --git a/src/framework/runtime.rs b/src/framework/runtime.rs index 57727eb..1ab1514 100644 --- a/src/framework/runtime.rs +++ b/src/framework/runtime.rs @@ -22,7 +22,7 @@ use std::sync::Arc; use tokio::sync::mpsc::UnboundedSender; use twilight_cache_inmemory::InMemoryCache; use twilight_http::Client; -use twilight_model::oauth::Application; +use twilight_model::{gateway::payload::outgoing::UpdatePresence, oauth::Application}; use crate::framework::{ bot::PrefixGetter, commands::Command, interactions::registry::ComponentRegistry, @@ -51,7 +51,7 @@ pub struct Runtime { pub cache: InMemoryCache, /// Used to send messages through the gateway. - pub gateway_tx: UnboundedSender, + pub gateway_tx: UnboundedSender, pub shard_number: u32, pub shard_total: u32, diff --git a/src/groups/about/tasks.rs b/src/groups/about/tasks.rs index 350f5ed..4c0dbc5 100644 --- a/src/groups/about/tasks.rs +++ b/src/groups/about/tasks.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha20Rng; use twilight_model::gateway::{ - payload::outgoing::update_presence::UpdatePresencePayload, + payload::outgoing::{UpdatePresence, update_presence::UpdatePresencePayload}, presence::{Activity, ActivityType, Status}, }; @@ -224,38 +224,46 @@ impl Task for UpdatePresenceTask { "Cuando se apaga la luz", "Annie, are you ok?", "Will you tell us that you're ok?", + "Life's like a road that you travel on", + "Life is a highway, I wanna ride it all night long", + "I wanna drive it all night long (all night long)", + "Tu cuerpo y el mío, llenando el vacío, subiendo y bajando", + "Yo quiero estar contigo, vivir contigo, bailar contigo, tener contigo una noche loca", + "But let me stop you there, oh, before you speak", + "Nah to the ah to the, no, no, no", + "My name is no, my sign is no, my number is no", + "If that boy ain't giving up, lick your lips and swing your hips", ]; let mut rng = ChaCha20Rng::from_os_rng(); let index = rng.random_range(0..presences.len()); - rt.gateway_tx - .send(serde_json::to_string(&UpdatePresencePayload::new( - vec![Activity { - application_id: None, - assets: None, - buttons: vec![], - created_at: None, - details: None, - emoji: None, - flags: None, - id: None, - instance: None, - kind: ActivityType::Listening, - name: format!( - "p.help - \"{}\" - {}/{}", - presences[index], rt.shard_number, rt.shard_total - ), - party: None, - secrets: None, - state: None, - timestamps: None, - url: None, - }], - false, - None, - Status::Online, - )?)?)?; + rt.gateway_tx.send(UpdatePresence::new( + vec![Activity { + application_id: None, + assets: None, + buttons: vec![], + created_at: None, + details: None, + emoji: None, + flags: None, + id: None, + instance: None, + kind: ActivityType::Listening, + name: format!( + "p.help - \"{}\" - {}/{}", + presences[index], rt.shard_number, rt.shard_total + ), + party: None, + secrets: None, + state: None, + timestamps: None, + url: None, + }], + false, + None, + Status::Online, + )?)?; Ok(()) } diff --git a/src/groups/calls/events.rs b/src/groups/calls/events.rs index 87ad649..2bfc9f2 100644 --- a/src/groups/calls/events.rs +++ b/src/groups/calls/events.rs @@ -241,7 +241,7 @@ impl OnMessageHandler for CallMessageHandler { return Ok(()); }; - let (content, rules) = escape_message(event); + let (content, rules) = escape_message(event, user.is_moderator); let message: Message; @@ -377,7 +377,7 @@ impl OnMessageHandler for CallMessageHandler { .and_then(|i| i.color.map(|c| c as u32)) .unwrap_or(COLOR_WHITE) }) - .description(ellipse(moderate_message(&replying_to.data.content).0, 100)) + .description(ellipse(moderate_message(&replying_to.data.content, false).0, 100)) .build(), ); } @@ -531,7 +531,7 @@ impl OnMessageEditHandler for CallMessageEditHandler { }; if let Some(propagation_message_id) = message.data.propagation_message_id { - let (content, rules) = escape_message(event); + let (content, rules) = escape_message(event, false); if rules .iter() diff --git a/src/groups/calls/moderation.rs b/src/groups/calls/moderation.rs index 436fd9c..01054d2 100644 --- a/src/groups/calls/moderation.rs +++ b/src/groups/calls/moderation.rs @@ -99,12 +99,13 @@ use crate::discord::sanitizing::SanitizeDiscordMarkdown; /// and @here pings, and censoring by rules. /// /// Arguments: -/// * `event`: The incoming message event to escape. +/// * `event` - The incoming message event to escape. +/// * `is_moderator` - Whether the message was sent by a moderator. /// /// Returns: /// [`(String, Vec>)`] - The escaped and censored message, and a vector of the rules /// broken. -pub fn escape_message(event: &Message) -> (String, Vec>) { +pub fn escape_message(event: &Message, is_moderator: bool) -> (String, Vec>) { let mut message = event.content.to_string(); for mention in &event.mentions { @@ -125,7 +126,7 @@ pub fn escape_message(event: &Message) -> (String, Vec>) { ); } - let (censored, rules) = moderate_message(&message); + let (censored, rules) = moderate_message(&message, is_moderator); log::debug!("Escaped and normalized message: {censored:?}"); log::debug!("Rules broken: {rules:?}"); @@ -272,15 +273,21 @@ type RuleAnalysis = ((Vec, Vec), Arc); /// Arguments: /// * `original` - The original message without normalization. /// * `normalized` - The normalized version of the message. +/// * `is_moderator` - Whether the message was sent by a moderator. /// /// Returns: /// [`Vec`] - The results of the analysis, including all detections (on the original /// message first, on the normalized message later) and their associated rules. -pub fn analyze_message(original: &str, normalized: &str) -> Vec { +pub fn analyze_message(original: &str, normalized: &str, is_moderator: bool) -> Vec { let mut results = Vec::new(); for rule in RULES.iter() { + if rule.ignore_for_moderators() && is_moderator { + continue; + } + let (original_detections, normalized_detections) = rule.detect(original, normalized); + if !normalized_detections.is_empty() || !original_detections.is_empty() { results.push(((original_detections, normalized_detections), rule.clone())); } @@ -350,13 +357,14 @@ pub fn censor_message( /// /// Arguments: /// * `original` - The original message. +/// * `is_moderator` - Whether the message was sent by a moderator. /// /// Returns: /// [`(String, Vec>)`] - The censored message and the rules that were broken. -pub fn moderate_message(original: &str) -> (String, Vec>) { +pub fn moderate_message(original: &str, is_moderator: bool) -> (String, Vec>) { let normalized = normalize(original.to_string()); - let analysis = analyze_message(original, &normalized.message); + let analysis = analyze_message(original, &normalized.message, is_moderator); let censored = censor_message(original, normalized, &analysis); (censored, analysis.iter().map(|(_, r)| r.clone()).collect()) @@ -774,7 +782,7 @@ impl Rule for LinksRule { (detections, vec![]) } - + fn ignore_for_moderators(&self) -> bool { true }