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 <rikingcoding@gmail.com>
This commit is contained in:
Vincent Ambo 2020-08-02 00:53:14 +01:00 committed by tazjin
parent f9840fe2d0
commit 688d4c6be3

View file

@ -22,6 +22,24 @@ mod keyword;
mod models; mod models;
mod schema; mod schema;
lazy_static! {
static ref LEARN_RE: Regex =
Regex::new(r#"^\?\?(?P<gen>!)?\s*(?P<subj>[^\[:]*):\s*(?P<val>.*)"#).unwrap();
static ref QUERY_RE: Regex =
Regex::new(r#"^\?\?\s*(?P<subj>[^\[:]*)(?P<idx>\[[^\]]+\])?"#).unwrap();
static ref QLAST_RE: Regex = Regex::new(r#"^\?\?\s*(?P<subj>[^\[:]*)!"#).unwrap();
static ref INCREMENT_RE: Regex =
Regex::new(r#"^\?\?(?P<gen>!)?\s*(?P<subj>[^\[:]*)(?P<incrdecr>\+\+|\-\-)"#)
.unwrap();
static ref MOVE_RE: Regex = Regex::new(
r#"^\?\?(?P<gen>!)?\s*(?P<subj>[^\[:]*)(?P<idx>\[[^\]]+\])->(?P<new_idx>.*)"#
).unwrap();
}
pub struct App { pub struct App {
client: IrcClient, client: IrcClient,
pg: Pool<ConnectionManager<PgConnection>>, pg: Pool<ConnectionManager<PgConnection>>,
@ -264,21 +282,6 @@ impl App {
} }
pub fn handle_privmsg(&mut self, from: &str, chan: &str, msg: &str) -> Result<(), Error> { 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<gen>!)?\s*(?P<subj>[^\[:]*):\s*(?P<val>.*)"#).unwrap();
static ref QUERY_RE: Regex =
Regex::new(r#"^\?\?\s*(?P<subj>[^\[:]*)(?P<idx>\[[^\]]+\])?"#).unwrap();
static ref QLAST_RE: Regex = Regex::new(r#"^\?\?\s*(?P<subj>[^\[:]*)!"#).unwrap();
static ref INCREMENT_RE: Regex =
Regex::new(r#"^\?\?(?P<gen>!)?\s*(?P<subj>[^\[:]*)(?P<incrdecr>\+\+|\-\-)"#)
.unwrap();
static ref MOVE_RE: Regex = Regex::new(
r#"^\?\?(?P<gen>!)?\s*(?P<subj>[^\[:]*)(?P<idx>\[[^\]]+\])->(?P<new_idx>.*)"#
)
.unwrap();
}
let nick = from.split("!").next().ok_or(format_err!( let nick = from.split("!").next().ok_or(format_err!(
"Received PRIVMSG from a source without nickname (failed to split n!u@h)" "Received PRIVMSG from a source without nickname (failed to split n!u@h)"
))?; ))?;