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:
// %GENERAL-DESCRIPTION%
// %PREFIX%%COMMAND% - %DESCRIPTION%
/// Use commands in format /%command% %num% %unit%
#[derive(BotCommands, Clone)]
#[command(
rename_rule = "lowercase",
description = "Use commands in format /%command% %num% %unit%",
parse_with = "split"
)]
#[command(rename_rule = "lowercase", parse_with = "split")]
enum Command {
#[command(description = "kick user from chat.")]
/// Kick user from chat.
Kick,
#[command(description = "ban user in chat.")]
/// Ban user in chat.
Ban {
time: u64,
unit: UnitOfTime,
},
#[command(description = "mute user in chat.")]
/// Mute user in chat.
Mute {
time: u64,
unit: UnitOfTime,

View file

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

View file

@ -10,14 +10,16 @@ async fn main() {
Command::repl(bot, answer).await;
}
/// These commands are supported:
#[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "These commands are supported:")]
#[command(rename_rule = "lowercase")]
enum Command {
#[command(description = "display this text.")]
/// Display this text.
Help,
#[command(description = "handle a username.")]
/// Handle a username.
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 },
}

View file

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

View file

@ -95,21 +95,24 @@ struct ConfigParameters {
maintainer_username: Option<String>,
}
/// Simple commands
#[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "Simple commands")]
#[command(rename_rule = "lowercase")]
enum SimpleCommand {
#[command(description = "shows this message.")]
/// Shows this message.
Help,
#[command(description = "shows maintainer info.")]
/// Shows maintainer info.
Maintainer,
#[command(description = "shows your ID.")]
/// Shows your ID.
MyId,
}
/// Maintainer commands
#[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "Maintainer commands")]
#[command(rename_rule = "lowercase")]
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 },
}

View file

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