From 26f823b19d791e93a38712457df9294f3d1d2224 Mon Sep 17 00:00:00 2001 From: Jokler Date: Fri, 13 Oct 2017 16:32:14 +0200 Subject: Do not use regex to check for commands --- src/lib.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index e1ca7e3..c00d3ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,6 @@ //! frippy::run(); //! ``` -#[macro_use] -extern crate lazy_static; #[macro_use] extern crate plugin_derive; @@ -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 { .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; } -- cgit v1.2.3-70-g09d2