From 21b285dae0c2ea238c824a5ca6569fd294aea882 Mon Sep 17 00:00:00 2001 From: C J Silverio Date: Mon, 6 Jul 2020 13:52:36 -0700 Subject: [PATCH] FEAT: LOGGING VIA MACROS THAT RESPECTS RUST_LOG ALSO WE ARE NOW FUSSIER ABOUT WHAT COUNTS AS SHOUTING. SLACK USER NAMES ARE NOT SHOUTING. THREE-LETTER ACRONYMS ARE NOT SHOUTING. --- Cargo.lock | 325 +++++++++++++++++++++++++++++++++++---------- Cargo.toml | 6 +- README.md | 1 + src/bin/LOUDBOT.rs | 71 ++++++---- 4 files changed, 304 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4034baa..22a0e2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,14 +2,16 @@ # It is not intended for manual editing. [[package]] name = "LOUDCRAB" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "dotenv", + "log 0.4.8", "markov", "rand 0.7.3", "redis", "regex", + "simple_logger", "slack", ] @@ -34,12 +36,6 @@ version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9a60d744a80c30fcb657dfe2c1b22bcb3e814c1a1e3674f32bf5820b570fbff" -[[package]] -name = "ascii" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" - [[package]] name = "async-compression" version = "0.3.2" @@ -53,6 +49,57 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-std" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d68a33ebc8b57800847d00787307f84a562224a14db069b0acefe4c2abbf5d" +dependencies = [ + "async-task", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "kv-log-macro", + "log 0.4.8", + "memchr", + "num_cpus", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "smol", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17772156ef2829aadc587461c7753af20b7e8db1529bc66855add962a3b35d3" + +[[package]] +name = "async-trait" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a265e3abeffdce30b2e26b7a11b222fe37c6067404001b434101457d0385eb92" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.8", +] + [[package]] name = "autocfg" version = "1.0.0" @@ -92,6 +139,19 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "blocking" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d17efb70ce4421e351d61aafd90c16a20fb5bfe339fcdc32a86816280e62ce0" +dependencies = [ + "futures-channel", + "futures-util", + "once_cell", + "parking", + "waker-fn", +] + [[package]] name = "bumpalo" version = "3.2.1" @@ -126,6 +186,12 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" +[[package]] +name = "cache-padded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24508e28c677875c380c20f4d28124fab6f8ed4ef929a1397d7b1a31e92f1005" + [[package]] name = "cc" version = "1.0.52" @@ -138,17 +204,48 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "chrono" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6" +dependencies = [ + "num-integer", + "num-traits", + "time", +] + +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi 0.3.8", +] + [[package]] name = "combine" -version = "3.8.1" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" +checksum = "b8e5ef862b2df927249f4e2bdc29c1bd13a33105f900884b0c32acdf32aff584" dependencies = [ - "ascii", - "byteorder", - "either", + "bytes 0.5.4", + "futures-util", "memchr", - "unreachable", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "concurrent-queue" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83c06aff61f2d899eb87c379df3cbf7876f14471dcab474e0b6dc90ab96c080" +dependencies = [ + "cache-padded", ] [[package]] @@ -176,6 +273,17 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if", + "lazy_static", +] + [[package]] name = "digest" version = "0.8.1" @@ -218,6 +326,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +[[package]] +name = "fastrand" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b90eb1dec02087df472ab9f0db65f27edaa654a746830042688bcc2eaf68090f" + [[package]] name = "fixedbitset" version = "0.1.9" @@ -281,59 +395,53 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures-channel" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8" +checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" dependencies = [ "futures-core", + "futures-sink", ] [[package]] name = "futures-core" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a" - -[[package]] -name = "futures-executor" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] +checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" [[package]] name = "futures-io" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" +checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" [[package]] name = "futures-sink" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6" +checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" [[package]] name = "futures-task" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27" +checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" +dependencies = [ + "once_cell", +] [[package]] name = "futures-util" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" +checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" dependencies = [ "futures-core", "futures-io", "futures-sink", "futures-task", "memchr", + "pin-project", "pin-utils", "slab", ] @@ -383,7 +491,7 @@ dependencies = [ "log 0.4.8", "slab", "tokio", - "tokio-util 0.3.1", + "tokio-util", ] [[package]] @@ -542,6 +650,15 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log 0.4.8", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -550,9 +667,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.69" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" +checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" [[package]] name = "linked-hash-map" @@ -701,6 +818,25 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "num-integer" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.13.0" @@ -711,6 +847,12 @@ dependencies = [ "libc", ] +[[package]] +name = "once_cell" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" + [[package]] name = "opaque-debug" version = "0.2.3" @@ -756,6 +898,12 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" +[[package]] +name = "parking" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4029bc3504a62d92e42f30b9095fdef73b8a0b2a06aa41ce2935143b05a1a06" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -924,21 +1072,22 @@ dependencies = [ [[package]] name = "redis" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eeb1fe3fc011cde97315f370bc88e4db3c23b08709a04915921e02b1d363b20" +checksum = "7b94c6247d45d78d24481a5b7aca146f414ec0f5e39e175f294d1876b943eeeb" dependencies = [ + "async-std", + "async-trait", "bytes 0.5.4", "combine", "dtoa", - "futures-executor", "futures-util", "itoa", "percent-encoding", "pin-project-lite", "sha1", "tokio", - "tokio-util 0.2.0", + "tokio-util", "url", ] @@ -1027,6 +1176,12 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + [[package]] name = "security-framework" version = "0.4.3" @@ -1120,6 +1275,19 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" +[[package]] +name = "simple_logger" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0c4611f32f4c2bac73754f22dca1f57e6c1945e0590dae4e5f2a077b92367" +dependencies = [ + "atty", + "chrono", + "colored", + "log 0.4.8", + "winapi 0.3.8", +] + [[package]] name = "slab" version = "0.4.2" @@ -1159,6 +1327,39 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" +[[package]] +name = "smol" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "620cbb3c6e34da57d3a248cda0cd01cd5848164dc062e764e65d06fe3ea7aed5" +dependencies = [ + "async-task", + "blocking", + "concurrent-queue", + "fastrand", + "futures-io", + "futures-util", + "libc", + "once_cell", + "scoped-tls", + "slab", + "socket2", + "wepoll-sys-stjepang", + "winapi 0.3.8", +] + +[[package]] +name = "socket2" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi 0.3.8", +] + [[package]] name = "syn" version = "1.0.18" @@ -1233,20 +1434,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-util" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571da51182ec208780505a32528fc5512a8fe1443ab960b3f2f3ef093cd16930" -dependencies = [ - "bytes 0.5.4", - "futures-core", - "futures-sink", - "log 0.4.8", - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-util" version = "0.3.1" @@ -1338,15 +1525,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -dependencies = [ - "void", -] - [[package]] name = "url" version = "2.1.1" @@ -1377,10 +1555,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" [[package]] -name = "void" -version = "1.0.2" +name = "waker-fn" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +checksum = "9571542c2ce85ce642e6b58b3364da2fb53526360dfb7c211add4f5c23105ff7" [[package]] name = "want" @@ -1476,6 +1654,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wepoll-sys-stjepang" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fd319e971980166b53e17b1026812ad66c6b54063be879eb182342b55284694" +dependencies = [ + "cc", +] + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 6120ca5..717f300 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,13 +2,15 @@ authors = ["C J Silverio "] edition = "2018" name = "LOUDCRAB" -version = "0.2.0" +version = "0.2.1" [dependencies] anyhow = "1" dotenv = "0.15.0" +log = "*" markov = "*" rand = "0.7.3" -redis = "0.15.1" +redis = "0.16.0" regex = "1" +simple_logger = "1" slack = "0.23.0" diff --git a/README.md b/README.md index d9965c0..1a4ac68 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Config vars: - `REDIS_URL`: A URI giving the host:port of your redis. Defaults to `redis://localhost:6379` - `WELCOME_CHANNEL`: The human name of the channel LOUDBOT should toast in when it starts up. Optional. - `TUCKER_CHANCE`: The percentage chance Malcolm Tucker will be invoked if you swear. Malcolm only appears if certain four-letter words are used, so there is zero chance of sweary gifs in your Slack if you yourselves do not swear. +- `RUST_LOG`: One of `trace`, `debug`, `info`, `warn`, following [env_logger](https://lib.rs/crates/env_logger) convention. ## RUNNING diff --git a/src/bin/LOUDBOT.rs b/src/bin/LOUDBOT.rs index bdc8b40..a88143e 100644 --- a/src/bin/LOUDBOT.rs +++ b/src/bin/LOUDBOT.rs @@ -1,17 +1,21 @@ #![allow(non_snake_case)] use anyhow::{Context, Result}; use dotenv::dotenv; +use log::{debug, info, warn}; use markov::Chain; use rand::prelude::*; use rand::thread_rng; use rand::distributions::{DistIter, Uniform}; use redis::Commands; -use regex::Regex; +use regex::{ Regex, RegexSet }; +use simple_logger; use slack::{ api, Error, Event, Message, RtmClient }; use std::env; use std::convert::AsRef; type RString = std::result::Result; +// This pattern depends on the order of the chunks. +const IGNORE: &str = r"<@\w+>|[\W\d[[:punct:]]]|s+"; // This holds everything we want to allocate once at startup, because // what's the point of writing in Rust if we don't eke out RAW PERF? @@ -26,14 +30,15 @@ struct Loudbot { shipkey : String, swkey : String, yellkey : String, - cat : regex::Regex, - fuckity : regex::Regex, - intro : regex::Regex, - malc : regex::Regex, - report : regex::Regex, - ship : regex::Regex, - sw : regex::Regex, - swears : regex::RegexSet, + cat : Regex, + fuckity : Regex, + intro : Regex, + malc : Regex, + report : Regex, + ship : Regex, + ignore : Regex, + sw : Regex, + swears : RegexSet, } impl slack::EventHandler for Loudbot { @@ -42,17 +47,17 @@ impl slack::EventHandler for Loudbot { Event::Hello => self.maybe_toast(cli), Event::Message(ref m) => self.handle_message(cli, m), Event::MessageSent(_) => {}, - _ => {}, // println!("on_event(event: {:?})", event), + _ => debug!("on_event(event: {:?})", event), }; } fn on_close(&mut self, _cli: &RtmClient) { - println!("on_close; loudie has no idea what to do here yet"); + warn!("on_close; loudie has no idea what to do here yet"); // TODO reconnect } fn on_connect(&mut self, _cli: &RtmClient) { - println!("THIS BATTLESTATION WILL BE FULLY OPERATIONAL SHORTLY"); + info!("THIS BATTLESTATION WILL BE FULLY OPERATIONAL SHORTLY"); } } @@ -69,14 +74,14 @@ impl Loudbot { Ok(iter) => { iter.for_each(|token: String| { chain.feed_str(&token); }); } - } + }; let malc_chance: u8 = match env::var("TUCKER_CHANCE") { Ok(v) => { match v.parse::() { Ok(x) => std::cmp::min(x, 100), Err(e) => { - println!("Failed to parse TUCKER_CHANCE as u8; falling back to 2%; {:?}", e); + warn!("Failed to parse TUCKER_CHANCE as u8; falling back to 2%; {:?}", e); 2 }, } @@ -101,7 +106,8 @@ impl Loudbot { malc : Regex::new("(?i)MALCOLM +TUCKER").unwrap(), report : Regex::new("(?i)LOUDBOT +REPORT").unwrap(), ship : Regex::new("(?i)SHIP ?NAME").unwrap(), - sw : Regex::new("(?i)(LUKE|LEIA|LIGHTSABER|ENDOR|MILLENIUM +FALCON|DARTH|VADER|HAN +SOLO|OBIWAN|OBI-WAN|KENOBI|CHEWIE|CHEWBACCA|TATOOINE|STAR +WAR|DEATH +STAR)").unwrap(), + ignore : Regex::new(IGNORE).unwrap(), + sw : Regex::new("(?i)(LUKE|LEIA|SKYWALKER|ORGANA|TARKIN|LIGHTSABER|ENDOR|MILLENIUM +FALCON|DARTH|VADER|HAN +SOLO|OBIWAN|OBI-WAN|KENOBI|CHEWIE|CHEWBACCA|TATOOINE|STAR +WAR|DEATH +STAR)").unwrap(), swears : regex::RegexSet::new(&[ r"(?i).*FUCK.*", r"(?i)(^|\W)CUNT(\W|$)", @@ -157,7 +163,7 @@ impl Loudbot { let retort: RString = self.db.srandmember(key); match retort { Err(e) => { - println!("Failed to get a random set member from redis: {:?}", e); + warn!("Failed to get a random set member from redis: {:?}", e); None }, Ok(retort) => Some(retort), @@ -191,7 +197,7 @@ impl Loudbot { Some("https://cldup.com/NtvUeudPtg.gif".to_string()) } else if self.swears.is_match(text) && self.roll_the_dice() <= self.malc_chance { self.lookup(self.malckey.clone()) - } else if is_loud(text) { + } else if is_loud(&self.ignore, text) { // This case has to be last. self.remember(prompt.text.as_ref().unwrap()); if self.roll_the_dice() > 98 { @@ -221,7 +227,7 @@ impl Loudbot { fn yell(&mut self, cli: &RtmClient, prompt: &api::MessageStandard, retort: &str) { let channel = prompt.channel.as_ref().unwrap(); - println!("yelling: {}", retort); + info!("yelling: `{}`; prompt: `{}`", retort, prompt.text.as_ref().unwrap()); match send_message(cli, &channel, &retort, prompt.thread_ts.as_ref()) { Ok(_) => { }, @@ -231,10 +237,9 @@ impl Loudbot { } } -fn is_loud(text: &str) -> bool { - let punc = Regex::new(r"[\W\d[[:punct:]]]").unwrap(); - let result = punc.replace_all(text, ""); - if result.len() < 3 { +fn is_loud(pattern: &Regex, text: &str) -> bool { + let result = pattern.replace_all(text, ""); + if result.trim().len() < 4 { return false } result.to_uppercase() == result @@ -260,6 +265,8 @@ pub fn send_message(cli: &RtmClient, channel_id: &str, text: &str, maybe_ts: Opt fn main() -> Result<()> { dotenv().ok(); + simple_logger::init_by_env(); + let slack_token = env::var("SLACK_TOKEN") .with_context(|| "You must provide a valid slack api token in the env var SLACK_TOKEN.")?; @@ -271,6 +278,7 @@ fn main() -> Result<()> { .with_context(|| format!("Unable to create redis client @ {}", redis_uri))?; let rcon = client.get_connection() .with_context(|| format!("Unable to connect to redis @ {}", redis_uri))?; + info!("Memory @ {}", redis_uri); let mut loudie = Loudbot::new(rcon); match RtmClient::login_and_run(&slack_token, &mut loudie) { @@ -287,11 +295,18 @@ mod tests { #[test] fn is_loud_works() { - assert!(is_loud("THIS IS LOUD")); - assert!(!is_loud("This is not loud")); - assert!(is_loud("THIS IS LOUD.")); - assert!(!is_loud("12345")); - assert!(!is_loud("800-555-1212")); - assert!(!is_loud("FU!!!!!")); + let patt = Regex::new(IGNORE).unwrap(); + + assert!(is_loud(&patt, "THIS IS LOUD")); + assert!(!is_loud(&patt, "This is not loud")); + assert!(is_loud(&patt, "THIS IS LOUD.")); + assert!(!is_loud(&patt, "12345")); + assert!(!is_loud(&patt, "800-555-1212")); + assert!(!is_loud(&patt, "FU!!!!!")); + assert!(!is_loud(&patt, "<@U123>")); + assert!(!is_loud(&patt, "ABC")); + assert!(is_loud(&patt, "YOU ARE EXTREMELY SILLY <@U123> OH YEAH")); + assert!(!is_loud(&patt, "1234-1249384 <@U123> 912302")); + assert!(!is_loud(&patt, "<@U123> ABC")); } }