diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-28 08:54:19 -0500 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-28 08:54:19 -0500 |
commit | bd38d7f46a6b97b20ff5ef0c0c0c7ccd1e6b00d2 (patch) | |
tree | ebbff04e524a5ce0732ba78bdfa68962f109aa3f /src | |
parent | 9f36a68fba2d3c1e3e7052cc0a4e75f9c569adaa (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 03f9e02..4abd4b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,9 @@ #![plugin(serde_macros)] extern crate hyper; extern crate irc; +#[macro_use] +extern crate lazy_static; +extern crate rand; extern crate serde; extern crate serde_json; @@ -15,6 +18,22 @@ use hyper::header::Connection; use irc::client::prelude::*; +use rand::{thread_rng, sample}; + +lazy_static! { + static ref EMOTE_HAPPY: Vec<&'static str> = vec![":D", ":)", "^_^"]; + + static ref EMOTES: HashMap<&'static str, &'static [&'static str]> = { + let mut m = HashMap::new(); + m.insert("happy", &(*EMOTE_HAPPY)[..]); + m.insert("smile", &(*EMOTE_HAPPY)[..]); + m.insert(":)", &(*EMOTE_HAPPY)[..]); + m.insert(":D", &(*EMOTE_HAPPY)[..]); + + m + }; +} + #[derive(Debug, PartialEq, Serialize, Deserialize)] struct WikiPage { ns: u32, @@ -66,6 +85,10 @@ fn emote_action(action: &str) -> Option<&str> { if action == "shrugs" { Some("¯\\_(ツ)_/¯") } + else if let Some(x) = EMOTES.get(action) { + let mut rng = thread_rng(); + Some(sample(&mut rng, *x, 1)[0]) + } else { None } |