Merge pull request #99 from teloxide/tba_5.3

Update to Telegram Bot API 5.3
This commit is contained in:
Waffle Lapkin 2021-07-04 16:19:07 +03:00 committed by GitHub
commit 399ede26ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 416 additions and 120 deletions

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Getters for fields nested in `Chat` ([#80][pr80])
- API errors: `ApiError::NotEnoughRightsToManagePins`, `ApiError::BotKickedFromSupergroup` ([#84][pr84])
- Telegram bot API 5.2 support ([#86][pr86])
- Telegram bot API 5.3 support ([#99][pr99])
- `net::default_reqwest_settings` function ([#90][pr90])
[pr75]: https://github.com/teloxide/teloxide-core/pull/75
@ -26,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[pr86]: https://github.com/teloxide/teloxide-core/pull/86
[pr90]: https://github.com/teloxide/teloxide-core/pull/90
[pr96]: https://github.com/teloxide/teloxide-core/pull/96
[pr99]: https://github.com/teloxide/teloxide-core/pull/99
### Changed

View file

@ -15,7 +15,7 @@
<img src="https://img.shields.io/badge/license-MIT-blue.svg">
</a>
<a href="https://core.telegram.org/bots/api">
<img src="https://img.shields.io/badge/API%20coverage-Up%20to%205.2%20(inclusively)-green.svg">
<img src="https://img.shields.io/badge/API%20coverage-Up%20to%205.3%20(inclusively)-green.svg">
</a>
<a href="https://crates.io/crates/teloxide_core">
<img src="https://img.shields.io/crates/v/teloxide_core.svg">

View file

@ -89,14 +89,14 @@ where
edit_message_live_location, edit_message_live_location_inline,
stop_message_live_location, stop_message_live_location_inline, send_venue,
send_contact, send_poll, send_dice, send_chat_action, get_user_profile_photos,
get_file, kick_chat_member, unban_chat_member, restrict_chat_member,
get_file, kick_chat_member, ban_chat_member, unban_chat_member, restrict_chat_member,
promote_chat_member, set_chat_administrator_custom_title, set_chat_permissions,
export_chat_invite_link, create_chat_invite_link, edit_chat_invite_link,
revoke_chat_invite_link, set_chat_photo, delete_chat_photo, set_chat_title,
set_chat_description, pin_chat_message, unpin_chat_message, unpin_all_chat_messages,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count,get_chat_member,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count, get_chat_member_count, get_chat_member,
set_chat_sticker_set, delete_chat_sticker_set, answer_callback_query,
set_my_commands, get_my_commands, answer_inline_query, edit_message_text,
set_my_commands, get_my_commands, delete_my_commands, answer_inline_query, edit_message_text,
edit_message_text_inline, edit_message_caption, edit_message_caption_inline,
edit_message_media, edit_message_media_inline, edit_message_reply_markup,
edit_message_reply_markup_inline, stop_poll, delete_message, send_sticker,

View file

@ -96,14 +96,14 @@ where
edit_message_live_location, edit_message_live_location_inline,
stop_message_live_location, stop_message_live_location_inline, send_venue,
send_contact, send_poll, send_dice, send_chat_action, get_user_profile_photos,
get_file, kick_chat_member, unban_chat_member, restrict_chat_member,
get_file, kick_chat_member, ban_chat_member, unban_chat_member, restrict_chat_member,
promote_chat_member, set_chat_administrator_custom_title, set_chat_permissions,
export_chat_invite_link, create_chat_invite_link, edit_chat_invite_link,
revoke_chat_invite_link, set_chat_photo, delete_chat_photo, set_chat_title,
set_chat_description, pin_chat_message, unpin_chat_message, unpin_all_chat_messages,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count,get_chat_member,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count, get_chat_member_count, get_chat_member,
set_chat_sticker_set, delete_chat_sticker_set, answer_callback_query,
set_my_commands, get_my_commands, answer_inline_query, edit_message_text,
set_my_commands, get_my_commands, delete_my_commands, answer_inline_query, edit_message_text,
edit_message_text_inline, edit_message_caption, edit_message_caption_inline,
edit_message_media, edit_message_media_inline, edit_message_reply_markup,
edit_message_reply_markup_inline, stop_poll, delete_message, send_sticker,
@ -111,7 +111,8 @@ where
add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set,
set_sticker_set_thumb, send_invoice, answer_shipping_query,
answer_pre_checkout_query, set_passport_data_errors, send_game,
set_game_score, set_game_score_inline, get_game_high_scores, get_updates_fault_tolerant => f, fty
set_game_score, set_game_score_inline, get_game_high_scores,
get_updates_fault_tolerant => f, fty
}
}

View file

@ -107,14 +107,14 @@ impl<B: Requester> Requester for DefaultParseMode<B> {
edit_message_live_location, edit_message_live_location_inline,
stop_message_live_location, stop_message_live_location_inline, send_venue,
send_contact, send_dice, send_chat_action, get_user_profile_photos,
get_file, kick_chat_member, unban_chat_member, restrict_chat_member,
get_file, kick_chat_member, ban_chat_member, unban_chat_member, restrict_chat_member,
promote_chat_member, set_chat_administrator_custom_title, set_chat_permissions,
export_chat_invite_link, create_chat_invite_link, edit_chat_invite_link,
revoke_chat_invite_link, set_chat_photo, delete_chat_photo, set_chat_title,
set_chat_description, pin_chat_message, unpin_chat_message, unpin_all_chat_messages,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count,get_chat_member,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count, get_chat_member_count, get_chat_member,
set_chat_sticker_set, delete_chat_sticker_set, answer_callback_query,
set_my_commands, get_my_commands, answer_inline_query,
set_my_commands, get_my_commands, delete_my_commands, answer_inline_query,
edit_message_media, edit_message_media_inline, edit_message_reply_markup,
edit_message_reply_markup_inline, stop_poll, delete_message, send_sticker,
get_sticker_set, upload_sticker_file, create_new_sticker_set,

View file

@ -590,15 +590,15 @@ where
get_me, log_out, close, get_updates, set_webhook, delete_webhook, get_webhook_info,
edit_message_live_location, edit_message_live_location_inline,
stop_message_live_location, stop_message_live_location_inline,
send_chat_action, get_user_profile_photos, get_file, kick_chat_member,
send_chat_action, get_user_profile_photos, get_file, kick_chat_member, ban_chat_member,
unban_chat_member, restrict_chat_member, promote_chat_member,
set_chat_administrator_custom_title, set_chat_permissions,
export_chat_invite_link, create_chat_invite_link, edit_chat_invite_link,
revoke_chat_invite_link, set_chat_photo, delete_chat_photo, set_chat_title,
set_chat_description, pin_chat_message, unpin_chat_message, unpin_all_chat_messages,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count, get_chat_member_count,
get_chat_member, set_chat_sticker_set, delete_chat_sticker_set,
answer_callback_query, set_my_commands, get_my_commands, answer_inline_query,
answer_callback_query, set_my_commands, get_my_commands, delete_my_commands, answer_inline_query,
edit_message_text, edit_message_text_inline, edit_message_caption,
edit_message_caption_inline, edit_message_media, edit_message_media_inline,
edit_message_reply_markup, edit_message_reply_markup_inline, stop_poll,

View file

@ -337,6 +337,15 @@ impl Requester for Bot {
)
}
type BanChatMember = JsonRequest<payloads::BanChatMember>;
fn ban_chat_member<C>(&self, chat_id: C, user_id: i64) -> Self::BanChatMember
where
C: Into<ChatId>,
{
Self::BanChatMember::new(self.clone(), payloads::BanChatMember::new(chat_id, user_id))
}
type UnbanChatMember = JsonRequest<payloads::UnbanChatMember>;
fn unban_chat_member<C>(&self, chat_id: C, user_id: i64) -> Self::UnbanChatMember
@ -557,6 +566,15 @@ impl Requester for Bot {
Self::GetChatMembersCount::new(self.clone(), payloads::GetChatMembersCount::new(chat_id))
}
type GetChatMemberCount = JsonRequest<payloads::GetChatMemberCount>;
fn get_chat_member_count<C>(&self, chat_id: C) -> Self::GetChatMemberCount
where
C: Into<ChatId>,
{
Self::GetChatMemberCount::new(self.clone(), payloads::GetChatMemberCount::new(chat_id))
}
type GetChatMember = JsonRequest<payloads::GetChatMember>;
fn get_chat_member<C>(&self, chat_id: C, user_id: i64) -> Self::GetChatMember
@ -615,6 +633,12 @@ impl Requester for Bot {
Self::GetMyCommands::new(self.clone(), payloads::GetMyCommands::new())
}
type DeleteMyCommands = JsonRequest<payloads::DeleteMyCommands>;
fn delete_my_commands(&self) -> Self::DeleteMyCommands {
Self::DeleteMyCommands::new(self.clone(), payloads::DeleteMyCommands::new())
}
type AnswerInlineQuery = JsonRequest<payloads::AnswerInlineQuery>;
fn answer_inline_query<I, R>(&self, inline_query_id: I, results: R) -> Self::AnswerInlineQuery

View file

@ -1,7 +1,7 @@
//! Core part of the [`teloxide`] library.
//!
//! This library provides tools for making requests to the [Telegram Bot API]
//! (Currently, version `5.1` is supported) with ease. The library is fully
//! (Currently, version `5.3` is supported) with ease. The library is fully
//! asynchronouns and built using [`tokio`].
//!
//!```toml

View file

@ -684,6 +684,14 @@ macro_rules! requester_forward {
$body!(get_file this (file_id: F))
}
};
(@method ban_chat_member $body:ident $ty:ident) => {
type BanChatMember = $ty![BanChatMember];
fn ban_chat_member<C>(&self, chat_id: C, user_id: i64) -> Self::BanChatMember where C: Into<ChatId> {
let this = self;
$body!(ban_chat_member this (chat_id: C, user_id: i64))
}
};
(@method kick_chat_member $body:ident $ty:ident) => {
type KickChatMember = $ty![KickChatMember];
@ -848,6 +856,14 @@ macro_rules! requester_forward {
$body!(get_chat_administrators this (chat_id: C))
}
};
(@method get_chat_member_count $body:ident $ty:ident) => {
type GetChatMemberCount = $ty![GetChatMemberCount];
fn get_chat_member_count<C>(&self, chat_id: C) -> Self::GetChatMemberCount where C: Into<ChatId> {
let this = self;
$body!(get_chat_member_count this (chat_id: C))
}
};
(@method get_chat_members_count $body:ident $ty:ident) => {
type GetChatMembersCount = $ty![GetChatMembersCount];
@ -905,6 +921,14 @@ macro_rules! requester_forward {
$body!(get_my_commands this ())
}
};
(@method delete_my_commands $body:ident $ty:ident) => {
type DeleteMyCommands = $ty![DeleteMyCommands];
fn delete_my_commands(&self) -> Self::DeleteMyCommands {
let this = self;
$body!(delete_my_commands this ())
}
};
(@method answer_inline_query $body:ident $ty:ident) => {
type AnswerInlineQuery = $ty![AnswerInlineQuery];

View file

@ -25,6 +25,7 @@ mod answer_callback_query;
mod answer_inline_query;
mod answer_pre_checkout_query;
mod answer_shipping_query;
mod ban_chat_member;
mod close;
mod copy_message;
mod create_chat_invite_link;
@ -32,6 +33,7 @@ mod create_new_sticker_set;
mod delete_chat_photo;
mod delete_chat_sticker_set;
mod delete_message;
mod delete_my_commands;
mod delete_sticker_from_set;
mod delete_webhook;
mod edit_chat_invite_link;
@ -50,6 +52,7 @@ mod forward_message;
mod get_chat;
mod get_chat_administrators;
mod get_chat_member;
mod get_chat_member_count;
mod get_chat_members_count;
mod get_file;
mod get_game_high_scores;
@ -110,6 +113,7 @@ pub use answer_callback_query::{AnswerCallbackQuery, AnswerCallbackQuerySetters}
pub use answer_inline_query::{AnswerInlineQuery, AnswerInlineQuerySetters};
pub use answer_pre_checkout_query::{AnswerPreCheckoutQuery, AnswerPreCheckoutQuerySetters};
pub use answer_shipping_query::{AnswerShippingQuery, AnswerShippingQuerySetters};
pub use ban_chat_member::{BanChatMember, BanChatMemberSetters};
pub use close::{Close, CloseSetters};
pub use copy_message::{CopyMessage, CopyMessageSetters};
pub use create_chat_invite_link::{CreateChatInviteLink, CreateChatInviteLinkSetters};
@ -117,6 +121,7 @@ pub use create_new_sticker_set::{CreateNewStickerSet, CreateNewStickerSetSetters
pub use delete_chat_photo::{DeleteChatPhoto, DeleteChatPhotoSetters};
pub use delete_chat_sticker_set::{DeleteChatStickerSet, DeleteChatStickerSetSetters};
pub use delete_message::{DeleteMessage, DeleteMessageSetters};
pub use delete_my_commands::{DeleteMyCommands, DeleteMyCommandsSetters};
pub use delete_sticker_from_set::{DeleteStickerFromSet, DeleteStickerFromSetSetters};
pub use delete_webhook::{DeleteWebhook, DeleteWebhookSetters};
pub use edit_chat_invite_link::{EditChatInviteLink, EditChatInviteLinkSetters};
@ -139,6 +144,7 @@ pub use forward_message::{ForwardMessage, ForwardMessageSetters};
pub use get_chat::{GetChat, GetChatSetters};
pub use get_chat_administrators::{GetChatAdministrators, GetChatAdministratorsSetters};
pub use get_chat_member::{GetChatMember, GetChatMemberSetters};
pub use get_chat_member_count::{GetChatMemberCount, GetChatMemberCountSetters};
pub use get_chat_members_count::{GetChatMembersCount, GetChatMembersCountSetters};
pub use get_file::{GetFile, GetFileSetters};
pub use get_game_high_scores::{GetGameHighScores, GetGameHighScoresSetters};

View file

@ -0,0 +1,32 @@
// This file is auto generated by [`cg`] from [`schema`].
//
// **DO NOT EDIT THIS FILE**,
//
// Edit `cg` or `schema` instead.
//
// [cg]: https://github.com/teloxide/cg
// [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema
use serde::Serialize;
use crate::types::{ChatId, True};
impl_payload! {
/// Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless [unbanned] first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns _True_ on success.
///
/// [unbanned]: crate::payloads::UnbanChatMember
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)]
pub BanChatMember (BanChatMemberSetters) => True {
required {
/// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
pub chat_id: ChatId [into],
/// Unique identifier of the target user
pub user_id: i64,
}
optional {
/// Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
pub until_date: u64,
/// Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.
pub revoke_messages: bool,
}
}
}

View file

@ -0,0 +1,27 @@
// This file is auto generated by [`cg`] from [`schema`].
//
// **DO NOT EDIT THIS FILE**,
//
// Edit `cg` or `schema` instead.
//
// [cg]: https://github.com/teloxide/cg
// [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema
use serde::Serialize;
use crate::types::{BotCommandScope, True};
impl_payload! {
/// Use this method to delete the list of the bot's commands for the given scope and user language. After deletion, [higher level commands] will be shown to affected users. Returns _True_ on success.
///
/// [higher level commands]: https://core.telegram.org/bots/api#determining-list-of-commands
#[derive(Debug, PartialEq, Eq, Hash, Default, Clone, Serialize)]
pub DeleteMyCommands (DeleteMyCommandsSetters) => True {
optional {
/// A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
pub scope: BotCommandScope,
/// A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
pub language_code: String [into],
}
}
}

View file

@ -0,0 +1,22 @@
// This file is auto generated by [`cg`] from [`schema`].
//
// **DO NOT EDIT THIS FILE**,
//
// Edit `cg` or `schema` instead.
//
// [cg]: https://github.com/teloxide/cg
// [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema
use serde::Serialize;
use crate::types::ChatId;
impl_payload! {
/// Use this method to get the number of members in a chat. Returns _Int_ on success.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)]
pub GetChatMemberCount (GetChatMemberCountSetters) => u32 {
required {
/// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
pub chat_id: ChatId [into],
}
}
}

View file

@ -8,7 +8,7 @@
// [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema
use serde::Serialize;
use crate::types::BotCommand;
use crate::types::{BotCommand, BotCommandScope};
impl_payload! {
/// Use this method to get the current list of the bot's commands. Requires no parameters. Returns Array of [`BotCommand`] on success.
@ -17,5 +17,11 @@ impl_payload! {
#[derive(Debug, PartialEq, Eq, Hash, Default, Clone, Serialize)]
pub GetMyCommands (GetMyCommandsSetters) => Vec<BotCommand> {
optional {
/// A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
pub scope: BotCommandScope,
/// A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
pub language_code: String [into],
}
}
}

View file

@ -8,7 +8,7 @@
// [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema
use serde::Serialize;
use crate::types::{BotCommand, True};
use crate::types::{BotCommand, BotCommandScope, True};
impl_payload! {
/// Use this method to change the list of the bot's commands. Returns _True_ on success.
@ -18,5 +18,11 @@ impl_payload! {
/// A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
pub commands: Vec<BotCommand> [collect],
}
optional {
/// A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
pub scope: BotCommandScope,
/// A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands
pub language_code: String [into],
}
}
}

View file

@ -9,25 +9,26 @@
#[doc(no_inline)]
pub use crate::payloads::{
AddStickerToSetSetters as _, AnswerCallbackQuerySetters as _, AnswerInlineQuerySetters as _,
AnswerPreCheckoutQuerySetters as _, AnswerShippingQuerySetters as _, CloseSetters as _,
CopyMessageSetters as _, CreateChatInviteLinkSetters as _, CreateNewStickerSetSetters as _,
DeleteChatPhotoSetters as _, DeleteChatStickerSetSetters as _, DeleteMessageSetters as _,
DeleteStickerFromSetSetters as _, DeleteWebhookSetters as _, EditChatInviteLinkSetters as _,
AnswerPreCheckoutQuerySetters as _, AnswerShippingQuerySetters as _, BanChatMemberSetters as _,
CloseSetters as _, CopyMessageSetters as _, CreateChatInviteLinkSetters as _,
CreateNewStickerSetSetters as _, DeleteChatPhotoSetters as _, DeleteChatStickerSetSetters as _,
DeleteMessageSetters as _, DeleteMyCommandsSetters as _, DeleteStickerFromSetSetters as _,
DeleteWebhookSetters as _, EditChatInviteLinkSetters as _,
EditMessageCaptionInlineSetters as _, EditMessageCaptionSetters as _,
EditMessageLiveLocationInlineSetters as _, EditMessageLiveLocationSetters as _,
EditMessageMediaInlineSetters as _, EditMessageMediaSetters as _,
EditMessageReplyMarkupInlineSetters as _, EditMessageReplyMarkupSetters as _,
EditMessageTextInlineSetters as _, EditMessageTextSetters as _,
ExportChatInviteLinkSetters as _, ForwardMessageSetters as _,
GetChatAdministratorsSetters as _, GetChatMemberSetters as _, GetChatMembersCountSetters as _,
GetChatSetters as _, GetFileSetters as _, GetGameHighScoresSetters as _, GetMeSetters as _,
GetMyCommandsSetters as _, GetStickerSetSetters as _, GetUpdatesSetters as _,
GetUserProfilePhotosSetters as _, GetWebhookInfoSetters as _, KickChatMemberSetters as _,
LeaveChatSetters as _, LogOutSetters as _, PinChatMessageSetters as _,
PromoteChatMemberSetters as _, RestrictChatMemberSetters as _,
RevokeChatInviteLinkSetters as _, SendAnimationSetters as _, SendAudioSetters as _,
SendChatActionSetters as _, SendContactSetters as _, SendDiceSetters as _,
SendDocumentSetters as _, SendGameSetters as _, SendInvoiceSetters as _,
GetChatAdministratorsSetters as _, GetChatMemberCountSetters as _, GetChatMemberSetters as _,
GetChatMembersCountSetters as _, GetChatSetters as _, GetFileSetters as _,
GetGameHighScoresSetters as _, GetMeSetters as _, GetMyCommandsSetters as _,
GetStickerSetSetters as _, GetUpdatesSetters as _, GetUserProfilePhotosSetters as _,
GetWebhookInfoSetters as _, KickChatMemberSetters as _, LeaveChatSetters as _,
LogOutSetters as _, PinChatMessageSetters as _, PromoteChatMemberSetters as _,
RestrictChatMemberSetters as _, RevokeChatInviteLinkSetters as _, SendAnimationSetters as _,
SendAudioSetters as _, SendChatActionSetters as _, SendContactSetters as _,
SendDiceSetters as _, SendDocumentSetters as _, SendGameSetters as _, SendInvoiceSetters as _,
SendLocationSetters as _, SendMediaGroupSetters as _, SendMessageSetters as _,
SendPhotoSetters as _, SendPollSetters as _, SendStickerSetters as _, SendVenueSetters as _,
SendVideoNoteSetters as _, SendVideoSetters as _, SendVoiceSetters as _,

View file

@ -318,6 +318,13 @@ pub trait Requester {
where
F: Into<String>;
type BanChatMember: Request<Payload = BanChatMember, Err = Self::Err>;
/// For Telegram documentation see [`BanChatMember`].
fn ban_chat_member<C>(&self, chat_id: C, user_id: i64) -> Self::BanChatMember
where
C: Into<ChatId>;
type KickChatMember: Request<Payload = KickChatMember, Err = Self::Err>;
/// For Telegram documentation see [`KickChatMember`].
@ -483,6 +490,13 @@ pub trait Requester {
where
C: Into<ChatId>;
type GetChatMemberCount: Request<Payload = GetChatMemberCount, Err = Self::Err>;
/// For Telegram documentation see [`GetChatMemberCount`].
fn get_chat_member_count<C>(&self, chat_id: C) -> Self::GetChatMemberCount
where
C: Into<ChatId>;
type GetChatMembersCount: Request<Payload = GetChatMembersCount, Err = Self::Err>;
/// For Telegram documentation see [`GetChatMembersCount`].
@ -535,6 +549,11 @@ pub trait Requester {
/// For Telegram documentation see [`GetMyCommands`].
fn get_my_commands(&self) -> Self::GetMyCommands;
type DeleteMyCommands: Request<Payload = DeleteMyCommands, Err = Self::Err>;
/// For Telegram documentation see [`DeleteMyCommands`].
fn delete_my_commands(&self) -> Self::DeleteMyCommands;
type AnswerInlineQuery: Request<Payload = AnswerInlineQuery, Err = Self::Err>;
/// For Telegram documentation see [`AnswerInlineQuery`].
@ -831,14 +850,14 @@ macro_rules! forward_all {
edit_message_live_location, edit_message_live_location_inline,
stop_message_live_location, stop_message_live_location_inline, send_venue,
send_contact, send_poll, send_dice, send_chat_action, get_user_profile_photos,
get_file, kick_chat_member, unban_chat_member, restrict_chat_member,
get_file, kick_chat_member, ban_chat_member, unban_chat_member, restrict_chat_member,
promote_chat_member, set_chat_administrator_custom_title, set_chat_permissions,
export_chat_invite_link, create_chat_invite_link, edit_chat_invite_link,
revoke_chat_invite_link, set_chat_photo, delete_chat_photo, set_chat_title,
set_chat_description, pin_chat_message, unpin_chat_message, unpin_all_chat_messages,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count,get_chat_member,
leave_chat, get_chat, get_chat_administrators, get_chat_members_count, get_chat_member_count, get_chat_member,
set_chat_sticker_set, delete_chat_sticker_set, answer_callback_query,
set_my_commands, get_my_commands, answer_inline_query, edit_message_text,
set_my_commands, get_my_commands, delete_my_commands, answer_inline_query, edit_message_text,
edit_message_text_inline, edit_message_caption, edit_message_caption_inline,
edit_message_media, edit_message_media_inline, edit_message_reply_markup,
edit_message_reply_markup_inline, stop_poll, delete_message, send_sticker,

View file

@ -4,6 +4,7 @@ pub use allowed_update::*;
pub use animation::*;
pub use audio::*;
pub use bot_command::*;
pub use bot_command_scope::*;
pub use callback_game::*;
pub use callback_query::*;
pub use chat::*;
@ -108,6 +109,7 @@ mod allowed_update;
mod animation;
mod audio;
mod bot_command;
mod bot_command_scope;
mod callback_game;
mod callback_query;
mod chat;
@ -241,3 +243,27 @@ pub(crate) mod serde_opt_date_from_unix_timestamp {
// DateTime::from_utc(NaiveDateTime::from_timestamp(timestamp, 0), Utc)))
// }
}
pub(crate) mod serde_date_from_unix_timestamp {
use chrono::{DateTime, NaiveDateTime, Utc};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
pub(crate) fn serialize<S>(this: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
this.timestamp().serialize(serializer)
}
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
where
D: Deserializer<'de>,
{
let timestamp = i64::deserialize(deserializer)?;
Ok(DateTime::from_utc(
NaiveDateTime::from_timestamp(timestamp, 0),
Utc,
))
}
}

View file

@ -0,0 +1,55 @@
use serde::{Deserialize, Serialize};
use crate::types::ChatId;
/// This object represents the scope to which bot commands are applied.
///
/// ## Determining list of commands
///
/// The following algorithm is used to determine the list of commands for a
/// particular user viewing the bot menu. The first list of commands which is
/// set is returned:
///
/// ### Commands in the chat with the bot
///
/// - [`Chat`] + `language_code`
/// - [`Chat`]
/// - [`AllPrivateChats`] + `language_code`
/// - [`AllPrivateChats`]
/// - [`Default`] + `language_code`
/// - [`Default`]
///
/// ### Commands in group and supergroup chats
///
/// - [`ChatMember`] + `language_code`
/// - [`ChatMember`]
/// - [`ChatAdministrators`] + `language_code` (admins only)
/// - [`ChatAdministrators`] (admins only)
/// - [`Chat`] + `language_code`
/// - [`Chat`]
/// - [`AllChatAdministrators`] + `language_code` (admins only)
/// - [`AllChatAdministrators`] (admins only)
/// - [`AllGroupChats`] + `language_code`
/// - [`AllGroupChats`]
/// - [`Default`] + `language_code`
/// - [`Default`]
///
/// [`Default`]: BotCommandScope::Default
/// [`AllPrivateChats`]: BotCommandScope::AllPrivateChats
/// [`AllGroupChats`]: BotCommandScope::AllGroupChats
/// [`AllChatAdministrators`]: BotCommandScope::AllChatAdministrators
/// [`Chat`]: BotCommandScope::Chat
/// [`ChatAdministrators`]: BotCommandScope::ChatAdministrators
/// [`ChatMember`]: BotCommandScope::ChatMember
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub enum BotCommandScope {
Default,
AllPrivateChats,
AllGroupChats,
AllChatAdministrators,
Chat(#[serde(rename = "chat_id")] ChatId),
ChatAdministrators(#[serde(rename = "chat_id")] ChatId),
ChatMember { chat_id: ChatId, user_id: i64 },
}

View file

@ -1,5 +1,6 @@
use std::ops::Deref;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::User;
@ -21,17 +22,19 @@ pub struct ChatMember {
#[serde(rename_all = "snake_case")]
#[serde(tag = "status")]
pub enum ChatMemberKind {
Creator(Creator),
#[serde(rename = "creator")]
Owner(Owner),
Administrator(Administrator),
Member,
Restricted(Restricted),
Left,
Kicked(Kicked),
#[serde(rename = "kicked")]
Banned(Banned),
}
/// Creator of the group. This struct is part of the [`ChatMemberKind`] enum.
/// Owner of the group. This struct is part of the [`ChatMemberKind`] enum.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Creator {
pub struct Owner {
/// Custom title for this user.
pub custom_title: Option<String>,
@ -96,8 +99,9 @@ pub struct Administrator {
/// enum.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Restricted {
/// Date when restrictions will be lifted for this user, unix time.
pub until_date: i64,
/// Date when restrictions will be lifted for this user.
#[serde(with = "crate::types::serde_date_from_unix_timestamp")]
pub until_date: DateTime<Utc>,
/// `true` if the user can send text messages, contacts, locations and
/// venues.
@ -116,12 +120,13 @@ pub struct Restricted {
pub can_add_web_page_previews: bool,
}
/// User kicked from the group. This struct is part of the [`ChatMemberKind`]
/// enum.
/// User that was banned in the chat and can't return to it or view chat
/// messages. This struct is part of the [`ChatMemberKind`] enum.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Kicked {
/// Date when restrictions will be lifted for this user, unix time.
pub until_date: i64,
pub struct Banned {
/// Date when restrictions will be lifted for this user.
#[serde(with = "crate::types::serde_date_from_unix_timestamp")]
pub until_date: DateTime<Utc>,
}
/// This allows calling [`ChatMemberKind`]'s methods directly on [`ChatMember`].
@ -147,20 +152,20 @@ impl ChatMemberKind {
/// Returns chat member status.
pub fn status(&self) -> ChatMemberStatus {
match self {
ChatMemberKind::Creator(_) => ChatMemberStatus::Creator,
ChatMemberKind::Owner(_) => ChatMemberStatus::Owner,
ChatMemberKind::Administrator(_) => ChatMemberStatus::Administrator,
ChatMemberKind::Member => ChatMemberStatus::Member,
ChatMemberKind::Restricted(_) => ChatMemberStatus::Restricted,
ChatMemberKind::Left => ChatMemberStatus::Left,
ChatMemberKind::Kicked(_) => ChatMemberStatus::Kicked,
ChatMemberKind::Banned(_) => ChatMemberStatus::Banned,
}
}
/// Returns `true` if the user is the [creator] (owner) of the given chat.
/// Returns `true` if the user is the [owner] of the given chat.
///
/// [creator]: ChatMemberKind::Creator
pub fn is_creator(&self) -> bool {
matches!(self, Self::Creator { .. })
/// [owner]: ChatMemberKind::Owner
pub fn is_owner(&self) -> bool {
matches!(self, Self::Owner { .. })
}
/// Returns `true` if the user is an [administrator] of the given chat.
@ -168,7 +173,7 @@ impl ChatMemberKind {
/// [administrator]: ChatMemberKind::Administrator
///
/// **Note**: this function **doesn't** return `true` if the user is the
/// creator of the given chat. See also: [`is_privileged`].
/// owner of the given chat. See also: [`is_privileged`].
///
/// [`is_privileged`]: ChatMemberKind::is_privileged
pub fn is_administrator(&self) -> bool {
@ -196,67 +201,83 @@ impl ChatMemberKind {
matches!(self, Self::Left { .. })
}
/// Returns `true` if the user is [banned] in the given chat.
///
/// [banned]: ChatMemberKind::Banned
pub fn is_banned(&self) -> bool {
matches!(self, Self::Banned { .. })
}
/// Returns `true` if the user is [kicked] from the given chat.
///
/// [kicked]: ChatMemberKind::Kicked
/// [kicked]: ChatMemberKind::Banned
#[deprecated = "use `is_banned` instead"]
pub fn is_kicked(&self) -> bool {
matches!(self, Self::Kicked { .. })
self.is_banned()
}
/// Returns `true` if the user is the [creator] (owner) of the given chat.
///
/// [creator]: ChatMemberKind::Owner
#[deprecated = "use `is_owner` instead"]
pub fn is_creator(&self) -> bool {
self.is_owner()
}
}
/// Compound methods for checking a user status.
impl ChatMemberKind {
/// Returns `true` if the user is privileged in the given chat. i.e. if the
/// user is either the [creator] or an [administrator] in the given chat.
/// user is either the [owner] or an [administrator] in the given chat.
///
/// [creator]: ChatMemberKind::Creator
/// [owner]: ChatMemberKind::Owner
/// [administrator]: ChatMemberKind::Administrator
pub fn is_privileged(&self) -> bool {
self.is_administrator() || self.is_creator()
self.is_administrator() || self.is_owner()
}
/// Returns `true` if the user is currently present in the chat. i.e. if the
/// user **hasn't** [left] or been [kicked].
/// user **hasn't** [left] or been [banned].
///
/// [left]: ChatMemberKind::Left
/// [kicked]: ChatMemberKind::Kicked
/// [banned]: ChatMemberKind::Banned
pub fn is_present(&self) -> bool {
!(self.is_left() || self.is_kicked())
!(self.is_left() || self.is_banned())
}
}
impl ChatMemberKind {
/// Getter for [`Administrator::custom_title`] and [`Creator::custom_title`]
/// Getter for [`Administrator::custom_title`] and [`Owner::custom_title`]
/// fields.
pub fn custom_title(&self) -> Option<&str> {
match &self {
Self::Administrator(Administrator { custom_title, .. })
| Self::Creator(Creator { custom_title, .. }) => custom_title.as_deref(),
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => None,
| Self::Owner(Owner { custom_title, .. }) => custom_title.as_deref(),
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => None,
}
}
/// Returns `true` if the user's presence in the chat is hidden.
///
/// I.e. returns `true` if the user is the creator of the chat or an
/// I.e. returns `true` if the user is the owner of the chat or an
/// administrator in the chat and has the [`can_manage_chat`] privilege.
/// Returns `false` otherwise.
///
/// [`can_manage_chat`]: Administrator::can_manage_chat
pub fn is_anonymous(&self) -> bool {
match self {
Self::Creator(Creator { is_anonymous, .. })
Self::Owner(Owner { is_anonymous, .. })
| Self::Administrator(Administrator { is_anonymous, .. }) => *is_anonymous,
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
/// Getter for [`Restricted::until_date`] and [`Kicked::until_date`] fields.
pub fn until_date(&self) -> Option<i64> {
/// Getter for [`Restricted::until_date`] and [`Banned::until_date`] fields.
pub fn until_date(&self) -> Option<DateTime<Utc>> {
match &self {
Self::Creator(_) | Self::Administrator(_) | Self::Member | Self::Left => None,
Self::Owner(_) | Self::Administrator(_) | Self::Member | Self::Left => None,
Self::Restricted(Restricted { until_date, .. })
| Self::Kicked(Kicked { until_date, .. }) => Some(*until_date),
| Self::Banned(Banned { until_date, .. }) => Some(*until_date),
}
}
}
@ -268,12 +289,10 @@ impl ChatMemberKind {
pub fn can_be_edited(&self) -> bool {
match self {
Self::Administrator(Administrator { can_be_edited, .. }) => *can_be_edited,
// Creator can't ever be edited by any bot.
Self::Creator(_)
| Self::Member
| Self::Restricted(_)
| Self::Left
| Self::Kicked(_) => false,
// Owner can't ever be edited by any bot.
Self::Owner(_) | Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => {
false
}
}
}
@ -283,7 +302,7 @@ impl ChatMemberKind {
/// any other administrator privilege.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat
/// - is the owner of the chat
/// - is an administrator in the given chat and has [`can_manage_chat`]
/// privilege.
/// Returns `false` otherwise.
@ -291,11 +310,11 @@ impl ChatMemberKind {
/// [`can_manage_chat`]: Administrator::can_manage_chat
pub fn can_manage_chat(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_manage_chat, ..
}) => *can_manage_chat,
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => true,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => true,
}
}
@ -303,7 +322,7 @@ impl ChatMemberKind {
/// settings.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat
/// - is the owner of the chat
/// - is an administrator in the given chat and has the [`can_change_info`]
/// privilege.
/// Returns `false` otherwise.
@ -311,18 +330,18 @@ impl ChatMemberKind {
/// [`can_change_info`]: Administrator::can_change_info
pub fn can_change_info(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_change_info, ..
}) => *can_change_info,
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
/// Returns `true` if the user can post in the channel, channels only.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat (even if the chat is not a channel)
/// - is the owner of the chat (even if the chat is not a channel)
/// - is an administrator in the given chat and has [`can_post_messages`]
/// privilege.
/// Returns `false` otherwise.
@ -330,11 +349,11 @@ impl ChatMemberKind {
/// [`can_post_messages`]: Administrator::can_post_messages
pub fn can_post_messages(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_post_messages, ..
}) => can_post_messages.unwrap_or_default(),
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
@ -342,7 +361,7 @@ impl ChatMemberKind {
/// messages, channels only.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat (even if the chat is not a channel)
/// - is the owner of the chat (even if the chat is not a channel)
/// - is an administrator in the given chat and has the
/// [`can_edit_messages`] privilege.
/// Returns `false` otherwise.
@ -350,18 +369,18 @@ impl ChatMemberKind {
/// [`can_edit_messages`]: Administrator::can_edit_messages
pub fn can_edit_messages(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_edit_messages, ..
}) => can_edit_messages.unwrap_or_default(),
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
/// Returns `true` if the user can delete messages of other users.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat
/// - is the owner of the chat
/// - is an administrator in the given chat and has the
/// [`can_delete_messages`] privilege.
/// Returns `false` otherwise.
@ -369,19 +388,19 @@ impl ChatMemberKind {
/// [`can_delete_messages`]: Administrator::can_delete_messages
pub fn can_delete_messages(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_delete_messages,
..
}) => *can_delete_messages,
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
/// Returns `true` if the user can manage voice chats.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat
/// - is the owner of the chat
/// - is an administrator in the given chat and has the
/// [`can_manage_voice_chats`] privilege.
/// Returns `false` otherwise.
@ -389,19 +408,19 @@ impl ChatMemberKind {
/// [`can_manage_voice_chats`]: Administrator::can_manage_voice_chats
pub fn can_manage_voice_chats(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_manage_voice_chats,
..
}) => *can_manage_voice_chats,
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
/// Returns `true` if the user can can invite new users to the chat.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat
/// - is the owner of the chat
/// - is an administrator in the given chat and has the [`can_invite_users`]
/// privilege.
/// Returns `false` otherwise.
@ -409,18 +428,18 @@ impl ChatMemberKind {
/// [`can_invite_users`]: Administrator::can_invite_users
pub fn can_invite_users(&self) -> bool {
match &self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_invite_users, ..
}) => *can_invite_users,
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
/// Returns `true` if the user can restrict, ban or unban chat members.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat
/// - is the owner of the chat
/// - is an administrator in the given chat and has the
/// [`can_restrict_members`] privilege.
/// Returns `false` otherwise.
@ -428,19 +447,19 @@ impl ChatMemberKind {
/// [`can_restrict_members`]: Administrator::can_restrict_members
pub fn can_restrict_members(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_restrict_members,
..
}) => *can_restrict_members,
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
/// Returns `true` if the user can pin messages, supergroups only.
///
/// I.e. returns `true` if the user
/// - is the creator of the chat (even if the chat is not a supergroup)
/// - is the owner of the chat (even if the chat is not a supergroup)
/// - is an administrator in the given chat and has the [`can_pin_messages`]
/// privilege.
/// Returns `false` otherwise.
@ -448,11 +467,11 @@ impl ChatMemberKind {
/// [`can_pin_messages`]: Administrator::can_pin_messages
pub fn can_pin_messages(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_pin_messages, ..
}) => can_pin_messages.unwrap_or_default(),
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
@ -462,7 +481,7 @@ impl ChatMemberKind {
/// by the user).
///
/// I.e. returns `true` if the user
/// - is the creator of the chat (even if the chat is not a channel)
/// - is the owner of the chat (even if the chat is not a channel)
/// - is an administrator in the given chat and has the
/// [`can_promote_members`] privilege.
/// Returns `false` otherwise.
@ -470,12 +489,12 @@ impl ChatMemberKind {
/// [`can_promote_members`]: Administrator::can_promote_members
pub fn can_promote_members(&self) -> bool {
match self {
Self::Creator(_) => true,
Self::Owner(_) => true,
Self::Administrator(Administrator {
can_promote_members,
..
}) => *can_promote_members,
Self::Member | Self::Restricted(_) | Self::Left | Self::Kicked(_) => false,
Self::Member | Self::Restricted(_) | Self::Left | Self::Banned(_) => false,
}
}
}
@ -486,7 +505,7 @@ impl ChatMemberKind {
/// and venues.
///
/// I.e. returns **`false`** if the user
/// - has left or has been kicked from the chat
/// - has left or has been banned in the chat
/// - is restricted and doesn't have the [`can_send_messages`] right
/// Returns `true` otherwise.
///
@ -496,8 +515,8 @@ impl ChatMemberKind {
Self::Restricted(Restricted {
can_send_messages, ..
}) => *can_send_messages,
Self::Creator(_) | Self::Administrator(_) | Self::Member => true,
Self::Left | Self::Kicked(_) => false,
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
Self::Left | Self::Banned(_) => false,
}
}
@ -505,7 +524,7 @@ impl ChatMemberKind {
/// videos, video notes and voice notes.
///
/// I.e. returns **`false`** if the user
/// - has left or has been kicked from the chat
/// - has left or has been banned in the chat
/// - is restricted and doesn't have the [`can_send_media_messages`] right
/// Returns `true` otherwise.
///
@ -516,8 +535,8 @@ impl ChatMemberKind {
can_send_media_messages,
..
}) => *can_send_media_messages,
Self::Creator(_) | Self::Administrator(_) | Self::Member => true,
Self::Left | Self::Kicked(_) => false,
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
Self::Left | Self::Banned(_) => false,
}
}
@ -525,7 +544,7 @@ impl ChatMemberKind {
/// stickers and use inline bots.
///
/// I.e. returns **`false`** if the user
/// - has left or has been kicked from the chat
/// - has left or has been banned from the chat
/// - is restricted and doesn't have the [`can_send_media_messages`] right
/// Returns `true` otherwise.
///
@ -536,8 +555,8 @@ impl ChatMemberKind {
can_send_other_messages,
..
}) => *can_send_other_messages,
Self::Creator(_) | Self::Administrator(_) | Self::Member => true,
Self::Left | Self::Kicked(_) => false,
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
Self::Left | Self::Banned(_) => false,
}
}
@ -545,7 +564,7 @@ impl ChatMemberKind {
/// messages.
///
/// I.e. returns **`false`** if the user
/// - has left or has been kicked from the chat
/// - has left or has been banned from the chat
/// - is restricted and doesn't have the [`can_send_media_messages`] right
/// Returns `true` otherwise.
///
@ -556,8 +575,8 @@ impl ChatMemberKind {
can_add_web_page_previews,
..
}) => *can_add_web_page_previews,
Self::Creator(_) | Self::Administrator(_) | Self::Member => true,
Self::Left | Self::Kicked(_) => false,
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
Self::Left | Self::Banned(_) => false,
}
}
}
@ -565,12 +584,12 @@ impl ChatMemberKind {
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ChatMemberStatus {
Creator,
Owner,
Administrator,
Member,
Restricted,
Left,
Kicked,
Banned,
}
#[cfg(test)]

View file

@ -13,12 +13,16 @@ use crate::types::True;
///
/// [privacy mode]: https://core.telegram.org/bots#privacy-mode
#[serde_with_macros::skip_serializing_none]
#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ForceReply {
/// Shows reply interface to the user, as if they manually selected the
/// bots message and tapped Reply'.
pub force_reply: True,
/// The placeholder to be shown in the input field when the reply is active;
/// 1-64 characters.
pub input_field_placeholder: Option<String>,
/// Use this parameter if you want to force reply from specific users only.
/// Targets: 1) users that are `@mentioned` in the text of the
/// [`Message`] object; 2) if the bot's message is a reply
@ -32,10 +36,19 @@ impl ForceReply {
pub const fn new() -> Self {
Self {
force_reply: True,
input_field_placeholder: None,
selective: None,
}
}
pub fn input_field_placeholder<T>(mut self, val: T) -> Self
where
T: Into<Option<String>>,
{
self.input_field_placeholder = val.into();
self
}
pub const fn selective(mut self, val: bool) -> Self {
self.selective = Some(val);
self

View file

@ -31,6 +31,10 @@ pub struct KeyboardMarkup {
/// Defaults to `false`.
pub one_time_keyboard: Option<bool>,
/// The placeholder to be shown in the input field when the keyboard is
/// active; 1-64 characters.
pub input_field_placeholder: Option<String>,
/// Use this parameter if you want to show the keyboard to specific users
/// only. Targets: 1) users that are `@mentioned` in the `text` of the
/// [`Message`] object; 2) if the bot's message is a reply (has
@ -58,6 +62,7 @@ impl KeyboardMarkup {
.collect(),
resize_keyboard: None,
one_time_keyboard: None,
input_field_placeholder: None,
selective: None,
}
}
@ -91,6 +96,14 @@ impl KeyboardMarkup {
self
}
pub fn input_field_placeholder<T>(mut self, val: T) -> Self
where
T: Into<Option<String>>,
{
self.input_field_placeholder = val.into();
self
}
pub fn selective<T>(mut self, val: T) -> Self
where
T: Into<Option<bool>>,