extern crate telegram_bot; use telegram_bot::{Api, Message, MessageType}; use std::sync::{Arc, Mutex}; use std::thread; use std::time::Duration; use std::ascii::AsciiExt; use feature::FeatureResult; use feature::Feature; pub struct Jisoku { running: bool, } const MESSAGES: [&'static str; 5] = ["JISOKU METER FURIKIRI UBAU GAME", "I AM A CHASER DARE YORI HAYAI RACE", "LIFE IS FIRE TSUKIRU MADE HIGH PACE", "LETS GET READY TO RUMBLE MEZAMERO PASSION", "*insert dubstep*"]; impl Feature for Jisoku { fn name(&self) -> &'static str { "Jisoku Meter" } fn init(&mut self) {} fn handle(&mut self, a: Api, m: Message) -> Result { if let MessageType::Text(ref s) = m.msg { if !(&s).contains("JISOKU METER") { return Ok(FeatureResult::Skip); } } else { return Ok(FeatureResult::Skip); } if self.running { return Ok(FeatureResult::Skip); } self.running = true; thread::spawn(move || { for s in MESSAGES.into_iter() { a.send_message(m.chat.id(), (*s).to_owned(), None, None, None, None); thread::sleep(Duration::new(1, 0)); } }); Ok(FeatureResult::Handled) } } impl Jisoku { pub fn new() -> Jisoku { let mut j = Jisoku { running: false }; j } }