mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
revert tryable repls
This commit is contained in:
parent
e861454413
commit
8d858c43ff
3 changed files with 6 additions and 120 deletions
|
@ -60,7 +60,7 @@
|
|||
#![allow(clippy::nonstandard_macro_braces)]
|
||||
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
pub use repls::{repl, repl_with_listener, try_repl, try_repl_with_listener};
|
||||
pub use repls::{repl, repl_with_listener};
|
||||
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[allow(deprecated)]
|
||||
|
|
|
@ -14,4 +14,4 @@ mod repl;
|
|||
pub use commands_repl::CommandReplExt;
|
||||
#[allow(deprecated)]
|
||||
pub use commands_repl::{commands_repl, commands_repl_with_listener};
|
||||
pub use repl::{repl, repl_with_listener, try_repl, try_repl_with_listener};
|
||||
pub use repl::{repl, repl_with_listener};
|
||||
|
|
|
@ -50,65 +50,13 @@ use std::fmt::Debug;
|
|||
///
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
pub async fn repl<R, H, Args>(bot: R, handler: H)
|
||||
where
|
||||
R: Requester + Send + Sync + Clone + 'static,
|
||||
<R as Requester>::GetUpdates: Send,
|
||||
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
|
||||
{
|
||||
try_repl(bot, handler).await.expect("try_repl failed")
|
||||
}
|
||||
|
||||
/// Same as `repl` but returns a Result<_> instead of panicking
|
||||
///
|
||||
/// A [REPL] for messages.
|
||||
//
|
||||
///
|
||||
//
|
||||
#[doc = include_str!("preamble.md")]
|
||||
///
|
||||
/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop
|
||||
///
|
||||
/// ## Signature
|
||||
///
|
||||
/// Don't be scared by many trait bounds in the signature, in essence they
|
||||
/// require:
|
||||
///
|
||||
/// 1. `bot` is a bot, client for the Telegram bot API. It is represented via
|
||||
/// the [`Requester`] trait.
|
||||
/// 2. `handler` is an `async` function that takes arguments from
|
||||
/// [`DependencyMap`] (see below) and returns [`ResponseResult`].
|
||||
///
|
||||
/// ## Handler arguments
|
||||
///
|
||||
/// `teloxide` provides the following types to the `handler`:
|
||||
/// - [`Message`]
|
||||
/// - `R` (type of the `bot`)
|
||||
/// - [`Me`]
|
||||
///
|
||||
/// Each of these types can be accepted as a handler parameter. Note that they
|
||||
/// aren't all required at the same time: e.g., you can take only the bot and
|
||||
/// the message without [`Me`].
|
||||
///
|
||||
/// [`Me`]: crate::types::Me
|
||||
/// [`Message`]: crate::types::Message
|
||||
///
|
||||
/// ## Stopping
|
||||
//
|
||||
#[doc = include_str!("stopping.md")]
|
||||
///
|
||||
/// ## Caution
|
||||
//
|
||||
#[doc = include_str!("caution.md")]
|
||||
///
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
pub async fn try_repl<R, H, Args>(bot: R, handler: H) -> Result<(), R::Err>
|
||||
where
|
||||
R: Requester + Send + Sync + Clone + 'static,
|
||||
<R as Requester>::GetUpdates: Send,
|
||||
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
|
||||
{
|
||||
let cloned_bot = bot.clone();
|
||||
try_repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot).await).await
|
||||
repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot).await).await;
|
||||
}
|
||||
|
||||
/// A [REPL] for messages, with a custom [`UpdateListener`].
|
||||
|
@ -156,66 +104,6 @@ where
|
|||
///
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
pub async fn repl_with_listener<R, H, L, Args>(bot: R, handler: H, listener: L)
|
||||
where
|
||||
R: Requester + Clone + Send + Sync + 'static,
|
||||
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
|
||||
L: UpdateListener + Send,
|
||||
L::Err: Debug,
|
||||
{
|
||||
try_repl_with_listener(bot, handler, listener).await.expect("try_repl_with_listener failed")
|
||||
}
|
||||
|
||||
/// Same as `repl_with_listener` but returns a Result<_> instead of panicking
|
||||
///
|
||||
/// A [REPL] for messages, with a custom [`UpdateListener`].
|
||||
//
|
||||
///
|
||||
//
|
||||
#[doc = include_str!("preamble.md")]
|
||||
///
|
||||
/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop
|
||||
/// [`UpdateListener`]: crate::update_listeners::UpdateListener
|
||||
///
|
||||
/// ## Signature
|
||||
///
|
||||
/// Don't be scared by many trait bounds in the signature, in essence they
|
||||
/// require:
|
||||
///
|
||||
/// 1. `bot` is a bot, client for the Telegram bot API. It is represented via
|
||||
/// the [`Requester`] trait.
|
||||
/// 2. `handler` is an `async` function that takes arguments from
|
||||
/// [`DependencyMap`] (see below) and returns [`ResponseResult`].
|
||||
/// 3. `listener` is something that takes updates from a Telegram server and
|
||||
/// implements [`UpdateListener`].
|
||||
///
|
||||
/// ## Handler arguments
|
||||
///
|
||||
/// `teloxide` provides the following types to the `handler`:
|
||||
/// - [`Message`]
|
||||
/// - `R` (type of the `bot`)
|
||||
/// - [`Me`]
|
||||
///
|
||||
/// Each of these types can be accepted as a handler parameter. Note that they
|
||||
/// aren't all required at the same time: e.g., you can take only the bot and
|
||||
/// the message without [`Me`].
|
||||
///
|
||||
/// [`Me`]: crate::types::Me
|
||||
/// [`Message`]: crate::types::Message
|
||||
///
|
||||
/// ## Stopping
|
||||
//
|
||||
#[doc = include_str!("stopping.md")]
|
||||
///
|
||||
/// ## Caution
|
||||
//
|
||||
#[doc = include_str!("caution.md")]
|
||||
///
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
pub async fn try_repl_with_listener<R, H, L, Args>(
|
||||
bot: R,
|
||||
handler: H,
|
||||
listener: L,
|
||||
) -> Result<(), R::Err>
|
||||
where
|
||||
R: Requester + Clone + Send + Sync + 'static,
|
||||
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
|
||||
|
@ -232,13 +120,11 @@ where
|
|||
.default_handler(ignore_update)
|
||||
.enable_ctrlc_handler()
|
||||
.build()
|
||||
.try_dispatch_with_listener(
|
||||
.dispatch_with_listener(
|
||||
listener,
|
||||
LoggingErrorHandler::with_custom_text("An error from the update listener"),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
.await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue