summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2017-10-09 23:55:47 +0200
committerJokler <jokler.contact@gmail.com>2017-10-11 15:41:32 +0200
commit44d50cecf46e379ef42381d435c1db13cdea1e82 (patch)
tree22b7436c254dd60f2ebebeb0e4293e9c780cb516
parentea3cd019142d2276ba9a6a9a3945143b18789873 (diff)
downloadfrippy-44d50cecf46e379ef42381d435c1db13cdea1e82.tar.gz
frippy-44d50cecf46e379ef42381d435c1db13cdea1e82.zip
Use regex to check for commands
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--src/lib.rs15
3 files changed, 17 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4d65484..5ff705b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,6 +4,7 @@ version = "0.1.0"
dependencies = [
"clippy 0.0.165 (registry+https://github.com/rust-lang/crates.io-index)",
"irc 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 21af580..552d95c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,6 +22,7 @@ doc = false
irc = "0.12.5"
reqwest = "0.8.0"
regex = "0.2.2"
+lazy_static = "0.2.9"
serde = "1.0.15"
serde_json = "1.0.3"
diff --git a/src/lib.rs b/src/lib.rs
index efd15fd..a5ce23b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,7 +1,11 @@
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
+#[macro_use]
+extern crate lazy_static;
+
extern crate irc;
+extern crate regex;
#[macro_use]
mod plugin;
@@ -9,6 +13,7 @@ mod plugins;
use std::thread::spawn;
use std::sync::{Arc, Mutex};
+use regex::Regex;
use irc::client::prelude::*;
use irc::proto::Command::PRIVMSG;
use irc::error::Error as IrcError;
@@ -98,7 +103,17 @@ fn get_command(nick: &str, message: &Message) -> Option<PluginCommand> {
return None;
}
+ lazy_static! {
+ static ref RE: Regex = Regex::new("^[:,]*?$").unwrap();
+ }
+
if tokens[0].to_lowercase().starts_with(nick) {
+ tokens[0].drain(..nick.len());
+
+ if !RE.is_match(&tokens[0]) {
+ return None;
+ }
+
tokens.remove(0);
Some(PluginCommand {