diff options
author | jan <jan@ruken.pw> | 2016-04-06 17:54:12 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-04-06 17:54:12 (UTC) |
commit | 314047dda73387fff1fd4ccdb35f5db6ea6d7d5a (patch) | |
tree | f6b0d4c52db0a93c9afa9989b4624f23193b3a28 /src/feature/jisoku.rs | |
parent | ac1f32f068a8c1e856b6db00a8058d9bf372a006 (diff) |
FEATURES!
Diffstat (limited to 'src/feature/jisoku.rs')
-rw-r--r-- | src/feature/jisoku.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/feature/jisoku.rs b/src/feature/jisoku.rs new file mode 100644 index 0000000..70bc886 --- /dev/null +++ b/src/feature/jisoku.rs | |||
@@ -0,0 +1,55 @@ | |||
1 | extern crate telegram_bot; | ||
2 | use telegram_bot::{Api, Message, MessageType}; | ||
3 | use std::sync::{Arc, Mutex}; | ||
4 | use std::thread; | ||
5 | use std::time::Duration; | ||
6 | |||
7 | use std::ascii::AsciiExt; | ||
8 | |||
9 | use feature::FeatureResult; | ||
10 | use feature::Feature; | ||
11 | |||
12 | pub struct Jisoku { | ||
13 | running: bool, | ||
14 | } | ||
15 | |||
16 | const MESSAGES: [&'static str; 5] = ["JISOKU METER FURIKIRI UBAU GAME", | ||
17 | "I AM A CHASER DARE YORI HAYAI RACE", | ||
18 | "LIFE IS FIRE TSUKIRU MADE HIGH PACE", | ||
19 | "LETS GET READY TO RUMBLE MEZAMERO PASSION", | ||
20 | "*insert dubstep*"]; | ||
21 | |||
22 | impl Feature for Jisoku { | ||
23 | fn name(&self) -> &'static str { | ||
24 | "Jisoku Meter" | ||
25 | } | ||
26 | fn init(&mut self) {} | ||
27 | fn handle(&mut self, a: Api, m: Message) -> Result<FeatureResult, String> { | ||
28 | if let MessageType::Text(ref s) = m.msg { | ||
29 | if !(&s).contains("JISOKU METER") { | ||
30 | return Ok(FeatureResult::Skip); | ||
31 | } | ||
32 | } else { | ||
33 | return Ok(FeatureResult::Skip); | ||
34 | } | ||
35 | |||
36 | if self.running { | ||
37 | return Ok(FeatureResult::Skip); | ||
38 | } | ||
39 | self.running = true; | ||
40 | thread::spawn(move || { | ||
41 | for s in MESSAGES.into_iter() { | ||
42 | a.send_message(m.chat.id(), (*s).to_owned(), None, None, None, None); | ||
43 | thread::sleep(Duration::new(1, 0)); | ||
44 | } | ||
45 | }); | ||
46 | Ok(FeatureResult::Handled) | ||
47 | } | ||
48 | } | ||
49 | |||
50 | impl Jisoku { | ||
51 | pub fn new() -> Jisoku { | ||
52 | let mut j = Jisoku { running: false }; | ||
53 | j | ||
54 | } | ||
55 | } | ||