-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpolls.rs
More file actions
83 lines (71 loc) · 2.26 KB
/
Copy pathpolls.rs
File metadata and controls
83 lines (71 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use tbot::{
prelude::*,
types::parameters::poll::{self, Answer, AutoClose, Poll, Quiz},
Bot,
};
#[tokio::main]
async fn main() {
let mut bot = Bot::from_env("BOT_TOKEN").event_loop();
bot.command("poll", |context| async move {
let regular = poll::Any::new(
"Do you like tbot?",
[
"Yes".to_owned(),
"Also yes".to_owned(),
"I like shooting myself in the foot more".to_owned(),
],
Poll::new(Answer::Single),
)
.auto_close(AutoClose::OpenPeriod(60));
let call_result = context.send_poll(regular).call().await;
if let Err(err) = call_result {
dbg!(err);
}
});
bot.command("quiz", |context| async move {
let quiz = poll::Any::new(
"The best Telegram bot library is...",
[
"aiogram".to_owned(),
"tbot".to_owned(),
"python-telegram-bot".to_owned(),
],
Quiz::new(1).explanation(
"Why would you want to use something else than tbot for \
writing bots?",
),
)
.is_anonymous(false);
let call_result = context.send_poll(quiz).call().await;
if let Err(err) = call_result {
dbg!(err);
}
});
bot.command("close", |context| async move {
let err = if let Some(message) = &context.reply_to {
let chat_id = context.chat.id;
let call_result =
context.bot.stop_poll(chat_id, message.id).call().await;
call_result.err()
} else {
context
.send_message("Please send the command in reply to a poll")
.call()
.await
.err()
};
if let Some(err) = err {
dbg!(err);
}
});
bot.poll(|context| async move {
println!("Someone sent a poll: {:#?}", context.poll);
});
bot.updated_poll(|context| async move {
println!("New update on my poll: {:#?}", context.poll);
});
bot.poll_answer(|context| async move {
println!("New answer in my poll: {:#?}", context.answer);
});
bot.polling().start().await.unwrap();
}