diff options
Diffstat (limited to 'src/feature')
-rw-r--r-- | src/feature/tasterank.rs | 17 |
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 | ||
7 | extern crate telegram_bot; | 7 | extern crate telegram_bot; |
8 | use telegram_bot::{Api, Message, MessageType}; | 8 | use telegram_bot::{Api, Message, MessageType}; |
9 | extern crate time; | ||
9 | 10 | ||
10 | use feature::FeatureResult; | 11 | use feature::FeatureResult; |
11 | use feature::Feature; | 12 | use 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) |