From 688d4c6be3847e1aa5f9d946cb69a3ac2332e961 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 2 Aug 2020 00:53:14 +0100 Subject: [PATCH] refactor(paroxysm): Move lazy_static regex definitions to the top Change-Id: If04cc7ee72230f6b5163d33ef683bcb90bd9bc26 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1554 Tested-by: BuildkiteCI Reviewed-by: kanepyork --- fun/paroxysm/src/main.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/fun/paroxysm/src/main.rs b/fun/paroxysm/src/main.rs index a5382e9c0..081f273ba 100644 --- a/fun/paroxysm/src/main.rs +++ b/fun/paroxysm/src/main.rs @@ -22,6 +22,24 @@ mod keyword; mod models; mod schema; +lazy_static! { + static ref LEARN_RE: Regex = + Regex::new(r#"^\?\?(?P!)?\s*(?P[^\[:]*):\s*(?P.*)"#).unwrap(); + + static ref QUERY_RE: Regex = + Regex::new(r#"^\?\?\s*(?P[^\[:]*)(?P\[[^\]]+\])?"#).unwrap(); + + static ref QLAST_RE: Regex = Regex::new(r#"^\?\?\s*(?P[^\[:]*)!"#).unwrap(); + + static ref INCREMENT_RE: Regex = + Regex::new(r#"^\?\?(?P!)?\s*(?P[^\[:]*)(?P\+\+|\-\-)"#) + .unwrap(); + + static ref MOVE_RE: Regex = Regex::new( + r#"^\?\?(?P!)?\s*(?P[^\[:]*)(?P\[[^\]]+\])->(?P.*)"# + ).unwrap(); +} + pub struct App { client: IrcClient, pg: Pool>, @@ -264,21 +282,6 @@ impl App { } pub fn handle_privmsg(&mut self, from: &str, chan: &str, msg: &str) -> Result<(), Error> { - // TODO(tazjin): Move these to the top. - lazy_static! { - static ref LEARN_RE: Regex = - Regex::new(r#"^\?\?(?P!)?\s*(?P[^\[:]*):\s*(?P.*)"#).unwrap(); - static ref QUERY_RE: Regex = - Regex::new(r#"^\?\?\s*(?P[^\[:]*)(?P\[[^\]]+\])?"#).unwrap(); - static ref QLAST_RE: Regex = Regex::new(r#"^\?\?\s*(?P[^\[:]*)!"#).unwrap(); - static ref INCREMENT_RE: Regex = - Regex::new(r#"^\?\?(?P!)?\s*(?P[^\[:]*)(?P\+\+|\-\-)"#) - .unwrap(); - static ref MOVE_RE: Regex = Regex::new( - r#"^\?\?(?P!)?\s*(?P[^\[:]*)(?P\[[^\]]+\])->(?P.*)"# - ) - .unwrap(); - } let nick = from.split("!").next().ok_or(format_err!( "Received PRIVMSG from a source without nickname (failed to split n!u@h)" ))?;