mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Update dptree
This commit is contained in:
parent
56f8ef90ec
commit
eb8b384f46
2 changed files with 43 additions and 26 deletions
|
@ -64,7 +64,8 @@ teloxide-macros = { version = "0.6.2", optional = true }
|
|||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
dptree = "0.2.1"
|
||||
#dptree = "0.2.1"
|
||||
dptree = { git = "https://github.com/teloxide/dptree.git", rev = "df578e4" }
|
||||
|
||||
tokio = { version = "1.8", features = ["fs"] }
|
||||
tokio-util = "0.6"
|
||||
|
|
|
@ -1,44 +1,27 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use dptree::{description::EventKind, HandlerDescription};
|
||||
use dptree::{
|
||||
description::{EventKind, InterestSet},
|
||||
HandlerDescription,
|
||||
};
|
||||
use teloxide_core::types::AllowedUpdate;
|
||||
|
||||
/// Handler description that is used by [`Dispatcher`].
|
||||
///
|
||||
/// [`Dispatcher`]: crate::dispatching::Dispatcher
|
||||
pub struct DpHandlerDescription {
|
||||
allowed: EventKind<AllowedUpdate>,
|
||||
allowed: InterestSet<Kind>,
|
||||
}
|
||||
|
||||
impl DpHandlerDescription {
|
||||
pub(crate) fn of(allowed: AllowedUpdate) -> Self {
|
||||
let mut set = HashSet::with_capacity(1);
|
||||
set.insert(allowed);
|
||||
Self { allowed: EventKind::InterestList(set) }
|
||||
set.insert(Kind(allowed));
|
||||
Self { allowed: InterestSet::new_filter(set) }
|
||||
}
|
||||
|
||||
pub(crate) fn allowed_updates(&self) -> Vec<AllowedUpdate> {
|
||||
use AllowedUpdate::*;
|
||||
|
||||
match &self.allowed {
|
||||
EventKind::InterestList(set) => set.iter().copied().collect(),
|
||||
EventKind::Entry => panic!("No updates were allowed"),
|
||||
EventKind::UserDefined => vec![
|
||||
Message,
|
||||
EditedMessage,
|
||||
ChannelPost,
|
||||
EditedChannelPost,
|
||||
InlineQuery,
|
||||
ChosenInlineResult,
|
||||
CallbackQuery,
|
||||
ShippingQuery,
|
||||
PreCheckoutQuery,
|
||||
Poll,
|
||||
PollAnswer,
|
||||
MyChatMember,
|
||||
ChatMember,
|
||||
],
|
||||
}
|
||||
self.allowed.observed.iter().map(|Kind(x)| x).copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,6 +42,39 @@ impl HandlerDescription for DpHandlerDescription {
|
|||
Self { allowed: self.allowed.merge_branch(&other.allowed) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||
struct Kind(AllowedUpdate);
|
||||
|
||||
impl EventKind for Kind {
|
||||
fn full_set() -> HashSet<Self> {
|
||||
use AllowedUpdate::*;
|
||||
|
||||
[
|
||||
Message,
|
||||
EditedMessage,
|
||||
ChannelPost,
|
||||
EditedChannelPost,
|
||||
InlineQuery,
|
||||
ChosenInlineResult,
|
||||
CallbackQuery,
|
||||
ShippingQuery,
|
||||
PreCheckoutQuery,
|
||||
Poll,
|
||||
PollAnswer,
|
||||
MyChatMember,
|
||||
ChatMember,
|
||||
]
|
||||
.into_iter()
|
||||
.map(Kind)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn empty_set() -> HashSet<Self> {
|
||||
HashSet::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
|
|
Loading…
Reference in a new issue