diff options
| author | Jokler <jokler.contact@gmail.com> | 2017-10-13 16:32:14 +0200 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2017-10-13 16:32:14 +0200 |
| commit | 26f823b19d791e93a38712457df9294f3d1d2224 (patch) | |
| tree | f69ed11e2d84b4e67d04fe5ae2ad3a4a27e0c882 | |
| parent | 725946b73de13b3d09866849f0d8a39728eb0cda (diff) | |
| download | frippy-26f823b19d791e93a38712457df9294f3d1d2224.tar.gz frippy-26f823b19d791e93a38712457df9294f3d1d2224.zip | |
Do not use regex to check for commands
| -rw-r--r-- | src/lib.rs | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -12,8 +12,6 @@ //! ``` #[macro_use] -extern crate lazy_static; -#[macro_use] extern crate plugin_derive; extern crate irc; @@ -24,7 +22,6 @@ 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; @@ -141,24 +138,21 @@ fn get_command(nick: &str, message: &Message) -> Option<PluginCommand> { .map(ToOwned::to_owned) .collect(); - // Check if the message contained notthing but spaces + // Check if the message contained nothing but spaces if tokens.is_empty() { return None; } - // Only compile the regex once - // We assume that only ':' and ',' are used as suffixes on IRC - lazy_static! { - static ref RE: Regex = Regex::new("^[:,]*?$").unwrap(); - } - + // Commands start with our name if tokens[0].to_lowercase().starts_with(nick) { // Remove the bot's name from the first token tokens[0].drain(..nick.len()); - // If the regex does not match the message is not directed at the bot - if !RE.is_match(&tokens[0]) { + // We assume that only ':' and ',' are used as suffixes on IRC + // If there are any other chars we assume that it is not ment for the bot + tokens[0] = tokens[0].chars().filter(|&c| !":,".contains(c)).collect(); + if !tokens[0].is_empty() { return None; } |
