summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock34
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs24
3 files changed, 55 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6615a65..230d275 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/Cargo.toml b/Cargo.toml
index bcbc5a0..03c7d1f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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) {