Skip to content

Commit

Permalink
Fine, add excluded roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Kile committed Mar 19, 2024
1 parent 5971f37 commit 0090996
Showing 1 changed file with 62 additions and 32 deletions.
94 changes: 62 additions & 32 deletions src/events/dot_remover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ use serenity::prelude::*;

pub struct DotHandler;

const DOTS: [StrOrChar<&str>; 27] = [
StrOrChar::Char('.'),
StrOrChar::Char('·'),
StrOrChar::Char('․'),
StrOrChar::Char('‧'),
StrOrChar::Char('⋅'),
StrOrChar::Char('・'),
StrOrChar::Char('⸱'),
StrOrChar::Char('ᐧ'),
StrOrChar::Char('⏺'),
StrOrChar::Char('●'),
StrOrChar::Char('⚬'),
StrOrChar::Char('⦁'),
StrOrChar::Char('⸰'),
StrOrChar::Char('﹒'),
StrOrChar::Char('⸱'),
StrOrChar::Char('⋅'),
StrOrChar::Char('。'),
StrOrChar::Char('.'),
StrOrChar::Char('。'),
StrOrChar::Char('܂'),
StrOrChar::Char('˳'),
StrOrChar::Char('݀'),
StrOrChar::Char('݂'),
StrOrChar::Char('ܼ'),
StrOrChar::Char('ٜ'),
StrOrChar::Char('ִ'),
StrOrChar::Char('ׅ'),
];

const EXLUDED: u64 = 1166491561614385303;

enum StrOrChar<T: AsRef<str>> {
Str(T),
Char(char),
Expand Down Expand Up @@ -53,36 +85,6 @@ impl std::fmt::Display for StrOrChar<&str> {
}
}

const DOTS: [StrOrChar<&str>; 27] = [
StrOrChar::Char('.'),
StrOrChar::Char('·'),
StrOrChar::Char('․'),
StrOrChar::Char('‧'),
StrOrChar::Char('⋅'),
StrOrChar::Char('・'),
StrOrChar::Char('⸱'),
StrOrChar::Char('ᐧ'),
StrOrChar::Char('⏺'),
StrOrChar::Char('●'),
StrOrChar::Char('⚬'),
StrOrChar::Char('⦁'),
StrOrChar::Char('⸰'),
StrOrChar::Char('﹒'),
StrOrChar::Char('⸱'),
StrOrChar::Char('⋅'),
StrOrChar::Char('。'),
StrOrChar::Char('.'),
StrOrChar::Char('。'),
StrOrChar::Char('܂'),
StrOrChar::Char('˳'),
StrOrChar::Char('݀'),
StrOrChar::Char('݂'),
StrOrChar::Char('ܼ'),
StrOrChar::Char('ٜ'),
StrOrChar::Char('ִ'),
StrOrChar::Char('ׅ'),
];

fn remove_whitespace_from_end(text: &str, dot: &StrOrChar<&str>) -> String {
const WHITESPACE: [StrOrChar<&str>; 21] = [
StrOrChar::Char('\u{2000}'),
Expand Down Expand Up @@ -319,7 +321,20 @@ impl EventHandler for DotHandler {
if msg.author.bot {
return;
}
// TODO add excluded users
// If the message is in dms
if msg.guild_id.is_none() {
return;
}
// Check if the message is fron a user with an exluded role
if msg
.author
.has_role(&ctx.http, msg.guild_id.unwrap(), EXLUDED)
.await
.unwrap_or(false)
{
return;
}

// Figure out if it ends with a single dot and only has one
// sentence using regex
let text = find_if_dot(&msg.clone().content);
Expand Down Expand Up @@ -371,7 +386,22 @@ impl EventHandler for DotHandler {
if event.clone().author.unwrap().bot {
return;
}
// TODO add excluded users
// If the message is in dms
if event.guild_id.is_none() {
return;
}
// Check if the message is fron a user with an exluded role
if event
.clone()
.author
.unwrap()
.has_role(&ctx.http, event.clone().guild_id.unwrap(), EXLUDED)
.await
.unwrap_or(false)
{
return;
}

// Figure out if it ends with a single dot and only has one
// sentence using regex
let text = find_if_dot(&event.clone().content.unwrap());
Expand Down

0 comments on commit 0090996

Please sign in to comment.