commit e073f78f27626d407ba54e3d32be9acaf8e8d9ce
parent afabbf80a049e5439ccc3acac4ef01ea83fd5af2
Author: Marcel <MTRNord@users.noreply.github.com>
Date: Sat, 13 Nov 2021 15:41:18 +0100
Merge pull request #6 from donicrosby/use-lazy-static-macro
Regexs use lazy_static macro
Diffstat:
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/example-bot/Cargo.toml b/example-bot/Cargo.toml
@@ -18,7 +18,7 @@ serde = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3.1"
tracing-futures = "0.2.4"
-tokio = { version = "1", features = ["full"] }
+tokio = { version = "1", features = ["rt", "rt-multi-thread", "sync", "macros"] }
clap = "=3.0.0-beta.2"
clap_derive = "=3.0.0-beta.2"
async-trait = "0.1.41"
diff --git a/mrsbfh-macros/src/lib.rs b/mrsbfh-macros/src/lib.rs
@@ -254,13 +254,11 @@ pub fn commands(_: TokenStream, input: TokenStream) -> TokenStream {
let cloned_config = config.clone();
let cloned_client = client.clone();
tokio::spawn(async move {
- let whitespace_deduplicator_magic = regex::Regex::new(r"\s+").unwrap();
- let command_matcher_magic = regex::Regex::new(r"!([\w-]+)").unwrap();
- let normalized_body = whitespace_deduplicator_magic.replace_all(&msg_body, " ");
+ let normalized_body = mrsbfh::commands::command_utils::WHITESPACE_DEDUPLICATOR_MAGIC.replace_all(&msg_body, " ");
let mut split = msg_body.split_whitespace();
let command_raw = split.next().expect("This is not a command").to_lowercase();
- let command = command_matcher_magic.captures(command_raw.as_str())
+ let command = mrsbfh::commands::command_utils::COMMAND_MATCHER_MAGIC.captures(command_raw.as_str())
.map_or(String::new(), |caps| {
caps.get(1)
.map_or(String::new(),
diff --git a/mrsbfh/Cargo.toml b/mrsbfh/Cargo.toml
@@ -23,7 +23,7 @@ thiserror = "1.0"
# Command macros
mrsbfh-macros = {version = "0.2.0", path = "../mrsbfh-macros", optional = true}
-tokio = { version = "1", features = ["full"] }
+tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
tracing = "0.1"
serde = "1.0"
@@ -34,6 +34,7 @@ pulldown-cmark = "0.8.0" # For generating the help text
regex = "1.4"
async-trait = "0.1"
+lazy_static = "1"
[features]
default = ["macros", "native-tls"]
diff --git a/mrsbfh/src/commands.rs b/mrsbfh/src/commands.rs
@@ -119,5 +119,16 @@
//! in the example.
//!
+pub mod command_utils {
+ use lazy_static::lazy_static;
+
+ lazy_static! {
+ pub static ref WHITESPACE_DEDUPLICATOR_MAGIC: regex::Regex =
+ regex::Regex::new(r"\s+").unwrap();
+ pub static ref COMMAND_MATCHER_MAGIC: regex::Regex =
+ regex::Regex::new(r"!([\w-]+)").unwrap();
+ }
+}
+
#[cfg(feature = "macros")]
pub use mrsbfh_macros::{command, command_generate, commands};