mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-22 06:45:37 +01:00
Deprecate teloxide::handler!
in favour of dptree::case!
This commit is contained in:
parent
51d00ec351
commit
deb992c787
7 changed files with 25 additions and 46 deletions
|
@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
[Bot API 6.0]: https://core.telegram.org/bots/api#april-16-2022
|
[Bot API 6.0]: https://core.telegram.org/bots/api#april-16-2022
|
||||||
|
|
||||||
|
### Deprecated
|
||||||
|
|
||||||
|
- `teloxide::handler!` in favour of `dptree::case!`.
|
||||||
|
|
||||||
## 0.8.2 - 2022-04-26
|
## 0.8.2 - 2022-04-26
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -62,7 +62,7 @@ teloxide-macros = { version = "0.6.1", optional = true }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
||||||
dptree = "0.2.0"
|
dptree = "0.2.1"
|
||||||
|
|
||||||
tokio = { version = "1.8", features = ["fs"] }
|
tokio = { version = "1.8", features = ["fs"] }
|
||||||
tokio-util = "0.6"
|
tokio-util = "0.6"
|
||||||
|
|
10
README.md
10
README.md
|
@ -210,7 +210,6 @@ impl Default for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() {
|
async fn main() {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
log::info!("Starting dialogue_bot...");
|
log::info!("Starting dialogue_bot...");
|
||||||
|
@ -221,12 +220,11 @@ async fn main() {
|
||||||
bot,
|
bot,
|
||||||
Update::filter_message()
|
Update::filter_message()
|
||||||
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
||||||
.branch(teloxide::handler![State::Start].endpoint(start))
|
.branch(dptree::case![State::Start].endpoint(start))
|
||||||
.branch(teloxide::handler![State::ReceiveFullName].endpoint(receive_full_name))
|
.branch(dptree::case![State::ReceiveFullName].endpoint(receive_full_name))
|
||||||
.branch(teloxide::handler![State::ReceiveAge { full_name }].endpoint(receive_age))
|
.branch(dptree::case![State::ReceiveAge { full_name }].endpoint(receive_age))
|
||||||
.branch(
|
.branch(
|
||||||
teloxide::handler![State::ReceiveLocation { full_name, age }]
|
dptree::case![State::ReceiveLocation { full_name, age }].endpoint(receive_location),
|
||||||
.endpoint(receive_location),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.dependencies(dptree::deps![InMemStorage::<State>::new()])
|
.dependencies(dptree::deps![InMemStorage::<State>::new()])
|
||||||
|
|
|
@ -50,9 +50,9 @@ async fn main() {
|
||||||
|
|
||||||
let handler = Update::filter_message()
|
let handler = Update::filter_message()
|
||||||
.enter_dialogue::<Message, ErasedStorage<State>, State>()
|
.enter_dialogue::<Message, ErasedStorage<State>, State>()
|
||||||
.branch(teloxide::handler![State::Start].endpoint(start))
|
.branch(dptree::case![State::Start].endpoint(start))
|
||||||
.branch(
|
.branch(
|
||||||
teloxide::handler![State::GotNumber(n)]
|
dptree::case![State::GotNumber(n)]
|
||||||
.branch(dptree::entry().filter_command::<Command>().endpoint(got_number))
|
.branch(dptree::entry().filter_command::<Command>().endpoint(got_number))
|
||||||
.branch(dptree::endpoint(invalid_command)),
|
.branch(dptree::endpoint(invalid_command)),
|
||||||
);
|
);
|
||||||
|
|
|
@ -43,12 +43,11 @@ async fn main() {
|
||||||
bot,
|
bot,
|
||||||
Update::filter_message()
|
Update::filter_message()
|
||||||
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
||||||
.branch(teloxide::handler![State::Start].endpoint(start))
|
.branch(dptree::case![State::Start].endpoint(start))
|
||||||
.branch(teloxide::handler![State::ReceiveFullName].endpoint(receive_full_name))
|
.branch(dptree::case![State::ReceiveFullName].endpoint(receive_full_name))
|
||||||
.branch(teloxide::handler![State::ReceiveAge { full_name }].endpoint(receive_age))
|
.branch(dptree::case![State::ReceiveAge { full_name }].endpoint(receive_age))
|
||||||
.branch(
|
.branch(
|
||||||
teloxide::handler![State::ReceiveLocation { full_name, age }]
|
dptree::case![State::ReceiveLocation { full_name, age }].endpoint(receive_location),
|
||||||
.endpoint(receive_location),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.dependencies(dptree::deps![InMemStorage::<State>::new()])
|
.dependencies(dptree::deps![InMemStorage::<State>::new()])
|
||||||
|
|
|
@ -67,19 +67,19 @@ async fn main() {
|
||||||
fn schema() -> UpdateHandler<Box<dyn std::error::Error + Send + Sync + 'static>> {
|
fn schema() -> UpdateHandler<Box<dyn std::error::Error + Send + Sync + 'static>> {
|
||||||
let command_handler = teloxide::filter_command::<Command, _>()
|
let command_handler = teloxide::filter_command::<Command, _>()
|
||||||
.branch(
|
.branch(
|
||||||
teloxide::handler![State::Start]
|
dptree::case![State::Start]
|
||||||
.branch(teloxide::handler![Command::Help].endpoint(help))
|
.branch(dptree::case![Command::Help].endpoint(help))
|
||||||
.branch(teloxide::handler![Command::Start].endpoint(start)),
|
.branch(dptree::case![Command::Start].endpoint(start)),
|
||||||
)
|
)
|
||||||
.branch(teloxide::handler![Command::Cancel].endpoint(cancel));
|
.branch(dptree::case![Command::Cancel].endpoint(cancel));
|
||||||
|
|
||||||
let message_handler = Update::filter_message()
|
let message_handler = Update::filter_message()
|
||||||
.branch(command_handler)
|
.branch(command_handler)
|
||||||
.branch(teloxide::handler![State::ReceiveFullName].endpoint(receive_full_name))
|
.branch(dptree::case![State::ReceiveFullName].endpoint(receive_full_name))
|
||||||
.branch(dptree::endpoint(invalid_state));
|
.branch(dptree::endpoint(invalid_state));
|
||||||
|
|
||||||
let callback_query_handler = Update::filter_callback_query().chain(
|
let callback_query_handler = Update::filter_callback_query().chain(
|
||||||
teloxide::handler![State::ReceiveProductChoice { full_name }]
|
dptree::case![State::ReceiveProductChoice { full_name }]
|
||||||
.endpoint(receive_product_selection),
|
.endpoint(receive_product_selection),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -252,38 +252,16 @@ where
|
||||||
/// - Your dialogue state enumeration `State`.
|
/// - Your dialogue state enumeration `State`.
|
||||||
///
|
///
|
||||||
/// [`examples/purchase.rs`]: https://github.com/teloxide/teloxide/blob/master/examples/purchase.rs
|
/// [`examples/purchase.rs`]: https://github.com/teloxide/teloxide/blob/master/examples/purchase.rs
|
||||||
|
#[deprecated(note = "Use dptree::case! instead")]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! handler {
|
macro_rules! handler {
|
||||||
($($variant:ident)::+) => {
|
($($x:tt)*) => {
|
||||||
$crate::dptree::filter(|state| matches!(state, $($variant)::+))
|
$crate::dptree::case![$($x)*]
|
||||||
};
|
|
||||||
($($variant:ident)::+ ($param:ident)) => {
|
|
||||||
$crate::dptree::filter_map(|state| match state {
|
|
||||||
$($variant)::+($param) => Some($param),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
};
|
|
||||||
($($variant:ident)::+ ($($param:ident),+ $(,)?)) => {
|
|
||||||
$crate::dptree::filter_map(|state| match state {
|
|
||||||
$($variant)::+($($param),+) => Some(($($param),+ ,)),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
};
|
|
||||||
($($variant:ident)::+ {$param:ident}) => {
|
|
||||||
$crate::dptree::filter_map(|state| match state {
|
|
||||||
$($variant)::+{$param} => Some($param),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
};
|
|
||||||
($($variant:ident)::+ {$($param:ident),+ $(,)?}) => {
|
|
||||||
$crate::dptree::filter_map(|state| match state {
|
|
||||||
$($variant)::+ { $($param),+ } => Some(($($param),+ ,)),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[allow(deprecated)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue