Checkpoint
This commit is contained in:
+36
-28
@@ -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<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(
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
@@ -774,7 +782,7 @@ impl Rule for LinksRule {
|
||||
|
||||
(detections, vec![])
|
||||
}
|
||||
|
||||
|
||||
fn ignore_for_moderators(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user