mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Remove deprecated repl command stuff
This commit is contained in:
parent
d7b954b1c6
commit
f4127325da
5 changed files with 2 additions and 168 deletions
|
@ -134,6 +134,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- `InlineKeyboardButton::{text, kind}`
|
||||
`teloxide::dispatching::{update_listeners, repls}` (use `reloxide::{update_listeners, repls}` instead)
|
||||
- `Dispatcher::setup_ctrlc_handler` (use `enable_ctrlc_handler` on the builder instead)
|
||||
- `BotCommands::ty` and `repls::{commands_repl, commands_repl_with_listener}` (use `CommandsRepl::{repl, repl_with_listener}` instead)
|
||||
|
||||
[pr954]: https://github.com/teloxide/teloxide/pull/954
|
||||
[pr1013]: https://github.com/teloxide/teloxide/pull/1013
|
||||
|
|
|
@ -131,10 +131,6 @@
|
|||
#[cfg(feature = "ctrlc_handler")]
|
||||
pub use repls::{repl, repl_with_listener};
|
||||
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[allow(deprecated)]
|
||||
pub use repls::{commands_repl, commands_repl_with_listener};
|
||||
|
||||
pub mod backoff;
|
||||
pub mod dispatching;
|
||||
pub mod error_handlers;
|
||||
|
|
|
@ -12,6 +12,4 @@ mod commands_repl;
|
|||
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};
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
};
|
||||
use dptree::di::{DependencyMap, Injectable};
|
||||
use futures::future::BoxFuture;
|
||||
use std::{fmt::Debug, marker::PhantomData};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// A [REPL] for commands.
|
||||
///
|
||||
|
@ -147,154 +147,3 @@ where
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A [REPL] for commands.
|
||||
//
|
||||
///
|
||||
//
|
||||
#[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`].
|
||||
/// 3. `cmd` is a type hint for your command enumeration `MyCommand`: just write
|
||||
/// `MyCommand::ty()`. Note that `MyCommand` must implement the
|
||||
/// [`BotCommands`] trait, typically via
|
||||
/// `#[derive(BotCommands)]`.
|
||||
///
|
||||
/// All the other requirements are about thread safety and data validity and can
|
||||
/// be ignored for most of the time.
|
||||
///
|
||||
/// ## Handler arguments
|
||||
///
|
||||
/// `teloxide` provides the following types to the `handler`:
|
||||
/// - [`Message`]
|
||||
/// - `R` (type of the `bot`)
|
||||
/// - `Cmd` (type of the parsed command)
|
||||
/// - [`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 command without [`Me`] and [`Message`].
|
||||
///
|
||||
/// [`Me`]: crate::types::Me
|
||||
/// [`Message`]: crate::types::Message
|
||||
///
|
||||
/// ## Stopping
|
||||
//
|
||||
#[doc = include_str!("stopping.md")]
|
||||
///
|
||||
/// ## Caution
|
||||
//
|
||||
#[doc = include_str!("caution.md")]
|
||||
///
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[deprecated(note = "Use `CommandsRepl::repl` instead")]
|
||||
pub async fn commands_repl<'a, R, Cmd, H, Args>(bot: R, handler: H, cmd: PhantomData<Cmd>)
|
||||
where
|
||||
R: Requester + Clone + Send + Sync + 'static,
|
||||
<R as Requester>::GetUpdates: Send,
|
||||
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
|
||||
Cmd: BotCommands + Send + Sync + 'static,
|
||||
{
|
||||
let cloned_bot = bot.clone();
|
||||
|
||||
#[allow(deprecated)]
|
||||
commands_repl_with_listener(
|
||||
bot,
|
||||
handler,
|
||||
update_listeners::polling_default(cloned_bot).await,
|
||||
cmd,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// A [REPL] for commands, with a custom [`UpdateListener`].
|
||||
//
|
||||
///
|
||||
//
|
||||
#[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`].
|
||||
/// 3. `listener` is something that takes updates from a Telegram server and
|
||||
/// implements [`UpdateListener`].
|
||||
/// 4. `cmd` is a type hint for your command enumeration `MyCommand`: just write
|
||||
/// `MyCommand::ty()`. Note that `MyCommand` must implement the
|
||||
/// [`BotCommands`] trait, typically via `#[derive(BotCommands)]`.
|
||||
///
|
||||
/// All the other requirements are about thread safety and data validity and can
|
||||
/// be ignored for most of the time.
|
||||
///
|
||||
/// ## Handler arguments
|
||||
///
|
||||
/// `teloxide` provides the following types to the `handler`:
|
||||
/// - [`Message`]
|
||||
/// - `R` (type of the `bot`)
|
||||
/// - `Cmd` (type of the parsed command)
|
||||
/// - [`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 command without [`Me`] and [`Message`].
|
||||
///
|
||||
/// [`Me`]: crate::types::Me
|
||||
/// [`Message`]: crate::types::Message
|
||||
///
|
||||
/// ## Stopping
|
||||
//
|
||||
#[doc = include_str!("stopping.md")]
|
||||
///
|
||||
/// ## Caution
|
||||
//
|
||||
#[doc = include_str!("caution.md")]
|
||||
///
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[deprecated(note = "Use `CommandsRepl::repl_with_listener` instead")]
|
||||
pub async fn commands_repl_with_listener<'a, R, Cmd, H, L, Args>(
|
||||
bot: R,
|
||||
handler: H,
|
||||
listener: L,
|
||||
cmd: PhantomData<Cmd>,
|
||||
) where
|
||||
Cmd: BotCommands + Send + Sync + 'static,
|
||||
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
|
||||
L: UpdateListener + Send + 'a,
|
||||
L::Err: Debug + Send + 'a,
|
||||
R: Requester + Clone + Send + Sync + 'static,
|
||||
{
|
||||
use crate::dispatching::Dispatcher;
|
||||
|
||||
let _ = cmd;
|
||||
|
||||
// Other update types are of no interest to use since this REPL is only for
|
||||
// commands. See <https://github.com/teloxide/teloxide/issues/557>.
|
||||
let ignore_update = |_upd| Box::pin(async {});
|
||||
|
||||
Dispatcher::builder(bot, Update::filter_message().filter_command::<Cmd>().endpoint(handler))
|
||||
.default_handler(ignore_update)
|
||||
.enable_ctrlc_handler()
|
||||
.build()
|
||||
.dispatch_with_listener(
|
||||
listener,
|
||||
LoggingErrorHandler::with_custom_text("An error from the update listener"),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ use std::{
|
|||
fmt::{Display, Formatter, Write},
|
||||
};
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use teloxide_core::types::{BotCommand, Me};
|
||||
#[cfg(feature = "macros")]
|
||||
pub use teloxide_macros::BotCommands;
|
||||
|
@ -265,15 +264,6 @@ pub trait BotCommands: Sized {
|
|||
/// [`BotCommand`]: crate::types::BotCommand
|
||||
/// [`set_my_commands`]: crate::requests::Requester::set_my_commands
|
||||
fn bot_commands() -> Vec<BotCommand>;
|
||||
|
||||
/// Returns `PhantomData<Self>` that is used as a param of [`commands_repl`]
|
||||
///
|
||||
/// [`commands_repl`]: (crate::repls::commands_repl)
|
||||
#[must_use]
|
||||
#[deprecated(note = "Use `CommandReplExt` instead")]
|
||||
fn ty() -> PhantomData<Self> {
|
||||
PhantomData
|
||||
}
|
||||
}
|
||||
|
||||
pub type PrefixedBotCommand = String;
|
||||
|
|
Loading…
Reference in a new issue