Checkpoint
This commit is contained in:
Generated
+1
-1
@@ -2013,7 +2013,7 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
||||
|
||||
[[package]]
|
||||
name = "payphone"
|
||||
version = "4.4.32"
|
||||
version = "4.4.35"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "payphone"
|
||||
version = "4.4.32"
|
||||
version = "4.4.35"
|
||||
edition = "2024"
|
||||
default-run = "payphone"
|
||||
|
||||
|
||||
@@ -494,7 +494,7 @@ where
|
||||
});
|
||||
}
|
||||
Some(json) = gateway_rx.recv() => {
|
||||
gateway.send(json)
|
||||
gateway.command(&json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T, E> {
|
||||
pub cache: InMemoryCache,
|
||||
|
||||
/// Used to send messages through the gateway.
|
||||
pub gateway_tx: UnboundedSender<String>,
|
||||
pub gateway_tx: UnboundedSender<UpdatePresence>,
|
||||
|
||||
pub shard_number: u32,
|
||||
pub shard_total: u32,
|
||||
|
||||
@@ -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,13 +224,21 @@ impl Task<State, Extras> 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(
|
||||
rt.gateway_tx.send(UpdatePresence::new(
|
||||
vec![Activity {
|
||||
application_id: None,
|
||||
assets: None,
|
||||
@@ -255,7 +263,7 @@ impl Task<State, Extras> for UpdatePresenceTask {
|
||||
false,
|
||||
None,
|
||||
Status::Online,
|
||||
)?)?)?;
|
||||
)?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ impl OnMessageHandler<State, Extras> 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<State, Extras> 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<State, Extras> 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()
|
||||
|
||||
@@ -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<Arc<dyn Rule>>)`] - The escaped and censored message, and a vector of the rules
|
||||
/// broken.
|
||||
pub fn escape_message(event: &Message) -> (String, Vec<Arc<dyn Rule>>) {
|
||||
pub fn escape_message(event: &Message, is_moderator: bool) -> (String, Vec<Arc<dyn Rule>>) {
|
||||
let mut message = event.content.to_string();
|
||||
|
||||
for mention in &event.mentions {
|
||||
@@ -125,7 +126,7 @@ pub fn escape_message(event: &Message) -> (String, Vec<Arc<dyn Rule>>) {
|
||||
);
|
||||
}
|
||||
|
||||
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<String>, Vec<String>), Arc<dyn Rule>);
|
||||
/// 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<RuleAnalysis>`] - 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<RuleAnalysis> {
|
||||
pub fn analyze_message(original: &str, normalized: &str, is_moderator: bool) -> Vec<RuleAnalysis> {
|
||||
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<Arc<dyn Rule>>)`] - The censored message and the rules that were broken.
|
||||
pub fn moderate_message(original: &str) -> (String, Vec<Arc<dyn Rule>>) {
|
||||
pub fn moderate_message(original: &str, is_moderator: bool) -> (String, Vec<Arc<dyn Rule>>) {
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user