fixed documentation

This commit is contained in:
p0lunin 2020-02-22 22:53:11 +02:00
parent 43a8c21b68
commit 61f06a5e7a
5 changed files with 10 additions and 9 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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"
);
}

View file

@ -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)?;