diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 4cca6d1..eaec1f4 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,18 +1,31 @@ | |||
1 | extern crate telegram_bot; | 1 | extern crate telegram_bot; |
2 | use telegram_bot::{Api, ListeningMethod, ListeningAction, Update}; | ||
2 | 3 | ||
3 | use telegram_bot::{Api, ListeningMethod, ListeningAction, MessageType, Update}; | 4 | mod feature; |
5 | use feature::{Feature, FeatureResult}; | ||
4 | 6 | ||
5 | fn main() { | 7 | fn main() { |
6 | let api = Api::from_env("TELEGRAM_BOT_TOKEN").unwrap(); | 8 | let api = Api::from_env("TELEGRAM_BOT_TOKEN").unwrap(); |
7 | 9 | ||
8 | println!("api started: {:?}", api.get_me()); | 10 | println!("api started: {:?}", api.get_me()); |
11 | let mut features = feature::init(); | ||
9 | 12 | ||
10 | let mut listener = api.listener(ListeningMethod::LongPoll(None)); | 13 | let mut listener = api.listener(ListeningMethod::LongPoll(None)); |
11 | let res = listener.listen(|u| { | 14 | let res = listener.listen(|u| { |
12 | if let Some(m) = u.message { | 15 | if let Some(m) = u.message { |
13 | let name = m.from.first_name; | 16 | for f in &mut features { |
14 | 17 | match (**f).handle(api.clone(), m.clone()) { | |
15 | println!("got message from {}", name); | 18 | Ok(r) => { |
19 | match r { | ||
20 | FeatureResult::Handled => break, | ||
21 | FeatureResult::Skip => continue, | ||
22 | }; | ||
23 | } | ||
24 | Err(e) => { | ||
25 | println!("Error in feature {}: {}", f.name(), e); | ||
26 | } | ||
27 | }; | ||
28 | } | ||
16 | }; | 29 | }; |
17 | Ok(ListeningAction::Continue) | 30 | Ok(ListeningAction::Continue) |
18 | }); | 31 | }); |