Add support for editing messages
This commit is contained in:
@@ -88,7 +88,7 @@ use std::{collections::HashMap, sync::Arc};
|
||||
use linkify::LinkFinder;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use twilight_model::gateway::payload::incoming::MessageCreate;
|
||||
use twilight_model::channel::Message;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
use unidecode::unidecode;
|
||||
|
||||
@@ -103,7 +103,7 @@ use crate::discord::sanitizing::SanitizeDiscordMarkdown;
|
||||
/// Returns:
|
||||
/// [`(String, Vec<Arc<dyn Rule>>)`] - The escaped and censored message, and a vector of the rules
|
||||
/// broken.
|
||||
pub fn escape_message(event: &MessageCreate) -> (String, Vec<Arc<dyn Rule>>) {
|
||||
pub fn escape_message(event: &Message) -> (String, Vec<Arc<dyn Rule>>) {
|
||||
let mut message = event.content.to_string();
|
||||
|
||||
for mention in &event.mentions {
|
||||
@@ -274,10 +274,7 @@ type RuleAnalysis = ((Vec<String>, Vec<String>), Arc<dyn Rule>);
|
||||
/// 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) -> Vec<RuleAnalysis> {
|
||||
let mut results = Vec::new();
|
||||
|
||||
for rule in RULES.iter() {
|
||||
@@ -568,7 +565,10 @@ impl Rule for LinksRule {
|
||||
fn detect(&self, original: &str, _normalized: &str) -> (Vec<String>, Vec<String>) {
|
||||
let mut detections = Vec::new();
|
||||
|
||||
for link in LinkFinder::new().url_must_have_scheme(false).links(original) {
|
||||
for link in LinkFinder::new()
|
||||
.url_must_have_scheme(false)
|
||||
.links(original)
|
||||
{
|
||||
detections.push(link.as_str().to_string());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user