diff --git a/README.md b/README.md index b22fb24d..20a2b4eb 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,7 @@ async fn main() { let bot = Bot::from_env().auto_send(); - DispatcherBuilder::new( + Dispatcher::builder( bot, Update::filter_message() .enter_dialogue::, State>() diff --git a/examples/buttons.rs b/examples/buttons.rs index 990abda3..3405081e 100644 --- a/examples/buttons.rs +++ b/examples/buttons.rs @@ -124,7 +124,7 @@ async fn main() -> Result<(), Box> { .branch(Update::filter_callback_query().endpoint(callback_handler)) .branch(Update::filter_inline_query().endpoint(inline_query_handler)); - DispatcherBuilder::new(bot, handler).build().setup_ctrlc_handler().dispatch().await; + Dispatcher::builder(bot, handler).build().setup_ctrlc_handler().dispatch().await; log::info!("Closing bot... Goodbye!"); diff --git a/examples/dialogue.rs b/examples/dialogue.rs index e96892be..0ddb9c53 100644 --- a/examples/dialogue.rs +++ b/examples/dialogue.rs @@ -46,7 +46,7 @@ async fn main() { let bot = Bot::from_env().auto_send(); - DispatcherBuilder::new( + Dispatcher::builder( bot, Update::filter_message() .enter_dialogue::, State>() diff --git a/examples/dispatching2_features.rs b/examples/dispatching2_features.rs index d404ecee..0ffdda36 100644 --- a/examples/dispatching2_features.rs +++ b/examples/dispatching2_features.rs @@ -81,7 +81,7 @@ async fn main() { ); // Start create dispatcher. - DispatcherBuilder::new(bot, handler) + Dispatcher::builder(bot, handler) // You can specify dependencies to that you have access inside of handlers. It may be // configs, connection to Database, or dialogue storage (see more in the dialogue_bot // example). It is similar to the `actix_web::Extensions`. diff --git a/examples/inline.rs b/examples/inline.rs index a1153970..57049546 100644 --- a/examples/inline.rs +++ b/examples/inline.rs @@ -60,5 +60,5 @@ async fn main() { }, )); - DispatcherBuilder::new(bot, handler).build().setup_ctrlc_handler().dispatch().await; + Dispatcher::builder(bot, handler).build().setup_ctrlc_handler().dispatch().await; } diff --git a/examples/redis_remember.rs b/examples/redis_remember.rs index 55bb2a16..8fc9f62f 100644 --- a/examples/redis_remember.rs +++ b/examples/redis_remember.rs @@ -47,7 +47,7 @@ async fn main() { .enter_dialogue::, State>() .dispatch_by::(); - DispatcherBuilder::new(bot, handler) + Dispatcher::builder(bot, handler) .dependencies(dptree::deps![storage]) .build() .setup_ctrlc_handler() diff --git a/examples/shared_state.rs b/examples/shared_state.rs index 376c790f..b397160f 100644 --- a/examples/shared_state.rs +++ b/examples/shared_state.rs @@ -25,5 +25,5 @@ async fn main() { }, )); - DispatcherBuilder::new(bot, handler).build().setup_ctrlc_handler().dispatch().await; + Dispatcher::builder(bot, handler).build().setup_ctrlc_handler().dispatch().await; } diff --git a/examples/sqlite_remember.rs b/examples/sqlite_remember.rs index 777c5bd8..5a109f83 100644 --- a/examples/sqlite_remember.rs +++ b/examples/sqlite_remember.rs @@ -43,7 +43,7 @@ async fn main() { .enter_dialogue::, State>() .dispatch_by::(); - DispatcherBuilder::new(bot, handler) + Dispatcher::builder(bot, handler) .dependencies(dptree::deps![storage]) .build() .setup_ctrlc_handler() diff --git a/src/dispatching2/dispatcher.rs b/src/dispatching2/dispatcher.rs index 69701582..e69084af 100644 --- a/src/dispatching2/dispatcher.rs +++ b/src/dispatching2/dispatcher.rs @@ -28,20 +28,6 @@ where R: Clone + Requester + Clone + Send + Sync + 'static, Err: Debug + Send + Sync + 'static, { - /// Constructs a new [`DispatcherBuilder`] with `bot` and `handler`. - #[must_use] - pub fn new(bot: R, handler: UpdateHandler) -> Self { - Self { - bot, - dependencies: DependencyMap::new(), - handler, - default_handler: dptree::endpoint(|update: Update| async move { - log::warn!("Unhandled update: {:?}", update); - }), - error_handler: LoggingErrorHandler::new(), - } - } - /// Specifies a handler that will be called for an unhandled update. /// /// By default, it is a mere [`log::warn`]. Note that it **must** always @@ -114,6 +100,23 @@ where R: Requester + Clone + Send + Sync + 'static, Err: Send + Sync + 'static, { + /// Constructs a new [`DispatcherBuilder`] with `bot` and `handler`. + #[must_use] + pub fn builder(bot: R, handler: UpdateHandler) -> DispatcherBuilder + where + Err: Debug, + { + DispatcherBuilder { + bot, + dependencies: DependencyMap::new(), + handler, + default_handler: dptree::endpoint(|update: Update| async move { + log::warn!("Unhandled update: {:?}", update); + }), + error_handler: LoggingErrorHandler::new(), + } + } + /// Starts your bot with the default parameters. /// /// The default parameters are a long polling update listener and log all @@ -123,7 +126,7 @@ where /// dependencies (in addition to those passed to /// [`DispatcherBuilder::dependencies`]): /// - /// - Your bot passed to [`DispatcherBuilder::new`]; + /// - Your bot passed to [`Dispatcher::builder`]; /// - An update from Telegram; /// - [`crate::types::Me`] (can be used in [`HandlerExt::filter_command`]). /// diff --git a/src/dispatching2/mod.rs b/src/dispatching2/mod.rs index 1071645a..a26eaa6c 100644 --- a/src/dispatching2/mod.rs +++ b/src/dispatching2/mod.rs @@ -21,7 +21,7 @@ //! The [`Dispatcher`] type puts all these things together: it only provides //! [`Dispatcher::dispatch`] and a handful of other methods. Once you call //! `.dispatch()`, it will retrieve updates from the Telegram server and pass -//! them to your handler, which is a parameter of [`DispatcherBuilder::new`]. +//! them to your handler, which is a parameter of [`Dispatcher::builder`]. //! //! Let us look at a simple example: //! @@ -54,7 +54,7 @@ //! }, //! )); //! -//! DispatcherBuilder::new(bot, handler).build().setup_ctrlc_handler().dispatch().await; +//! Dispatcher::builder(bot, handler).build().setup_ctrlc_handler().dispatch().await; //! # } //! ``` //! diff --git a/src/dispatching2/repls/commands_repl.rs b/src/dispatching2/repls/commands_repl.rs index 0c68d45e..320381fa 100644 --- a/src/dispatching2/repls/commands_repl.rs +++ b/src/dispatching2/repls/commands_repl.rs @@ -1,6 +1,6 @@ use crate::{ dispatching::{update_listeners, update_listeners::UpdateListener}, - dispatching2::{DispatcherBuilder, HandlerExt, UpdateFilterExt}, + dispatching2::{HandlerExt, UpdateFilterExt}, error_handlers::LoggingErrorHandler, types::Update, utils::command::BotCommand, @@ -74,7 +74,9 @@ pub async fn commands_repl_with_listener<'a, R, Cmd, H, L, ListenerE, E, Args>( R: Requester + Clone + Send + Sync + 'static, E: Debug + Send + Sync + 'static, { - let mut dispatcher = DispatcherBuilder::new( + use crate::dispatching2::Dispatcher; + + let mut dispatcher = Dispatcher::builder( bot, Update::filter_message().filter_command::().branch(dptree::endpoint(handler)), ) diff --git a/src/dispatching2/repls/repl.rs b/src/dispatching2/repls/repl.rs index 9dd758b1..6a047b98 100644 --- a/src/dispatching2/repls/repl.rs +++ b/src/dispatching2/repls/repl.rs @@ -1,6 +1,6 @@ use crate::{ dispatching::{update_listeners, update_listeners::UpdateListener}, - dispatching2::{DispatcherBuilder, UpdateFilterExt}, + dispatching2::UpdateFilterExt, error_handlers::{LoggingErrorHandler, OnError}, types::Update, }; @@ -54,9 +54,11 @@ where E: Debug + Send + Sync + 'static, R: Requester + Clone + Send + Sync + 'static, { + use crate::dispatching2::Dispatcher; + #[allow(unused_mut)] let mut dispatcher = - DispatcherBuilder::new(bot, Update::filter_message().branch(dptree::endpoint(handler))) + Dispatcher::builder(bot, Update::filter_message().branch(dptree::endpoint(handler))) .build(); #[cfg(feature = "ctrlc_handler")] diff --git a/src/prelude2.rs b/src/prelude2.rs index 4c2d2c5b..79aadf51 100644 --- a/src/prelude2.rs +++ b/src/prelude2.rs @@ -6,8 +6,7 @@ pub use crate::{ }; pub use crate::dispatching2::{ - dialogue::Dialogue, Dispatcher, DispatcherBuilder, HandlerExt as _, MessageFilterExt as _, - UpdateFilterExt as _, + dialogue::Dialogue, Dispatcher, HandlerExt as _, MessageFilterExt as _, UpdateFilterExt as _, }; #[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]