diff --git a/CHANGELOG.md b/CHANGELOG.md index bf81ebdf..65a8ace9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 +### Deprecated + + - `teloxide::handler!` in favour of `dptree::case!`. + ## 0.8.2 - 2022-04-26 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index f39c2907..7afb0612 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ teloxide-macros = { version = "0.6.1", optional = true } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -dptree = "0.2.0" +dptree = "0.2.1" tokio = { version = "1.8", features = ["fs"] } tokio-util = "0.6" diff --git a/README.md b/README.md index 73ba1b81..54f26901 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,6 @@ impl Default for State { } } -#[tokio::main] async fn main() { pretty_env_logger::init(); log::info!("Starting dialogue_bot..."); @@ -221,12 +220,11 @@ async fn main() { bot, Update::filter_message() .enter_dialogue::, State>() - .branch(teloxide::handler![State::Start].endpoint(start)) - .branch(teloxide::handler![State::ReceiveFullName].endpoint(receive_full_name)) - .branch(teloxide::handler![State::ReceiveAge { full_name }].endpoint(receive_age)) + .branch(dptree::case![State::Start].endpoint(start)) + .branch(dptree::case![State::ReceiveFullName].endpoint(receive_full_name)) + .branch(dptree::case![State::ReceiveAge { full_name }].endpoint(receive_age)) .branch( - teloxide::handler![State::ReceiveLocation { full_name, age }] - .endpoint(receive_location), + dptree::case![State::ReceiveLocation { full_name, age }].endpoint(receive_location), ), ) .dependencies(dptree::deps![InMemStorage::::new()]) diff --git a/examples/db_remember.rs b/examples/db_remember.rs index 2aba6dc4..3a67a146 100644 --- a/examples/db_remember.rs +++ b/examples/db_remember.rs @@ -50,9 +50,9 @@ async fn main() { let handler = Update::filter_message() .enter_dialogue::, State>() - .branch(teloxide::handler![State::Start].endpoint(start)) + .branch(dptree::case![State::Start].endpoint(start)) .branch( - teloxide::handler![State::GotNumber(n)] + dptree::case![State::GotNumber(n)] .branch(dptree::entry().filter_command::().endpoint(got_number)) .branch(dptree::endpoint(invalid_command)), ); diff --git a/examples/dialogue.rs b/examples/dialogue.rs index f0c46a54..fcaafdb7 100644 --- a/examples/dialogue.rs +++ b/examples/dialogue.rs @@ -43,12 +43,11 @@ async fn main() { bot, Update::filter_message() .enter_dialogue::, State>() - .branch(teloxide::handler![State::Start].endpoint(start)) - .branch(teloxide::handler![State::ReceiveFullName].endpoint(receive_full_name)) - .branch(teloxide::handler![State::ReceiveAge { full_name }].endpoint(receive_age)) + .branch(dptree::case![State::Start].endpoint(start)) + .branch(dptree::case![State::ReceiveFullName].endpoint(receive_full_name)) + .branch(dptree::case![State::ReceiveAge { full_name }].endpoint(receive_age)) .branch( - teloxide::handler![State::ReceiveLocation { full_name, age }] - .endpoint(receive_location), + dptree::case![State::ReceiveLocation { full_name, age }].endpoint(receive_location), ), ) .dependencies(dptree::deps![InMemStorage::::new()]) diff --git a/examples/purchase.rs b/examples/purchase.rs index daa5e657..e8333380 100644 --- a/examples/purchase.rs +++ b/examples/purchase.rs @@ -67,19 +67,19 @@ async fn main() { fn schema() -> UpdateHandler> { let command_handler = teloxide::filter_command::() .branch( - teloxide::handler![State::Start] - .branch(teloxide::handler![Command::Help].endpoint(help)) - .branch(teloxide::handler![Command::Start].endpoint(start)), + dptree::case![State::Start] + .branch(dptree::case![Command::Help].endpoint(help)) + .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() .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)); 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), ); diff --git a/src/dispatching/dialogue/mod.rs b/src/dispatching/dialogue/mod.rs index dc68ff40..ee6954f8 100644 --- a/src/dispatching/dialogue/mod.rs +++ b/src/dispatching/dialogue/mod.rs @@ -252,38 +252,16 @@ where /// - Your dialogue state enumeration `State`. /// /// [`examples/purchase.rs`]: https://github.com/teloxide/teloxide/blob/master/examples/purchase.rs +#[deprecated(note = "Use dptree::case! instead")] #[macro_export] macro_rules! handler { - ($($variant:ident)::+) => { - $crate::dptree::filter(|state| matches!(state, $($variant)::+)) - }; - ($($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, - }) + ($($x:tt)*) => { + $crate::dptree::case![$($x)*] }; } #[cfg(test)] +#[allow(deprecated)] mod tests { use std::ops::ControlFlow;