Update dptree

This commit is contained in:
Hirrolot 2022-02-05 00:02:22 +06:00
parent bd73d79e80
commit 67901fa53b
4 changed files with 8 additions and 8 deletions

View file

@ -58,12 +58,12 @@ full = [
[dependencies]
teloxide-core = { version = "0.4", default-features = false }
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros.git", branch = "dispatching2", optional = true }
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros.git", rev = "57d3e266fa25a6ee2ccbfe140016cdb5d3223147", optional = true }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
dptree = { git = "https://github.com/p0lunin/dptree", optional = true }
dptree = { git = "https://github.com/p0lunin/dptree", rev = "9abc500782e55ed18909e223551f3b6998c9e1f4", optional = true }
tokio = { version = "1.8", features = ["fs"] }
tokio-util = "0.6"

View file

@ -25,7 +25,7 @@ async fn main() {
// Filter allow you to filter updates by some condition.
dptree::filter(
// Note that `async move` is obligatory.
|msg: Message| async move { msg.chat.is_group() || msg.chat.is_supergroup() },
|msg: Message| msg.chat.is_group() || msg.chat.is_supergroup(),
)
// Endpoint is a last message handler.
.endpoint(|msg: Message, bot: AutoSend<Bot>| async move {
@ -60,7 +60,7 @@ async fn main() {
)
.branch(
// Filter maintainer by used ID.
dptree::filter(|msg: Message, cfg: ConfigParameters| async move {
dptree::filter(|msg: Message, cfg: ConfigParameters| {
msg.from().map(|user| user.id == cfg.bot_maintainer).unwrap_or_default()
})
.filter_command::<MaintainerCommands>()

View file

@ -26,7 +26,7 @@ macro_rules! define_ext {
(@impl $for_ty:ty, $func:ident, $proj_fn:expr) => {
fn $func() -> Handler<'static, DependencyMap, Out> {
dptree::filter_map(move |input: $for_ty| {
async move { $proj_fn(input) }
$proj_fn(input)
})
}
};

View file

@ -47,7 +47,7 @@ where
{
self.chain(dptree::filter_map(move |message: Message, me: Me| {
let bot_name = me.user.username.expect("Bots must have a username");
async move { message.text().and_then(|text| C::parse(text, bot_name).ok()) }
message.text().and_then(|text| C::parse(text, bot_name).ok())
}))
}
@ -58,11 +58,11 @@ where
D: Default + Send + Sync + 'static,
Upd: GetChatId + Clone + Send + Sync + 'static,
{
self.chain(dptree::filter_map(|storage: Arc<S>, upd: Upd| async move {
self.chain(dptree::filter_map(|storage: Arc<S>, upd: Upd| {
let chat_id = upd.chat_id()?;
Some(Dialogue::new(storage, chat_id))
}))
.chain(dptree::filter_map(|dialogue: Dialogue<D, S>| async move {
.chain(dptree::filter_map_async(|dialogue: Dialogue<D, S>| async move {
dialogue.get_or_default().await.ok()
}))
}