diff --git a/Cargo.toml b/Cargo.toml index 8928132d..7fb07c2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,8 @@ full = [ [dependencies] teloxide-core = { version = "0.4", default-features = false } -teloxide-macros = { version = "0.5.1", optional = true } +#teloxide-macros = { version = "0.5.1", optional = true } +teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", rev = "7e000b9", optional = true } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } diff --git a/examples/admin.rs b/examples/admin.rs index bf257aa9..76b40f91 100644 --- a/examples/admin.rs +++ b/examples/admin.rs @@ -1,7 +1,7 @@ use std::{error::Error, str::FromStr}; use chrono::Duration; -use teloxide::{prelude2::*, types::ChatPermissions, utils::command::BotCommand}; +use teloxide::{prelude2::*, types::ChatPermissions, utils::command::BotCommands}; // Derive BotCommand to parse text with a command into this enumeration. // @@ -12,7 +12,7 @@ use teloxide::{prelude2::*, types::ChatPermissions, utils::command::BotCommand}; // your commands in this format: // %GENERAL-DESCRIPTION% // %PREFIX%%COMMAND% - %DESCRIPTION% -#[derive(BotCommand, Clone)] +#[derive(BotCommands, Clone)] #[command( rename = "lowercase", description = "Use commands in format /%command% %num% %unit%", diff --git a/examples/buttons.rs b/examples/buttons.rs index cb98eeec..c0dd518b 100644 --- a/examples/buttons.rs +++ b/examples/buttons.rs @@ -6,10 +6,10 @@ use teloxide::{ InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultArticle, InputMessageContent, InputMessageContentText, }, - utils::command::BotCommand, + utils::command::BotCommands, }; -#[derive(BotCommand)] +#[derive(BotCommands)] #[command(rename = "lowercase", description = "These commands are supported:")] enum Command { #[command(description = "Display this text")] @@ -47,7 +47,7 @@ async fn message_handler( bot: AutoSend, ) -> Result<(), Box> { if let Some(text) = m.text() { - match BotCommand::parse(text, "buttons") { + match BotCommands::parse(text, "buttons") { Ok(Command::Help) => { // Just send the description of all commands. bot.send_message(m.chat.id, Command::descriptions()).await?; diff --git a/examples/db_remember.rs b/examples/db_remember.rs index 8a52318e..1e1fcbdd 100644 --- a/examples/db_remember.rs +++ b/examples/db_remember.rs @@ -9,7 +9,7 @@ use teloxide::{ macros::DialogueState, prelude2::*, types::Me, - utils::command::BotCommand, + utils::command::BotCommands, }; type MyDialogue = Dialogue>; @@ -32,7 +32,7 @@ impl Default for State { } } -#[derive(BotCommand)] +#[derive(BotCommands)] #[command(rename = "lowercase", description = "These commands are supported:")] pub enum Command { #[command(description = "get your number.")] diff --git a/examples/dispatching2_features.rs b/examples/dispatching2_features.rs index 6f5d1e07..ce894272 100644 --- a/examples/dispatching2_features.rs +++ b/examples/dispatching2_features.rs @@ -8,7 +8,7 @@ use rand::Rng; use teloxide::{ prelude2::*, types::{Dice, Update}, - utils::command::BotCommand, + utils::command::BotCommands, }; #[tokio::main] @@ -101,7 +101,7 @@ struct ConfigParameters { maintainer_username: Option, } -#[derive(BotCommand, Clone)] +#[derive(BotCommands, Clone)] #[command(rename = "lowercase", description = "Simple commands")] enum SimpleCommand { #[command(description = "shows this message.")] @@ -112,7 +112,7 @@ enum SimpleCommand { MyId, } -#[derive(BotCommand, Clone)] +#[derive(BotCommands, Clone)] #[command(rename = "lowercase", description = "Maintainer commands")] enum MaintainerCommands { #[command(parse_with = "split", description = "generate a number within range")] diff --git a/examples/simple_commands.rs b/examples/simple_commands.rs index 47b4337a..4c13102b 100644 --- a/examples/simple_commands.rs +++ b/examples/simple_commands.rs @@ -1,8 +1,8 @@ -use teloxide::{prelude2::*, utils::command::BotCommand}; +use teloxide::{prelude2::*, utils::command::BotCommands}; use std::error::Error; -#[derive(BotCommand, Clone)] +#[derive(BotCommands, Clone)] #[command(rename = "lowercase", description = "These commands are supported:")] enum Command { #[command(description = "display this text.")] diff --git a/src/dispatching/dispatcher_handler_rx_ext.rs b/src/dispatching/dispatcher_handler_rx_ext.rs index 9270826f..c7ad4215 100644 --- a/src/dispatching/dispatcher_handler_rx_ext.rs +++ b/src/dispatching/dispatcher_handler_rx_ext.rs @@ -1,4 +1,4 @@ -use crate::{dispatching::UpdateWithCx, utils::command::BotCommand}; +use crate::{dispatching::UpdateWithCx, utils::command::BotCommands}; use futures::{stream::BoxStream, Stream, StreamExt}; use teloxide_core::types::Message; @@ -21,7 +21,7 @@ pub trait DispatcherHandlerRxExt { fn commands(self, bot_name: N) -> BoxStream<'static, (UpdateWithCx, C)> where Self: Stream>, - C: BotCommand, + C: BotCommands, N: Into + Send, R: Send + 'static; } @@ -45,7 +45,7 @@ where fn commands(self, bot_name: N) -> BoxStream<'static, (UpdateWithCx, C)> where Self: Stream>, - C: BotCommand, + C: BotCommands, N: Into + Send, R: Send + 'static, { diff --git a/src/dispatching/repls/commands_repl.rs b/src/dispatching/repls/commands_repl.rs index d87cb83f..4ac20dfb 100644 --- a/src/dispatching/repls/commands_repl.rs +++ b/src/dispatching/repls/commands_repl.rs @@ -4,7 +4,7 @@ use crate::{ DispatcherHandlerRxExt, UpdateWithCx, }, error_handlers::{LoggingErrorHandler, OnError}, - utils::command::BotCommand, + utils::command::BotCommands, }; use futures::StreamExt; use std::{fmt::Debug, future::Future, sync::Arc}; @@ -25,7 +25,7 @@ use tokio_stream::wrappers::UnboundedReceiverStream; #[cfg(feature = "ctrlc_handler")] pub async fn commands_repl(requester: R, bot_name: N, handler: H) where - Cmd: BotCommand + Send + 'static, + Cmd: BotCommands + Send + 'static, H: Fn(UpdateWithCx, Cmd) -> Fut + Send + Sync + 'static, Fut: Future> + Send + 'static, Result<(), HandlerE>: OnError, @@ -64,7 +64,7 @@ pub async fn commands_repl_with_listener<'a, R, Cmd, H, Fut, L, ListenerE, Handl handler: H, listener: L, ) where - Cmd: BotCommand + Send + 'static, + Cmd: BotCommands + Send + 'static, H: Fn(UpdateWithCx, Cmd) -> Fut + Send + Sync + 'static, Fut: Future> + Send + 'static, L: UpdateListener + Send + 'a, diff --git a/src/dispatching2/handler_ext.rs b/src/dispatching2/handler_ext.rs index 6fcafca1..a3774aa5 100644 --- a/src/dispatching2/handler_ext.rs +++ b/src/dispatching2/handler_ext.rs @@ -6,7 +6,7 @@ use crate::{ HandlerFactory, }, types::{Me, Message}, - utils::command::BotCommand, + utils::command::BotCommands, }; use dptree::{di::DependencyMap, Handler}; @@ -23,7 +23,7 @@ pub trait HandlerExt { #[must_use] fn filter_command(self) -> Self where - C: BotCommand + Send + Sync + 'static; + C: BotCommands + Send + Sync + 'static; /// Passes [`Dialogue`] and `D` as handler dependencies. /// @@ -62,7 +62,7 @@ where { fn filter_command(self) -> Self where - C: BotCommand + Send + Sync + 'static, + C: BotCommands + Send + Sync + 'static, { self.chain(dptree::filter_map(move |message: Message, me: Me| { let bot_name = me.user.username.expect("Bots must have a username"); diff --git a/src/dispatching2/repls/commands_repl.rs b/src/dispatching2/repls/commands_repl.rs index 488d8313..13d5c8de 100644 --- a/src/dispatching2/repls/commands_repl.rs +++ b/src/dispatching2/repls/commands_repl.rs @@ -3,7 +3,7 @@ use crate::{ dispatching2::{HandlerExt, UpdateFilterExt}, error_handlers::LoggingErrorHandler, types::Update, - utils::command::BotCommand, + utils::command::BotCommands, }; use dptree::di::{DependencyMap, Injectable}; use std::{fmt::Debug, marker::PhantomData}; @@ -27,7 +27,7 @@ use teloxide_core::requests::Requester; #[cfg(feature = "ctrlc_handler")] pub async fn commands_repl<'a, R, Cmd, H, E, Args>(bot: R, handler: H, cmd: PhantomData) where - Cmd: BotCommand + Send + Sync + 'static, + Cmd: BotCommands + Send + Sync + 'static, H: Injectable, Args> + Send + Sync + 'static, R: Requester + Clone + Send + Sync + 'static, ::GetUpdates: Send, @@ -67,7 +67,7 @@ pub async fn commands_repl_with_listener<'a, R, Cmd, H, L, ListenerE, E, Args>( listener: L, _cmd: PhantomData, ) where - Cmd: BotCommand + Send + Sync + 'static, + Cmd: BotCommands + Send + Sync + 'static, H: Injectable, Args> + Send + Sync + 'static, L: UpdateListener + Send + 'a, ListenerE: Debug + Send + 'a, diff --git a/src/utils/command.rs b/src/utils/command.rs index 8faf06d8..6a8f337c 100644 --- a/src/utils/command.rs +++ b/src/utils/command.rs @@ -52,8 +52,9 @@ use std::{ }; use std::marker::PhantomData; +use teloxide_core::types::BotCommand; #[cfg(feature = "macros")] -pub use teloxide_macros::BotCommand; +pub use teloxide_macros::BotCommands; /// An enumeration of bot's commands. /// @@ -205,7 +206,7 @@ pub use teloxide_macros::BotCommand; /// /// [`FromStr`]: https://doc.rust-lang.org/std/str/trait.FromStr.html /// [`BotCommand`]: crate::utils::command::BotCommand -pub trait BotCommand: Sized { +pub trait BotCommands: Sized { /// Parses a command. /// /// `bot_username` is required to parse commands like @@ -218,12 +219,12 @@ pub trait BotCommand: Sized { /// (for example when `/help` command is used). fn descriptions() -> String; - /// Returns a vector of [`types::BotCommand`] that can be used with + /// Returns a vector of [`BotCommand`] that can be used with /// [`set_my_commands`]. /// - /// [`types::BotCommand`]: crate::types::BotCommand + /// [`BotCommand`]: crate::types::BotCommand /// [`set_my_commands`]: crate::requests::Requester::set_my_commands - fn bot_commands() -> Vec; + fn bot_commands() -> Vec; /// Returns `PhantomData` that is used as a param of [`commands_repl`] /// diff --git a/tests/command.rs b/tests/command.rs index ebdbab6f..a7c3183b 100644 --- a/tests/command.rs +++ b/tests/command.rs @@ -2,7 +2,7 @@ #![allow(clippy::nonstandard_macro_braces)] #[cfg(feature = "macros")] -use teloxide::utils::command::{BotCommand, ParseError}; +use teloxide::utils::command::{BotCommands, ParseError}; // We put tests here because macro expand in unit tests in module // teloxide::utils::command was a failure @@ -10,7 +10,7 @@ use teloxide::utils::command::{BotCommand, ParseError}; #[test] #[cfg(feature = "macros")] fn parse_command_with_args() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] enum DefaultCommands { Start(String), @@ -26,7 +26,7 @@ fn parse_command_with_args() { #[test] #[cfg(feature = "macros")] fn parse_command_with_non_string_arg() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] enum DefaultCommands { Start(i32), @@ -42,7 +42,7 @@ fn parse_command_with_non_string_arg() { #[test] #[cfg(feature = "macros")] fn attribute_prefix() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] enum DefaultCommands { #[command(prefix = "!")] @@ -59,7 +59,7 @@ fn attribute_prefix() { #[test] #[cfg(feature = "macros")] fn many_attributes() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] enum DefaultCommands { #[command(prefix = "!", description = "desc")] @@ -74,7 +74,7 @@ fn many_attributes() { #[test] #[cfg(feature = "macros")] fn global_attributes() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(prefix = "!", rename = "lowercase", description = "Bot commands")] enum DefaultCommands { #[command(prefix = "/")] @@ -90,7 +90,7 @@ fn global_attributes() { #[test] #[cfg(feature = "macros")] fn parse_command_with_bot_name() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] enum DefaultCommands { #[command(prefix = "/")] @@ -107,7 +107,7 @@ fn parse_command_with_bot_name() { #[test] #[cfg(feature = "macros")] fn parse_with_split() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] #[command(parse_with = "split")] enum DefaultCommands { @@ -124,7 +124,7 @@ fn parse_with_split() { #[test] #[cfg(feature = "macros")] fn parse_with_split2() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] #[command(parse_with = "split", separator = "|")] enum DefaultCommands { @@ -152,7 +152,7 @@ fn parse_custom_parser() { .map_err(|_| ParseError::Custom("First argument must be a integer!".to_owned().into())) } - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] enum DefaultCommands { #[command(parse_with = "custom_parse_function")] @@ -169,7 +169,7 @@ fn parse_custom_parser() { #[test] #[cfg(feature = "macros")] fn parse_named_fields() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] #[command(parse_with = "split")] enum DefaultCommands { @@ -186,7 +186,7 @@ fn parse_named_fields() { #[test] #[cfg(feature = "macros")] fn descriptions_off() { - #[derive(BotCommand, Debug, PartialEq)] + #[derive(BotCommands, Debug, PartialEq)] #[command(rename = "lowercase")] enum DefaultCommands { #[command(description = "off")]