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 | |
parent | 9f36a68fba2d3c1e3e7052cc0a4e75f9c569adaa (diff) |
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/main.rs | 23 |
3 files changed, 27 insertions, 0 deletions
@@ -4,6 +4,8 @@ version = "0.1.0" dependencies = [ "hyper 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "irc 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6,6 +6,8 @@ authors = ["David Li <li.davidm96@gmail.com>"] [dependencies] hyper = "0.7.2" irc = "0.9.2" +lazy_static = "0.1.*" +rand = "0.3" serde = "*" serde_json = "*" serde_macros = "*" 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 } |