mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
DispatcherBuilder::new
=> Dispatcher::builder
This commit is contained in:
parent
a5d8a36f2c
commit
9efa2f6cbd
13 changed files with 37 additions and 31 deletions
|
@ -220,7 +220,7 @@ async fn main() {
|
|||
|
||||
let bot = Bot::from_env().auto_send();
|
||||
|
||||
DispatcherBuilder::new(
|
||||
Dispatcher::builder(
|
||||
bot,
|
||||
Update::filter_message()
|
||||
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
||||
|
|
|
@ -124,7 +124,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
.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!");
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ async fn main() {
|
|||
|
||||
let bot = Bot::from_env().auto_send();
|
||||
|
||||
DispatcherBuilder::new(
|
||||
Dispatcher::builder(
|
||||
bot,
|
||||
Update::filter_message()
|
||||
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
||||
|
|
|
@ -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`.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ async fn main() {
|
|||
.enter_dialogue::<Message, RedisStorage<Bincode>, State>()
|
||||
.dispatch_by::<State>();
|
||||
|
||||
DispatcherBuilder::new(bot, handler)
|
||||
Dispatcher::builder(bot, handler)
|
||||
.dependencies(dptree::deps![storage])
|
||||
.build()
|
||||
.setup_ctrlc_handler()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ async fn main() {
|
|||
.enter_dialogue::<Message, SqliteStorage<Json>, State>()
|
||||
.dispatch_by::<State>();
|
||||
|
||||
DispatcherBuilder::new(bot, handler)
|
||||
Dispatcher::builder(bot, handler)
|
||||
.dependencies(dptree::deps![storage])
|
||||
.build()
|
||||
.setup_ctrlc_handler()
|
||||
|
|
|
@ -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<Err>) -> 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<Err>) -> DispatcherBuilder<R, Err>
|
||||
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`]).
|
||||
///
|
||||
|
|
|
@ -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;
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
|
|
|
@ -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::<Cmd>().branch(dptree::endpoint(handler)),
|
||||
)
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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")))]
|
||||
|
|
Loading…
Reference in a new issue