From 5fe11c7ffa1227f10139836a9c755a63dacc6916 Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 7 Apr 2016 19:05:24 +0200 Subject: features anzeigen fuer luggas. irgendwas gefixt. 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 @@ use std::io; use std::io::prelude::*; use std::fs::File; -use std::usize; extern crate telegram_bot; use telegram_bot::{Api, Message, MessageType}; @@ -19,15 +18,6 @@ pub struct Anime { score: f64, } -impl Anime { - pub fn new(name: &str, score: f64) -> Anime { - Anime { - name: name.to_owned(), - score: score, - } - } -} - pub struct TopAnime { animes: Vec, 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 @@ extern crate telegram_bot; -use telegram_bot::{Api, ListeningMethod, ListeningAction}; +use telegram_bot::{Api, ListeningMethod, ParseMode, MessageType, ListeningAction}; extern crate rustc_serialize; -use rustc_serialize::json; +use std::ascii::AsciiExt; mod feature; use feature::{Feature, FeatureResult}; @@ -15,8 +15,29 @@ fn main() { let mut listener = api.listener(ListeningMethod::LongPoll(None)); let res = listener.listen(|u| { if let Some(m) = u.message { + if let &MessageType::Text(ref s) = &m.msg { + if (s).to_ascii_lowercase().contains("luggas zeig mir deine features") { + let mut msg = String::new(); + for f in &features { + msg.push_str(&format!("`{}`, ", f.name())); + } + let msg = msg; + let pos = msg.len() - 2; + let mut msg = msg; + msg.remove(pos); + if let Err(e) = api.send_message(m.chat.id(), + msg, + Some(ParseMode::Markdown), + None, + Some(m.message_id), + None) { + println!("{}", e); + } + return Ok(ListeningAction::Continue); + } + } for f in &mut features { - match (**f).handle(api.clone(), m.clone()) { + match f.handle(api.clone(), m.clone()) { Ok(r) => { match r { FeatureResult::Handled => break, -- cgit v0.10.1