6.diff (3188B)
1 diff --git a/example-bot/Cargo.toml b/example-bot/Cargo.toml 2 index a72742a..ab47333 100644 3 --- a/example-bot/Cargo.toml 4 +++ b/example-bot/Cargo.toml 5 @@ -18,7 +18,7 @@ serde = "1.0" 6 tracing = "0.1" 7 tracing-subscriber = "0.3.1" 8 tracing-futures = "0.2.4" 9 -tokio = { version = "1", features = ["full"] } 10 +tokio = { version = "1", features = ["rt", "rt-multi-thread", "sync", "macros"] } 11 clap = "=3.0.0-beta.2" 12 clap_derive = "=3.0.0-beta.2" 13 async-trait = "0.1.41" 14 diff --git a/mrsbfh-macros/src/lib.rs b/mrsbfh-macros/src/lib.rs 15 index 5666f22..1555b80 100644 16 --- a/mrsbfh-macros/src/lib.rs 17 +++ b/mrsbfh-macros/src/lib.rs 18 @@ -254,13 +254,11 @@ pub fn commands(_: TokenStream, input: TokenStream) -> TokenStream { 19 let cloned_config = config.clone(); 20 let cloned_client = client.clone(); 21 tokio::spawn(async move { 22 - let whitespace_deduplicator_magic = regex::Regex::new(r"\s+").unwrap(); 23 - let command_matcher_magic = regex::Regex::new(r"!([\w-]+)").unwrap(); 24 - let normalized_body = whitespace_deduplicator_magic.replace_all(&msg_body, " "); 25 + let normalized_body = mrsbfh::commands::command_utils::WHITESPACE_DEDUPLICATOR_MAGIC.replace_all(&msg_body, " "); 26 let mut split = msg_body.split_whitespace(); 27 28 let command_raw = split.next().expect("This is not a command").to_lowercase(); 29 - let command = command_matcher_magic.captures(command_raw.as_str()) 30 + let command = mrsbfh::commands::command_utils::COMMAND_MATCHER_MAGIC.captures(command_raw.as_str()) 31 .map_or(String::new(), |caps| { 32 caps.get(1) 33 .map_or(String::new(), 34 diff --git a/mrsbfh/Cargo.toml b/mrsbfh/Cargo.toml 35 index 37e1abd..188e14d 100644 36 --- a/mrsbfh/Cargo.toml 37 +++ b/mrsbfh/Cargo.toml 38 @@ -23,7 +23,7 @@ thiserror = "1.0" 39 # Command macros 40 mrsbfh-macros = {version = "0.2.0", path = "../mrsbfh-macros", optional = true} 41 42 -tokio = { version = "1", features = ["full"] } 43 +tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] } 44 tracing = "0.1" 45 46 serde = "1.0" 47 @@ -34,6 +34,7 @@ pulldown-cmark = "0.8.0" # For generating the help text 48 49 regex = "1.4" 50 async-trait = "0.1" 51 +lazy_static = "1" 52 53 [features] 54 default = ["macros", "native-tls"] 55 diff --git a/mrsbfh/src/commands.rs b/mrsbfh/src/commands.rs 56 index 5f24e7e..84977df 100644 57 --- a/mrsbfh/src/commands.rs 58 +++ b/mrsbfh/src/commands.rs 59 @@ -119,5 +119,16 @@ 60 //! in the example. 61 //! 62 63 +pub mod command_utils { 64 + use lazy_static::lazy_static; 65 + 66 + lazy_static! { 67 + pub static ref WHITESPACE_DEDUPLICATOR_MAGIC: regex::Regex = 68 + regex::Regex::new(r"\s+").unwrap(); 69 + pub static ref COMMAND_MATCHER_MAGIC: regex::Regex = 70 + regex::Regex::new(r"!([\w-]+)").unwrap(); 71 + } 72 +} 73 + 74 #[cfg(feature = "macros")] 75 pub use mrsbfh_macros::{command, command_generate, commands};