Use doc attr for help message instead of #[command(description = "...")]

This commit is contained in:
TheAwiteb 2023-09-20 10:28:43 +03:00
parent aaf75fd82c
commit 3ce998e8b8
No known key found for this signature in database
GPG key ID: ABF818BD15DC2D34
6 changed files with 34 additions and 28 deletions

View file

@ -12,21 +12,19 @@ use teloxide::{prelude::*, types::ChatPermissions, utils::command::BotCommands};
// your commands in this format: // your commands in this format:
// %GENERAL-DESCRIPTION% // %GENERAL-DESCRIPTION%
// %PREFIX%%COMMAND% - %DESCRIPTION% // %PREFIX%%COMMAND% - %DESCRIPTION%
/// Use commands in format /%command% %num% %unit%
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command( #[command(rename_rule = "lowercase", parse_with = "split")]
rename_rule = "lowercase",
description = "Use commands in format /%command% %num% %unit%",
parse_with = "split"
)]
enum Command { enum Command {
#[command(description = "kick user from chat.")] /// Kick user from chat.
Kick, Kick,
#[command(description = "ban user in chat.")] /// Ban user in chat.
Ban { Ban {
time: u64, time: u64,
unit: UnitOfTime, unit: UnitOfTime,
}, },
#[command(description = "mute user in chat.")] /// Mute user in chat.
Mute { Mute {
time: u64, time: u64,
unit: UnitOfTime, unit: UnitOfTime,

View file

@ -9,12 +9,13 @@ use teloxide::{
utils::command::BotCommands, utils::command::BotCommands,
}; };
/// These commands are supported:
#[derive(BotCommands)] #[derive(BotCommands)]
#[command(rename_rule = "lowercase", description = "These commands are supported:")] #[command(rename_rule = "lowercase")]
enum Command { enum Command {
#[command(description = "Display this text")] /// Display this text
Help, Help,
#[command(description = "Start")] /// Start
Start, Start,
} }

View file

@ -10,14 +10,16 @@ async fn main() {
Command::repl(bot, answer).await; Command::repl(bot, answer).await;
} }
/// These commands are supported:
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "These commands are supported:")] #[command(rename_rule = "lowercase")]
enum Command { enum Command {
#[command(description = "display this text.")] /// Display this text.
Help, Help,
#[command(description = "handle a username.")] /// Handle a username.
Username(String), Username(String),
#[command(description = "handle a username and an age.", parse_with = "split")] /// Handle a username and an age.
#[command(parse_with = "split")]
UsernameAndAge { username: String, age: u8 }, UsernameAndAge { username: String, age: u8 },
} }

View file

@ -21,12 +21,13 @@ pub enum State {
GotNumber(i32), GotNumber(i32),
} }
/// These commands are supported:
#[derive(Clone, BotCommands)] #[derive(Clone, BotCommands)]
#[command(rename_rule = "lowercase", description = "These commands are supported:")] #[command(rename_rule = "lowercase")]
pub enum Command { pub enum Command {
#[command(description = "get your number.")] /// Get your number.
Get, Get,
#[command(description = "reset your number.")] /// Reset your number.
Reset, Reset,
} }

View file

@ -95,21 +95,24 @@ struct ConfigParameters {
maintainer_username: Option<String>, maintainer_username: Option<String>,
} }
/// Simple commands
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "Simple commands")] #[command(rename_rule = "lowercase")]
enum SimpleCommand { enum SimpleCommand {
#[command(description = "shows this message.")] /// Shows this message.
Help, Help,
#[command(description = "shows maintainer info.")] /// Shows maintainer info.
Maintainer, Maintainer,
#[command(description = "shows your ID.")] /// Shows your ID.
MyId, MyId,
} }
/// Maintainer commands
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "Maintainer commands")] #[command(rename_rule = "lowercase")]
enum MaintainerCommands { enum MaintainerCommands {
#[command(parse_with = "split", description = "generate a number within range")] /// Generate a number within range
#[command(parse_with = "split")]
Rand { from: u64, to: u64 }, Rand { from: u64, to: u64 },
} }

View file

@ -32,14 +32,15 @@ pub enum State {
}, },
} }
/// These commands are supported:
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "These commands are supported:")] #[command(rename_rule = "lowercase")]
enum Command { enum Command {
#[command(description = "display this text.")] /// Display this text.
Help, Help,
#[command(description = "start the purchase procedure.")] /// Start the purchase procedure.
Start, Start,
#[command(description = "cancel the purchase procedure.")] /// Cancel the purchase procedure.
Cancel, Cancel,
} }