2020-03-04 09:15:23 +01:00
|
|
|
// This bot answers how many messages it received in total on every message.
|
|
|
|
|
|
|
|
use std::sync::atomic::{AtomicU64, Ordering};
|
|
|
|
|
2022-02-04 15:14:57 +01:00
|
|
|
use once_cell::sync::Lazy;
|
2022-01-06 13:50:59 +01:00
|
|
|
use teloxide::prelude2::*;
|
2020-03-04 09:15:23 +01:00
|
|
|
|
2022-02-04 15:14:57 +01:00
|
|
|
static MESSAGES_TOTAL: Lazy<AtomicU64> = Lazy::new(AtomicU64::default);
|
2020-03-04 09:15:23 +01:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
teloxide::enable_logging!();
|
2020-07-25 15:45:57 +02:00
|
|
|
log::info!("Starting shared_state_bot...");
|
2020-03-04 09:15:23 +01:00
|
|
|
|
2021-03-05 22:24:10 +01:00
|
|
|
let bot = Bot::from_env().auto_send();
|
2020-03-04 09:15:23 +01:00
|
|
|
|
2022-01-26 10:51:51 +01:00
|
|
|
let handler = Update::filter_message().branch(dptree::endpoint(
|
2022-02-02 10:40:22 +01:00
|
|
|
|msg: Message, bot: AutoSend<Bot>| async move {
|
2022-01-26 10:51:51 +01:00
|
|
|
let previous = MESSAGES_TOTAL.fetch_add(1, Ordering::Relaxed);
|
2022-02-02 10:40:22 +01:00
|
|
|
bot.send_message(msg.chat.id, format!("I received {} messages in total.", previous))
|
2022-01-06 12:59:50 +01:00
|
|
|
.await?;
|
2022-01-26 10:51:51 +01:00
|
|
|
respond(())
|
|
|
|
},
|
|
|
|
));
|
|
|
|
|
2022-02-04 15:09:53 +01:00
|
|
|
Dispatcher::builder(bot, handler).build().setup_ctrlc_handler().dispatch().await;
|
2020-03-04 09:15:23 +01:00
|
|
|
}
|