mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
commit
a9d3fae987
2 changed files with 30 additions and 10 deletions
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Add `MessageToCopyNotFound` error to `teloxide::errors::ApiError` ([PR 917](https://github.com/teloxide/teloxide/pull/917))
|
- Add `MessageToCopyNotFound` error to `teloxide::errors::ApiError` ([PR 917](https://github.com/teloxide/teloxide/pull/917))
|
||||||
|
- `Dispatcher::try_dispatch_with_listener` ([PR 913](https://github.com/teloxide/teloxide/pull/913))
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,6 @@ where
|
||||||
/// - 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`]).
|
||||||
///
|
///
|
||||||
/// [`shutdown`]: ShutdownToken::shutdown
|
|
||||||
/// [`HandlerExt::filter_command`]: crate::dispatching::HandlerExt::filter_command
|
/// [`HandlerExt::filter_command`]: crate::dispatching::HandlerExt::filter_command
|
||||||
pub async fn dispatch(&mut self)
|
pub async fn dispatch(&mut self)
|
||||||
where
|
where
|
||||||
|
@ -295,19 +294,39 @@ where
|
||||||
/// `update_listener_error_handler`.
|
/// `update_listener_error_handler`.
|
||||||
///
|
///
|
||||||
/// This method adds the same dependencies as [`Dispatcher::dispatch`].
|
/// This method adds the same dependencies as [`Dispatcher::dispatch`].
|
||||||
///
|
|
||||||
/// [`shutdown`]: ShutdownToken::shutdown
|
|
||||||
pub async fn dispatch_with_listener<'a, UListener, Eh>(
|
pub async fn dispatch_with_listener<'a, UListener, Eh>(
|
||||||
&'a mut self,
|
&'a mut self,
|
||||||
mut update_listener: UListener,
|
update_listener: UListener,
|
||||||
update_listener_error_handler: Arc<Eh>,
|
update_listener_error_handler: Arc<Eh>,
|
||||||
) where
|
) where
|
||||||
UListener: UpdateListener + 'a,
|
UListener: UpdateListener + 'a,
|
||||||
Eh: ErrorHandler<UListener::Err> + 'a,
|
Eh: ErrorHandler<UListener::Err> + 'a,
|
||||||
UListener::Err: Debug,
|
UListener::Err: Debug,
|
||||||
|
{
|
||||||
|
self.try_dispatch_with_listener(update_listener, update_listener_error_handler)
|
||||||
|
.await
|
||||||
|
.expect("Couldn't prepare dispatching context")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Same as `dispatch_with_listener` but returns a `Err(_)` instead of
|
||||||
|
/// panicking when the initial telegram api call (`get_me`) fails.
|
||||||
|
///
|
||||||
|
/// Starts your bot with custom `update_listener` and
|
||||||
|
/// `update_listener_error_handler`.
|
||||||
|
///
|
||||||
|
/// This method adds the same dependencies as [`Dispatcher::dispatch`].
|
||||||
|
pub async fn try_dispatch_with_listener<'a, UListener, Eh>(
|
||||||
|
&'a mut self,
|
||||||
|
mut update_listener: UListener,
|
||||||
|
update_listener_error_handler: Arc<Eh>,
|
||||||
|
) -> Result<(), R::Err>
|
||||||
|
where
|
||||||
|
UListener: UpdateListener + 'a,
|
||||||
|
Eh: ErrorHandler<UListener::Err> + 'a,
|
||||||
|
UListener::Err: Debug,
|
||||||
{
|
{
|
||||||
// FIXME: there should be a way to check if dependency is already inserted
|
// FIXME: there should be a way to check if dependency is already inserted
|
||||||
let me = self.bot.get_me().send().await.expect("Failed to retrieve 'me'");
|
let me = self.bot.get_me().send().await?;
|
||||||
self.dependencies.insert(me);
|
self.dependencies.insert(me);
|
||||||
self.dependencies.insert(self.bot.clone());
|
self.dependencies.insert(self.bot.clone());
|
||||||
|
|
||||||
|
@ -360,6 +379,7 @@ where
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.state.done();
|
self.state.done();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_update<LErr, LErrHandler>(
|
async fn process_update<LErr, LErrHandler>(
|
||||||
|
@ -462,9 +482,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setups the `^C` handler that [`shutdown`]s dispatching.
|
/// Setups the `^C` handler in order to call [`ShutdownToken::shutdown`]
|
||||||
///
|
/// when pressed.
|
||||||
/// [`shutdown`]: ShutdownToken::shutdown
|
|
||||||
#[cfg(feature = "ctrlc_handler")]
|
#[cfg(feature = "ctrlc_handler")]
|
||||||
#[deprecated(since = "0.10.0", note = "use `enable_ctrlc_handler` on builder instead")]
|
#[deprecated(since = "0.10.0", note = "use `enable_ctrlc_handler` on builder instead")]
|
||||||
pub fn setup_ctrlc_handler(&mut self) -> &mut Self {
|
pub fn setup_ctrlc_handler(&mut self) -> &mut Self {
|
||||||
|
@ -472,8 +491,8 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a shutdown token, which can later be used to shutdown
|
/// Returns a shutdown token, which can later be used to
|
||||||
/// dispatching.
|
/// [`ShutdownToken::shutdown`].
|
||||||
pub fn shutdown_token(&self) -> ShutdownToken {
|
pub fn shutdown_token(&self) -> ShutdownToken {
|
||||||
self.state.clone()
|
self.state.clone()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue