aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/feature/topanime.rs10
-rw-r--r--src/main.rs27
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 @@
1use std::io; 1use std::io;
2use std::io::prelude::*; 2use std::io::prelude::*;
3use std::fs::File; 3use std::fs::File;
4use std::usize;
5 4
6extern crate telegram_bot; 5extern crate telegram_bot;
7use telegram_bot::{Api, Message, MessageType}; 6use telegram_bot::{Api, Message, MessageType};
@@ -19,15 +18,6 @@ pub struct Anime {
19 score: f64, 18 score: f64,
20} 19}
21 20
22impl Anime {
23 pub fn new(name: &str, score: f64) -> Anime {
24 Anime {
25 name: name.to_owned(),
26 score: score,
27 }
28 }
29}
30
31pub struct TopAnime { 21pub 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 @@
1extern crate telegram_bot; 1extern crate telegram_bot;
2use telegram_bot::{Api, ListeningMethod, ListeningAction}; 2use telegram_bot::{Api, ListeningMethod, ParseMode, MessageType, ListeningAction};
3extern crate rustc_serialize; 3extern crate rustc_serialize;
4use rustc_serialize::json; 4use std::ascii::AsciiExt;
5 5
6mod feature; 6mod feature;
7use feature::{Feature, FeatureResult}; 7use 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,