mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
fixed documentation
This commit is contained in:
parent
43a8c21b68
commit
61f06a5e7a
5 changed files with 10 additions and 9 deletions
|
@ -179,7 +179,7 @@ async fn handle_commands(rx: DispatcherHandlerRx<Message>) {
|
|||
// Only iterate through messages from groups:
|
||||
rx.filter(|cx| future::ready(cx.update.chat.is_group()))
|
||||
// Only iterate through commands in a proper format:
|
||||
.commands::<Command>()
|
||||
.commands::<Command>(panic!("Insert here bot username"))
|
||||
// Execute all incoming commands concurrently:
|
||||
.for_each_concurrent(None, |(cx, command, args)| async move {
|
||||
action(cx, command, &args).await.log_on_error().await;
|
||||
|
|
|
@ -32,7 +32,7 @@ async fn answer(
|
|||
|
||||
async fn handle_commands(rx: DispatcherHandlerRx<Message>) {
|
||||
// Only iterate through commands in a proper format:
|
||||
rx.commands::<Command>()
|
||||
rx.commands::<Command>(panic!("Insert here bot username"))
|
||||
// Execute all incoming commands concurrently:
|
||||
.for_each_concurrent(None, |(cx, command, _)| async move {
|
||||
answer(cx, command).await.log_on_error().await;
|
||||
|
|
|
@ -108,7 +108,7 @@
|
|||
//!
|
||||
//! async fn handle_commands(rx: DispatcherHandlerRx<Message>) {
|
||||
//! // Only iterate through commands in a proper format:
|
||||
//! rx.commands::<Command>()
|
||||
//! rx.commands::<Command>("bot_name")
|
||||
//! // Execute all incoming commands concurrently:
|
||||
//! .for_each_concurrent(None, |(cx, command, _)| async move {
|
||||
//! answer(cx, command).await.log_on_error().await;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
//! Ban,
|
||||
//! }
|
||||
//!
|
||||
//! let (command, args) = AdminCommand::parse("/ban 3 hours").unwrap();
|
||||
//! let (command, args) = AdminCommand::parse("/ban 3 hours", "bot_name").unwrap();
|
||||
//! assert_eq!(command, AdminCommand::Ban);
|
||||
//! assert_eq!(args, vec!["3", "hours"]);
|
||||
//! ```
|
||||
|
@ -61,7 +61,7 @@ pub use teloxide_macros::BotCommand;
|
|||
/// Ban,
|
||||
/// }
|
||||
///
|
||||
/// let (command, args) = AdminCommand::parse("/ban 5 h").unwrap();
|
||||
/// let (command, args) = AdminCommand::parse("/ban 5 h", "bot_name").unwrap();
|
||||
/// assert_eq!(command, AdminCommand::Ban);
|
||||
/// assert_eq!(args, vec!["5", "h"]);
|
||||
/// ```
|
||||
|
@ -209,7 +209,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(
|
||||
DefaultCommands::descriptions(),
|
||||
"!start - desc\n/help - \n"
|
||||
"!start - desc\n/help\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(
|
||||
DefaultCommands::descriptions(),
|
||||
"Bot commands\n/start - \n!help - \n"
|
||||
"Bot commands\n/start\n!help\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,11 +109,12 @@ pub fn derive_telegram_command_enum(tokens: TokenStream) -> TokenStream {
|
|||
}
|
||||
fn parse<'a, 'b>(s: &'a str, bot_name: &'b str) -> Option<(Self, Vec<&'a str>)> {
|
||||
let mut words = s.split_whitespace();
|
||||
let splited = words.next()?.split('@');
|
||||
let mut splited = words.next()?.split('@');
|
||||
let command_raw = splited.next()?;
|
||||
let bot = splited.next();
|
||||
match bot {
|
||||
Some(name) if name == bot_name || None => {}
|
||||
Some(name) if name == bot_name => {}
|
||||
None => {}
|
||||
_ => return None,
|
||||
}
|
||||
let command = Self::try_from(command_raw)?;
|
||||
|
|
Loading…
Add table
Reference in a new issue