mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-20 15:54:53 +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();
|
let bot = Bot::from_env().auto_send();
|
||||||
|
|
||||||
DispatcherBuilder::new(
|
Dispatcher::builder(
|
||||||
bot,
|
bot,
|
||||||
Update::filter_message()
|
Update::filter_message()
|
||||||
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
.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_callback_query().endpoint(callback_handler))
|
||||||
.branch(Update::filter_inline_query().endpoint(inline_query_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!");
|
log::info!("Closing bot... Goodbye!");
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ async fn main() {
|
||||||
|
|
||||||
let bot = Bot::from_env().auto_send();
|
let bot = Bot::from_env().auto_send();
|
||||||
|
|
||||||
DispatcherBuilder::new(
|
Dispatcher::builder(
|
||||||
bot,
|
bot,
|
||||||
Update::filter_message()
|
Update::filter_message()
|
||||||
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
||||||
|
|
|
@ -81,7 +81,7 @@ async fn main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Start create dispatcher.
|
// 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
|
// 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
|
// configs, connection to Database, or dialogue storage (see more in the dialogue_bot
|
||||||
// example). It is similar to the `actix_web::Extensions`.
|
// 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>()
|
.enter_dialogue::<Message, RedisStorage<Bincode>, State>()
|
||||||
.dispatch_by::<State>();
|
.dispatch_by::<State>();
|
||||||
|
|
||||||
DispatcherBuilder::new(bot, handler)
|
Dispatcher::builder(bot, handler)
|
||||||
.dependencies(dptree::deps![storage])
|
.dependencies(dptree::deps![storage])
|
||||||
.build()
|
.build()
|
||||||
.setup_ctrlc_handler()
|
.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>()
|
.enter_dialogue::<Message, SqliteStorage<Json>, State>()
|
||||||
.dispatch_by::<State>();
|
.dispatch_by::<State>();
|
||||||
|
|
||||||
DispatcherBuilder::new(bot, handler)
|
Dispatcher::builder(bot, handler)
|
||||||
.dependencies(dptree::deps![storage])
|
.dependencies(dptree::deps![storage])
|
||||||
.build()
|
.build()
|
||||||
.setup_ctrlc_handler()
|
.setup_ctrlc_handler()
|
||||||
|
|
|
@ -28,20 +28,6 @@ where
|
||||||
R: Clone + Requester + Clone + Send + Sync + 'static,
|
R: Clone + Requester + Clone + Send + Sync + 'static,
|
||||||
Err: Debug + 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.
|
/// Specifies a handler that will be called for an unhandled update.
|
||||||
///
|
///
|
||||||
/// By default, it is a mere [`log::warn`]. Note that it **must** always
|
/// By default, it is a mere [`log::warn`]. Note that it **must** always
|
||||||
|
@ -114,6 +100,23 @@ where
|
||||||
R: Requester + Clone + Send + Sync + 'static,
|
R: Requester + Clone + Send + Sync + 'static,
|
||||||
Err: 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.
|
/// Starts your bot with the default parameters.
|
||||||
///
|
///
|
||||||
/// The default parameters are a long polling update listener and log all
|
/// The default parameters are a long polling update listener and log all
|
||||||
|
@ -123,7 +126,7 @@ where
|
||||||
/// dependencies (in addition to those passed to
|
/// dependencies (in addition to those passed to
|
||||||
/// [`DispatcherBuilder::dependencies`]):
|
/// [`DispatcherBuilder::dependencies`]):
|
||||||
///
|
///
|
||||||
/// - Your bot passed to [`DispatcherBuilder::new`];
|
/// - Your bot passed to [`Dispatcher::builder`];
|
||||||
/// - An update from Telegram;
|
/// - An update from Telegram;
|
||||||
/// - [`crate::types::Me`] (can be used in [`HandlerExt::filter_command`]).
|
/// - [`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
|
//! The [`Dispatcher`] type puts all these things together: it only provides
|
||||||
//! [`Dispatcher::dispatch`] and a handful of other methods. Once you call
|
//! [`Dispatcher::dispatch`] and a handful of other methods. Once you call
|
||||||
//! `.dispatch()`, it will retrieve updates from the Telegram server and pass
|
//! `.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:
|
//! 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::{
|
use crate::{
|
||||||
dispatching::{update_listeners, update_listeners::UpdateListener},
|
dispatching::{update_listeners, update_listeners::UpdateListener},
|
||||||
dispatching2::{DispatcherBuilder, HandlerExt, UpdateFilterExt},
|
dispatching2::{HandlerExt, UpdateFilterExt},
|
||||||
error_handlers::LoggingErrorHandler,
|
error_handlers::LoggingErrorHandler,
|
||||||
types::Update,
|
types::Update,
|
||||||
utils::command::BotCommand,
|
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,
|
R: Requester + Clone + Send + Sync + 'static,
|
||||||
E: Debug + Send + Sync + 'static,
|
E: Debug + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let mut dispatcher = DispatcherBuilder::new(
|
use crate::dispatching2::Dispatcher;
|
||||||
|
|
||||||
|
let mut dispatcher = Dispatcher::builder(
|
||||||
bot,
|
bot,
|
||||||
Update::filter_message().filter_command::<Cmd>().branch(dptree::endpoint(handler)),
|
Update::filter_message().filter_command::<Cmd>().branch(dptree::endpoint(handler)),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
dispatching::{update_listeners, update_listeners::UpdateListener},
|
dispatching::{update_listeners, update_listeners::UpdateListener},
|
||||||
dispatching2::{DispatcherBuilder, UpdateFilterExt},
|
dispatching2::UpdateFilterExt,
|
||||||
error_handlers::{LoggingErrorHandler, OnError},
|
error_handlers::{LoggingErrorHandler, OnError},
|
||||||
types::Update,
|
types::Update,
|
||||||
};
|
};
|
||||||
|
@ -54,9 +54,11 @@ where
|
||||||
E: Debug + Send + Sync + 'static,
|
E: Debug + Send + Sync + 'static,
|
||||||
R: Requester + Clone + Send + Sync + 'static,
|
R: Requester + Clone + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
|
use crate::dispatching2::Dispatcher;
|
||||||
|
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut dispatcher =
|
let mut dispatcher =
|
||||||
DispatcherBuilder::new(bot, Update::filter_message().branch(dptree::endpoint(handler)))
|
Dispatcher::builder(bot, Update::filter_message().branch(dptree::endpoint(handler)))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
#[cfg(feature = "ctrlc_handler")]
|
#[cfg(feature = "ctrlc_handler")]
|
||||||
|
|
|
@ -6,8 +6,7 @@ pub use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use crate::dispatching2::{
|
pub use crate::dispatching2::{
|
||||||
dialogue::Dialogue, Dispatcher, DispatcherBuilder, HandlerExt as _, MessageFilterExt as _,
|
dialogue::Dialogue, Dispatcher, HandlerExt as _, MessageFilterExt as _, UpdateFilterExt as _,
|
||||||
UpdateFilterExt as _,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
|
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "macros")))]
|
||||||
|
|
Loading…
Reference in a new issue