rust_tg_bot_ext/handlers/
poll_answer.rs1use std::future::Future;
7use std::pin::Pin;
8use std::sync::Arc;
9
10use rust_tg_bot_raw::types::update::Update;
11
12use super::base::{Handler, HandlerCallback, HandlerResult, MatchResult};
13
14pub struct PollAnswerHandler {
18 callback: HandlerCallback,
19 block: bool,
20}
21
22impl PollAnswerHandler {
23 pub fn new(callback: HandlerCallback, block: bool) -> Self {
25 Self { callback, block }
26 }
27}
28
29impl Handler for PollAnswerHandler {
30 fn check_update(&self, update: &Update) -> Option<MatchResult> {
31 if update.poll_answer().is_some() {
32 Some(MatchResult::Empty)
33 } else {
34 None
35 }
36 }
37
38 fn handle_update(
39 &self,
40 update: Arc<Update>,
41 match_result: MatchResult,
42 ) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>> {
43 (self.callback)(update, match_result)
44 }
45
46 fn block(&self) -> bool {
47 self.block
48 }
49}