mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-21 14:29:01 +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 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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue