use crate::chat::ChatId;
use crate::user::User;
use crate::{JsonMethod, TelegramMethod};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub struct BotCommand {
pub command: String,
pub description: String,
}
#[derive(Clone, Serialize)]
pub enum BotCommandScope {
Default,
AllPrivateChats,
AllGroupChats,
AllChatAdministrators,
Chat {
chat_id: ChatId,
},
ChatAdministrators {
chat_id: ChatId,
},
ChatMember {
chat_id: ChatId,
user_id: i64,
},
}
#[derive(Clone, Serialize)]
pub struct GetMe;
impl TelegramMethod for GetMe {
type Response = User;
fn name() -> &'static str {
"getMe"
}
}
impl JsonMethod for GetMe {}
#[derive(Clone, Serialize)]
pub struct LogOut;
impl TelegramMethod for LogOut {
type Response = bool;
fn name() -> &'static str {
"logOut"
}
}
impl JsonMethod for LogOut {}
#[derive(Clone, Serialize)]
pub struct Close;
impl TelegramMethod for Close {
type Response = bool;
fn name() -> &'static str {
"close"
}
}
impl JsonMethod for Close {}
#[derive(Clone, Serialize)]
pub struct SetMyCommands {
pub commands: Vec<BotCommand>,
#[serde(skip_serializing_if = "Option::is_none")]
pub scope: Option<BotCommandScope>,
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
}
impl SetMyCommands {
pub fn new(commands: impl Into<Vec<BotCommand>>) -> Self {
Self {
commands: commands.into(),
scope: None,
language_code: None,
}
}
pub fn with_scope(self, scope: BotCommandScope) -> Self {
Self {
scope: Some(scope),
..self
}
}
pub fn with_language_code(self, language_code: impl Into<String>) -> Self {
Self {
language_code: Some(language_code.into()),
..self
}
}
}
impl TelegramMethod for SetMyCommands {
type Response = bool;
fn name() -> &'static str {
"setMyCommands"
}
}
impl JsonMethod for SetMyCommands {}
#[derive(Clone, Serialize)]
pub struct DeleteMyCommands {
#[serde(skip_serializing_if = "Option::is_none")]
pub scope: Option<BotCommandScope>,
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
}
impl DeleteMyCommands {
pub fn new() -> Self {
Self {
scope: None,
language_code: None,
}
}
pub fn with_scope(self, scope: BotCommandScope) -> Self {
Self {
scope: Some(scope),
..self
}
}
pub fn with_language_code(self, language_code: impl Into<String>) -> Self {
Self {
language_code: Some(language_code.into()),
..self
}
}
}
impl TelegramMethod for DeleteMyCommands {
type Response = bool;
fn name() -> &'static str {
"deleteMyCommands"
}
}
#[derive(Clone, Serialize)]
pub struct GetMyCommands {
#[serde(skip_serializing_if = "Option::is_none")]
pub scope: Option<BotCommandScope>,
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
}
impl GetMyCommands {
pub fn new() -> Self {
Self {
scope: None,
language_code: None,
}
}
pub fn with_scope(self, scope: BotCommandScope) -> Self {
Self {
scope: Some(scope),
..self
}
}
pub fn with_language_code(self, language_code: impl Into<String>) -> Self {
Self {
language_code: Some(language_code.into()),
..self
}
}
}
impl TelegramMethod for GetMyCommands {
type Response = Vec<BotCommand>;
fn name() -> &'static str {
"getMyCommands"
}
}