From f4127325dadd536ac9d0eaa4367e54ca5c52def6 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 13 Feb 2024 20:48:01 +0100 Subject: [PATCH] Remove deprecated repl command stuff --- crates/teloxide-core/CHANGELOG.md | 1 + crates/teloxide/src/lib.rs | 4 - crates/teloxide/src/repls.rs | 2 - crates/teloxide/src/repls/commands_repl.rs | 153 +-------------------- crates/teloxide/src/utils/command.rs | 10 -- 5 files changed, 2 insertions(+), 168 deletions(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index f739bfdd..32c517a1 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -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 diff --git a/crates/teloxide/src/lib.rs b/crates/teloxide/src/lib.rs index 4535d843..9a2ebeb3 100644 --- a/crates/teloxide/src/lib.rs +++ b/crates/teloxide/src/lib.rs @@ -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; diff --git a/crates/teloxide/src/repls.rs b/crates/teloxide/src/repls.rs index aea4806e..6ba3d640 100644 --- a/crates/teloxide/src/repls.rs +++ b/crates/teloxide/src/repls.rs @@ -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}; diff --git a/crates/teloxide/src/repls/commands_repl.rs b/crates/teloxide/src/repls/commands_repl.rs index c846089e..699e57da 100644 --- a/crates/teloxide/src/repls/commands_repl.rs +++ b/crates/teloxide/src/repls/commands_repl.rs @@ -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) -where - R: Requester + Clone + Send + Sync + 'static, - ::GetUpdates: Send, - H: Injectable, 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, -) where - Cmd: BotCommands + Send + Sync + 'static, - H: Injectable, 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 . - let ignore_update = |_upd| Box::pin(async {}); - - Dispatcher::builder(bot, Update::filter_message().filter_command::().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; -} diff --git a/crates/teloxide/src/utils/command.rs b/crates/teloxide/src/utils/command.rs index 32aba462..ab85f893 100644 --- a/crates/teloxide/src/utils/command.rs +++ b/crates/teloxide/src/utils/command.rs @@ -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; - - /// Returns `PhantomData` 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 { - PhantomData - } } pub type PrefixedBotCommand = String;