diff options
| author | Sefa Eyeoglu <[email protected]> | 2023-05-19 14:08:54 +0200 |
|---|---|---|
| committer | seth <[email protected]> | 2023-05-19 09:36:45 -0400 |
| commit | 913f1bf789e4ad9d7bae13e13d318620cea6761b (patch) | |
| tree | 37358abbc3323183bf88727f3c865e628aa776d4 | |
| parent | e1e485d973fcb2f787e10deb60d85a6e8e7fa486 (diff) | |
feat: detect custom moyai emojis
Signed-off-by: Sefa Eyeoglu <[email protected]>
| -rw-r--r-- | Cargo.lock | 34 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/main.rs | 24 |
3 files changed, 55 insertions, 5 deletions
@@ -9,6 +9,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] +name = "aho-corasick" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" +dependencies = [ + "memchr", +] + +[[package]] name = "android_system_properties" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -638,6 +647,12 @@ dependencies = [ ] [[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] name = "levenshtein" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -958,6 +973,23 @@ dependencies = [ ] [[package]] +name = "regex" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" + +[[package]] name = "reqwest" version = "0.11.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1239,7 +1271,9 @@ version = "0.1.0" dependencies = [ "bottomify", "include_dir", + "lazy_static", "rand 0.8.5", + "regex", "reqwest", "serde", "serenity", @@ -8,7 +8,9 @@ edition = "2021" [dependencies] bottomify = "1.2.0" include_dir = "0.7.3" +lazy_static = "1.4.0" rand = "0.8.5" +regex = "1.8.1" reqwest = { version = "0.11.17", default-features = false, features = ["rustls-tls", "json"] } serde = "1.0.163" serenity = "0.11.5" 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) { |
