Checkpoint
This commit is contained in:
Generated
+1
-1
@@ -2013,7 +2013,7 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "payphone"
|
name = "payphone"
|
||||||
version = "4.4.32"
|
version = "4.4.35"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "payphone"
|
name = "payphone"
|
||||||
version = "4.4.32"
|
version = "4.4.35"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
default-run = "payphone"
|
default-run = "payphone"
|
||||||
|
|
||||||
|
|||||||
@@ -494,7 +494,7 @@ where
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
Some(json) = gateway_rx.recv() => {
|
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 tokio::sync::mpsc::UnboundedSender;
|
||||||
use twilight_cache_inmemory::InMemoryCache;
|
use twilight_cache_inmemory::InMemoryCache;
|
||||||
use twilight_http::Client;
|
use twilight_http::Client;
|
||||||
use twilight_model::oauth::Application;
|
use twilight_model::{gateway::payload::outgoing::UpdatePresence, oauth::Application};
|
||||||
|
|
||||||
use crate::framework::{
|
use crate::framework::{
|
||||||
bot::PrefixGetter, commands::Command, interactions::registry::ComponentRegistry,
|
bot::PrefixGetter, commands::Command, interactions::registry::ComponentRegistry,
|
||||||
@@ -51,7 +51,7 @@ pub struct Runtime<T, E> {
|
|||||||
pub cache: InMemoryCache,
|
pub cache: InMemoryCache,
|
||||||
|
|
||||||
/// Used to send messages through the gateway.
|
/// Used to send messages through the gateway.
|
||||||
pub gateway_tx: UnboundedSender<String>,
|
pub gateway_tx: UnboundedSender<UpdatePresence>,
|
||||||
|
|
||||||
pub shard_number: u32,
|
pub shard_number: u32,
|
||||||
pub shard_total: u32,
|
pub shard_total: u32,
|
||||||
|
|||||||
+36
-28
@@ -2,7 +2,7 @@ use async_trait::async_trait;
|
|||||||
use rand::{Rng, SeedableRng};
|
use rand::{Rng, SeedableRng};
|
||||||
use rand_chacha::ChaCha20Rng;
|
use rand_chacha::ChaCha20Rng;
|
||||||
use twilight_model::gateway::{
|
use twilight_model::gateway::{
|
||||||
payload::outgoing::update_presence::UpdatePresencePayload,
|
payload::outgoing::{UpdatePresence, update_presence::UpdatePresencePayload},
|
||||||
presence::{Activity, ActivityType, Status},
|
presence::{Activity, ActivityType, Status},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -224,38 +224,46 @@ impl Task<State, Extras> for UpdatePresenceTask {
|
|||||||
"Cuando se apaga la luz",
|
"Cuando se apaga la luz",
|
||||||
"Annie, are you ok?",
|
"Annie, are you ok?",
|
||||||
"Will you tell us that you're 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 mut rng = ChaCha20Rng::from_os_rng();
|
||||||
let index = rng.random_range(0..presences.len());
|
let index = rng.random_range(0..presences.len());
|
||||||
|
|
||||||
rt.gateway_tx
|
rt.gateway_tx.send(UpdatePresence::new(
|
||||||
.send(serde_json::to_string(&UpdatePresencePayload::new(
|
vec![Activity {
|
||||||
vec![Activity {
|
application_id: None,
|
||||||
application_id: None,
|
assets: None,
|
||||||
assets: None,
|
buttons: vec![],
|
||||||
buttons: vec![],
|
created_at: None,
|
||||||
created_at: None,
|
details: None,
|
||||||
details: None,
|
emoji: None,
|
||||||
emoji: None,
|
flags: None,
|
||||||
flags: None,
|
id: None,
|
||||||
id: None,
|
instance: None,
|
||||||
instance: None,
|
kind: ActivityType::Listening,
|
||||||
kind: ActivityType::Listening,
|
name: format!(
|
||||||
name: format!(
|
"p.help - \"{}\" - {}/{}",
|
||||||
"p.help - \"{}\" - {}/{}",
|
presences[index], rt.shard_number, rt.shard_total
|
||||||
presences[index], rt.shard_number, rt.shard_total
|
),
|
||||||
),
|
party: None,
|
||||||
party: None,
|
secrets: None,
|
||||||
secrets: None,
|
state: None,
|
||||||
state: None,
|
timestamps: None,
|
||||||
timestamps: None,
|
url: None,
|
||||||
url: None,
|
}],
|
||||||
}],
|
false,
|
||||||
false,
|
None,
|
||||||
None,
|
Status::Online,
|
||||||
Status::Online,
|
)?)?;
|
||||||
)?)?)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ impl OnMessageHandler<State, Extras> for CallMessageHandler {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let (content, rules) = escape_message(event);
|
let (content, rules) = escape_message(event, user.is_moderator);
|
||||||
|
|
||||||
let message: Message;
|
let message: Message;
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ impl OnMessageHandler<State, Extras> for CallMessageHandler {
|
|||||||
.and_then(|i| i.color.map(|c| c as u32))
|
.and_then(|i| i.color.map(|c| c as u32))
|
||||||
.unwrap_or(COLOR_WHITE)
|
.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(),
|
.build(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -531,7 +531,7 @@ impl OnMessageEditHandler<State, Extras> for CallMessageEditHandler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(propagation_message_id) = message.data.propagation_message_id {
|
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
|
if rules
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -99,12 +99,13 @@ use crate::discord::sanitizing::SanitizeDiscordMarkdown;
|
|||||||
/// and @here pings, and censoring by rules.
|
/// and @here pings, and censoring by rules.
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// 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:
|
/// Returns:
|
||||||
/// [`(String, Vec<Arc<dyn Rule>>)`] - The escaped and censored message, and a vector of the rules
|
/// [`(String, Vec<Arc<dyn Rule>>)`] - The escaped and censored message, and a vector of the rules
|
||||||
/// broken.
|
/// 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();
|
let mut message = event.content.to_string();
|
||||||
|
|
||||||
for mention in &event.mentions {
|
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!("Escaped and normalized message: {censored:?}");
|
||||||
log::debug!("Rules broken: {rules:?}");
|
log::debug!("Rules broken: {rules:?}");
|
||||||
@@ -272,15 +273,21 @@ type RuleAnalysis = ((Vec<String>, Vec<String>), Arc<dyn Rule>);
|
|||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// * `original` - The original message without normalization.
|
/// * `original` - The original message without normalization.
|
||||||
/// * `normalized` - The normalized version of the message.
|
/// * `normalized` - The normalized version of the message.
|
||||||
|
/// * `is_moderator` - Whether the message was sent by a moderator.
|
||||||
///
|
///
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// [`Vec<RuleAnalysis>`] - The results of the analysis, including all detections (on the original
|
/// [`Vec<RuleAnalysis>`] - The results of the analysis, including all detections (on the original
|
||||||
/// message first, on the normalized message later) and their associated rules.
|
/// 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();
|
let mut results = Vec::new();
|
||||||
|
|
||||||
for rule in RULES.iter() {
|
for rule in RULES.iter() {
|
||||||
|
if rule.ignore_for_moderators() && is_moderator {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let (original_detections, normalized_detections) = rule.detect(original, normalized);
|
let (original_detections, normalized_detections) = rule.detect(original, normalized);
|
||||||
|
|
||||||
if !normalized_detections.is_empty() || !original_detections.is_empty() {
|
if !normalized_detections.is_empty() || !original_detections.is_empty() {
|
||||||
results.push(((original_detections, normalized_detections), rule.clone()));
|
results.push(((original_detections, normalized_detections), rule.clone()));
|
||||||
}
|
}
|
||||||
@@ -350,13 +357,14 @@ pub fn censor_message(
|
|||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// * `original` - The original message.
|
/// * `original` - The original message.
|
||||||
|
/// * `is_moderator` - Whether the message was sent by a moderator.
|
||||||
///
|
///
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// [`(String, Vec<Arc<dyn Rule>>)`] - The censored message and the rules that were broken.
|
/// [`(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 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);
|
let censored = censor_message(original, normalized, &analysis);
|
||||||
|
|
||||||
(censored, analysis.iter().map(|(_, r)| r.clone()).collect())
|
(censored, analysis.iter().map(|(_, r)| r.clone()).collect())
|
||||||
@@ -774,7 +782,7 @@ impl Rule for LinksRule {
|
|||||||
|
|
||||||
(detections, vec![])
|
(detections, vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ignore_for_moderators(&self) -> bool {
|
fn ignore_for_moderators(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user