mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
update shared_state_bot example
This commit is contained in:
parent
980aab5fd0
commit
593dbc29f7
1 changed files with 9 additions and 10 deletions
|
@ -4,7 +4,6 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|||
|
||||
use lazy_static::lazy_static;
|
||||
use teloxide::prelude::*;
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
|
||||
lazy_static! {
|
||||
static ref MESSAGES_TOTAL: AtomicU64 = AtomicU64::new(0);
|
||||
|
@ -18,16 +17,16 @@ async fn main() {
|
|||
let bot = Bot::from_env().auto_send();
|
||||
|
||||
Dispatcher::new(bot)
|
||||
.messages_handler(|rx: DispatcherHandlerRx<AutoSend<Bot>, Message>| {
|
||||
UnboundedReceiverStream::new(rx).for_each_concurrent(None, |message| async move {
|
||||
.messages_handler(|h| {
|
||||
h.branch(dptree::endpoint(|mes: Message, bot: AutoSend<Bot>| async move {
|
||||
let previous = MESSAGES_TOTAL.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
message
|
||||
.answer(format!("I received {} messages in total.", previous))
|
||||
.await
|
||||
.log_on_error()
|
||||
.await;
|
||||
})
|
||||
bot.send_message(
|
||||
mes.chat.id,
|
||||
format!("I received {} messages in total.", previous),
|
||||
)
|
||||
.await?;
|
||||
respond(())
|
||||
}))
|
||||
})
|
||||
.dispatch()
|
||||
.await;
|
||||
|
|
Loading…
Reference in a new issue