update shared_state_bot example

This commit is contained in:
p0lunin 2022-01-06 13:59:50 +02:00
parent 980aab5fd0
commit 593dbc29f7

View file

@ -4,7 +4,6 @@ use std::sync::atomic::{AtomicU64, Ordering};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use teloxide::prelude::*; use teloxide::prelude::*;
use tokio_stream::wrappers::UnboundedReceiverStream;
lazy_static! { lazy_static! {
static ref MESSAGES_TOTAL: AtomicU64 = AtomicU64::new(0); static ref MESSAGES_TOTAL: AtomicU64 = AtomicU64::new(0);
@ -18,16 +17,16 @@ async fn main() {
let bot = Bot::from_env().auto_send(); let bot = Bot::from_env().auto_send();
Dispatcher::new(bot) Dispatcher::new(bot)
.messages_handler(|rx: DispatcherHandlerRx<AutoSend<Bot>, Message>| { .messages_handler(|h| {
UnboundedReceiverStream::new(rx).for_each_concurrent(None, |message| async move { h.branch(dptree::endpoint(|mes: Message, bot: AutoSend<Bot>| async move {
let previous = MESSAGES_TOTAL.fetch_add(1, Ordering::Relaxed); let previous = MESSAGES_TOTAL.fetch_add(1, Ordering::Relaxed);
bot.send_message(
message mes.chat.id,
.answer(format!("I received {} messages in total.", previous)) format!("I received {} messages in total.", previous),
.await )
.log_on_error() .await?;
.await; respond(())
}) }))
}) })
.dispatch() .dispatch()
.await; .await;