diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/feature/topanime.rs | 10 | ||||
-rw-r--r-- | src/main.rs | 27 |
2 files changed, 24 insertions, 13 deletions
diff --git a/src/feature/topanime.rs b/src/feature/topanime.rs index 94edd30..7380b11 100644 --- a/src/feature/topanime.rs +++ b/src/feature/topanime.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | use std::io; | 1 | use std::io; |
2 | use std::io::prelude::*; | 2 | use std::io::prelude::*; |
3 | use std::fs::File; | 3 | use std::fs::File; |
4 | use std::usize; | ||
5 | 4 | ||
6 | extern crate telegram_bot; | 5 | extern crate telegram_bot; |
7 | use telegram_bot::{Api, Message, MessageType}; | 6 | use telegram_bot::{Api, Message, MessageType}; |
@@ -19,15 +18,6 @@ pub struct Anime { | |||
19 | score: f64, | 18 | score: f64, |
20 | } | 19 | } |
21 | 20 | ||
22 | impl Anime { | ||
23 | pub fn new(name: &str, score: f64) -> Anime { | ||
24 | Anime { | ||
25 | name: name.to_owned(), | ||
26 | score: score, | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | |||
31 | pub struct TopAnime { | 21 | pub struct TopAnime { |
32 | animes: Vec<Anime>, | 22 | animes: Vec<Anime>, |
33 | last_update: f64, | 23 | last_update: f64, |
diff --git a/src/main.rs b/src/main.rs index 0880467..5e2cd01 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | extern crate telegram_bot; | 1 | extern crate telegram_bot; |
2 | use telegram_bot::{Api, ListeningMethod, ListeningAction}; | 2 | use telegram_bot::{Api, ListeningMethod, ParseMode, MessageType, ListeningAction}; |
3 | extern crate rustc_serialize; | 3 | extern crate rustc_serialize; |
4 | use rustc_serialize::json; | 4 | use std::ascii::AsciiExt; |
5 | 5 | ||
6 | mod feature; | 6 | mod feature; |
7 | use feature::{Feature, FeatureResult}; | 7 | use feature::{Feature, FeatureResult}; |
@@ -15,8 +15,29 @@ fn main() { | |||
15 | let mut listener = api.listener(ListeningMethod::LongPoll(None)); | 15 | let mut listener = api.listener(ListeningMethod::LongPoll(None)); |
16 | let res = listener.listen(|u| { | 16 | let res = listener.listen(|u| { |
17 | if let Some(m) = u.message { | 17 | if let Some(m) = u.message { |
18 | if let &MessageType::Text(ref s) = &m.msg { | ||
19 | if (s).to_ascii_lowercase().contains("luggas zeig mir deine features") { | ||
20 | let mut msg = String::new(); | ||
21 | for f in &features { | ||
22 | msg.push_str(&format!("`{}`, ", f.name())); | ||
23 | } | ||
24 | let msg = msg; | ||
25 | let pos = msg.len() - 2; | ||
26 | let mut msg = msg; | ||
27 | msg.remove(pos); | ||
28 | if let Err(e) = api.send_message(m.chat.id(), | ||
29 | msg, | ||
30 | Some(ParseMode::Markdown), | ||
31 | None, | ||
32 | Some(m.message_id), | ||
33 | None) { | ||
34 | println!("{}", e); | ||
35 | } | ||
36 | return Ok(ListeningAction::Continue); | ||
37 | } | ||
38 | } | ||
18 | for f in &mut features { | 39 | for f in &mut features { |
19 | match (**f).handle(api.clone(), m.clone()) { | 40 | match f.handle(api.clone(), m.clone()) { |
20 | Ok(r) => { | 41 | Ok(r) => { |
21 | match r { | 42 | match r { |
22 | FeatureResult::Handled => break, | 43 | FeatureResult::Handled => break, |