From bd38d7f46a6b97b20ff5ef0c0c0c7ccd1e6b00d2 Mon Sep 17 00:00:00 2001
From: David Li
Date: Thu, 28 Jan 2016 08:54:19 -0500
Subject: feat(emote): randomly choose appropriate emote
---
src/main.rs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'src')
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
}
--
cgit v1.2.3