aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-04-07 12:55:22 (UTC)
committerjan <jan@ruken.pw>2016-04-07 12:55:22 (UTC)
commit63e7f23364eef1eadeab49f3feab6480f77e1398 (patch)
tree4ea06436706f99f22d8109d5b0d2042de5d414f0 /src
parent0720a83bcdc22684c68759755afb007579e0ebcc (diff)
bb, Cargo.lock. Tasterank jetzt immer brandaktuell.
Diffstat (limited to 'src')
-rw-r--r--src/feature/tasterank.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/feature/tasterank.rs b/src/feature/tasterank.rs
index 13730e1..20146df 100644
--- a/src/feature/tasterank.rs
+++ b/src/feature/tasterank.rs
@@ -6,6 +6,7 @@ use std::ascii::AsciiExt;
6 6
7extern crate telegram_bot; 7extern crate telegram_bot;
8use telegram_bot::{Api, Message, MessageType}; 8use telegram_bot::{Api, Message, MessageType};
9extern crate time;
9 10
10use feature::FeatureResult; 11use feature::FeatureResult;
11use feature::Feature; 12use feature::Feature;
@@ -18,16 +19,20 @@ impl Feature for Tasterank {
18 fn name(&self) -> &'static str { 19 fn name(&self) -> &'static str {
19 "Tasterank" 20 "Tasterank"
20 } 21 }
21 fn init(&mut self) { 22 fn init(&mut self) {}
22 if let Err(e) = self.update_ranks() {
23 panic!(e);
24 }
25 }
26 fn handle(&mut self, a: Api, m: Message) -> Result<FeatureResult, String> { 23 fn handle(&mut self, a: Api, m: Message) -> Result<FeatureResult, String> {
27 if let MessageType::Text(s) = m.msg { 24 if let MessageType::Text(s) = m.msg {
28 if !(&s).to_ascii_lowercase().contains("luggas tasterank") { 25 if !(&s).to_ascii_lowercase().contains("luggas tasterank") {
29 return Ok(FeatureResult::Skip); 26 return Ok(FeatureResult::Skip);
30 } 27 }
28 let start = time::precise_time_ns();
29 if let Err(e) = self.update_ranks() {
30 println!("{}", e);
31 return Ok(FeatureResult::Skip);
32 }
33 println!("(benchm) updating ranks: {}ms",
34 (time::precise_time_ns() - start) / 1000000);
35
31 let mut msg = String::new(); 36 let mut msg = String::new();
32 for (i, rank) in self.ranks.iter().enumerate() { 37 for (i, rank) in self.ranks.iter().enumerate() {
33 msg.push_str(&format!("{}. {}\n", i + 1, rank)); 38 msg.push_str(&format!("{}. {}\n", i + 1, rank));
@@ -35,6 +40,8 @@ impl Feature for Tasterank {
35 if let Err(e) = a.send_message(m.chat.id(), msg, None, None, Some(m.message_id), None) { 40 if let Err(e) = a.send_message(m.chat.id(), msg, None, None, Some(m.message_id), None) {
36 println!("{}", e); 41 println!("{}", e);
37 } 42 }
43 println!("(benchm) tasterank: {}ms",
44 (time::precise_time_ns() - start) / 1000000);
38 return Ok(FeatureResult::Handled); 45 return Ok(FeatureResult::Handled);
39 } 46 }
40 Ok(FeatureResult::Skip) 47 Ok(FeatureResult::Skip)