Refactor dptree usage

Former-commit-id: fe3aa2e798
This commit is contained in:
Hirrolot 2022-10-07 10:14:36 +06:00
parent 760f843010
commit 744679419a
2 changed files with 14 additions and 15 deletions

View file

@ -220,12 +220,11 @@ where
Upd: GetChatId + Clone + Send + Sync + 'static, Upd: GetChatId + Clone + Send + Sync + 'static,
Output: Send + Sync + 'static, Output: Send + Sync + 'static,
{ {
dptree::entry() dptree::filter_map(|storage: Arc<S>, upd: Upd| {
.chain(dptree::filter_map(|storage: Arc<S>, upd: Upd| {
let chat_id = upd.chat_id()?; let chat_id = upd.chat_id()?;
Some(Dialogue::new(storage, chat_id)) Some(Dialogue::new(storage, chat_id))
})) })
.chain(dptree::filter_map_async(|dialogue: Dialogue<D, S>| async move { .filter_map_async(|dialogue: Dialogue<D, S>| async move {
match dialogue.get_or_default().await { match dialogue.get_or_default().await {
Ok(dialogue) => Some(dialogue), Ok(dialogue) => Some(dialogue),
Err(err) => { Err(err) => {
@ -233,5 +232,5 @@ where
None None
} }
} }
})) })
} }

View file

@ -88,8 +88,8 @@ where
C: BotCommands + Send + Sync + 'static, C: BotCommands + Send + Sync + 'static,
Output: Send + Sync + 'static, Output: Send + Sync + 'static,
{ {
dptree::entry().chain(dptree::filter_map(move |message: Message, me: Me| { dptree::filter_map(move |message: Message, me: Me| {
let bot_name = me.user.username.expect("Bots must have a username"); let bot_name = me.user.username.expect("Bots must have a username");
message.text().and_then(|text| C::parse(text, &bot_name).ok()) message.text().and_then(|text| C::parse(text, &bot_name).ok())
})) })
} }