1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use super::handlers::CommandHandlerFunc;
use crate::{model::BotCommand, utils::result::Error};
#[derive(Clone)]
pub enum CommandTypes {
Default(CommandHandlerFunc),
}
#[derive(Clone)]
pub struct CommandOptions {
pub name: &'static str,
pub description: &'static str,
}
#[derive(Clone)]
pub struct TelegramCommand {
pub options: &'static CommandOptions,
pub command: CommandTypes,
}
impl TelegramCommand {
pub fn get_bot_command(&self) -> BotCommand {
BotCommand {
command: self.options.name.to_owned(),
description: self.options.description.to_owned(),
}
}
}
#[derive(Debug, Clone)]
pub struct CommandError(pub String);
impl<T: std::fmt::Display> From<T> for CommandError {
#[inline]
fn from(d: T) -> Self {
CommandError(d.to_string())
}
}
pub type CommandResult = ::std::result::Result<(), CommandError>;
impl From<CommandError> for Error {
#[inline]
fn from(d: CommandError) -> Self {
Error::Command(d)
}
}