Module teloxide::utils::command [−][src]
Command parsers.
You can either create an enum
with derived BotCommand
, containing
commands of your bot, or use functions, which split input text into a string
command with its arguments.
Using BotCommand
use teloxide::utils::command::BotCommand; type UnitOfTime = u8; #[derive(BotCommand, PartialEq, Debug)] #[command(rename = "lowercase", parse_with = "split")] enum AdminCommand { Mute(UnitOfTime, char), Ban(UnitOfTime, char), } let command = AdminCommand::parse("/ban 5 h", "bot_name").unwrap(); assert_eq!(command, AdminCommand::Ban(5, 'h'));
Using parse_command
use teloxide::utils::command::parse_command; let (command, args) = parse_command("/ban@MyBotName 3 hours", "MyBotName").unwrap(); assert_eq!(command, "ban"); assert_eq!(args, vec!["3", "hours"]);
Using parse_command_with_prefix
use teloxide::utils::command::parse_command_with_prefix; let text = "!ban 3 hours"; let (command, args) = parse_command_with_prefix("!", text, "").unwrap(); assert_eq!(command, "ban"); assert_eq!(args, vec!["3", "hours"]);
See examples/admin_bot as a more complicated examples.
Enums
ParseError | Errors returned from |
Traits
BotCommand | An enumeration of bot’s commands. |
Functions
parse_command | Parses a string into a command with args. |
parse_command_with_prefix | Parses a string into a command with args (custom prefix). |
Type Definitions
BotName | |
PrefixedBotCommand |
Derive Macros
BotCommand | macros |