summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorSefa Eyeoglu <[email protected]>2023-05-19 14:08:54 +0200
committerseth <[email protected]>2023-05-19 09:36:45 -0400
commit913f1bf789e4ad9d7bae13e13d318620cea6761b (patch)
tree37358abbc3323183bf88727f3c865e628aa776d4 /src/main.rs
parente1e485d973fcb2f787e10deb60d85a6e8e7fa486 (diff)
feat: detect custom moyai emojis
Signed-off-by: Sefa Eyeoglu <[email protected]>
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index fac587a..01b3fb2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+use lazy_static::lazy_static;
+use regex::Regex;
use serenity::async_trait;
use serenity::framework::standard::macros::{command, group};
use serenity::framework::standard::{CommandResult, StandardFramework};
@@ -41,14 +43,26 @@ impl EventHandler for Handler {
echo_msgs.push(emoji);
}
- for echo in echo_msgs {
- if msg.content.as_str() == echo {
- let send = msg.reply(&ctx, echo);
- if let Err(why) = send.await {
- println!("error when replying to {:?}: {:?}", msg.content, why);
+ let mut should_echo = echo_msgs.contains(&msg.content.as_str());
+
+ if !should_echo {
+ lazy_static! {
+ static ref EMOJI_RE: Regex = Regex::new(r"^<a?:(\w+):\d+>$").unwrap();
+ }
+ if let Some(cap) = EMOJI_RE.captures(msg.content.as_str()) {
+ if let Some(emoji_name) = cap.get(1) {
+ let emoji_name = emoji_name.as_str();
+ should_echo = emoji_name.contains("moai") || emoji_name.contains("moyai");
}
}
}
+
+ if should_echo {
+ let send = msg.reply(&ctx, msg.content.as_str());
+ if let Err(why) = send.await {
+ println!("error when replying to {:?}: {:?}", msg.content, why);
+ }
+ }
}
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {