diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 24 |
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) { |
