Skip to content

Commit

Permalink
Merge pull request #3 from Desiders/add-support-bot-api-7.0
Browse files Browse the repository at this point in the history
Add support Bot API 7.0
  • Loading branch information
Desiders authored Jan 7, 2024
2 parents f9bf737 + 19fddbf commit dc9cb1b
Show file tree
Hide file tree
Showing 126 changed files with 4,173 additions and 1,240 deletions.
27 changes: 18 additions & 9 deletions src/enums/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pub enum ContentType {
VideoNote,
#[strum(serialize = "voice")]
Voice,
#[strum(serialize = "has_media_spoiler")]
HasMediaSpoiler,
#[strum(serialize = "contact")]
Contact,
#[strum(serialize = "dice")]
Expand Down Expand Up @@ -93,6 +91,14 @@ pub enum ContentType {
GeneralForumTopicHidden,
#[strum(serialize = "general_forum_topic_unhidden")]
GeneralForumTopicUnhidden,
#[strum(serialize = "giveaway_created")]
GiveawayCreated,
#[strum(serialize = "giveaway")]
Giveaway,
#[strum(serialize = "giveaway_winners")]
GiveawayWinners,
#[strum(serialize = "giveaway_completed")]
GiveawayCompleted,
#[strum(serialize = "video_chat_scheduled")]
VideoChatScheduled,
#[strum(serialize = "video_chat_started")]
Expand All @@ -103,13 +109,11 @@ pub enum ContentType {
VideoChatParticipantsInvited,
#[strum(serialize = "web_app_data")]
WebAppData,
#[strum(serialize = "empty")]
Empty,
}

impl ContentType {
#[must_use]
pub const fn all() -> [ContentType; 49] {
pub const fn all() -> [ContentType; 51] {
[
ContentType::Text,
ContentType::Animation,
Expand All @@ -121,7 +125,6 @@ impl ContentType {
ContentType::Video,
ContentType::VideoNote,
ContentType::Voice,
ContentType::HasMediaSpoiler,
ContentType::Contact,
ContentType::Dice,
ContentType::Game,
Expand Down Expand Up @@ -154,12 +157,15 @@ impl ContentType {
ContentType::ForumTopicReopened,
ContentType::GeneralForumTopicHidden,
ContentType::GeneralForumTopicUnhidden,
ContentType::GiveawayCreated,
ContentType::Giveaway,
ContentType::GiveawayWinners,
ContentType::GiveawayCompleted,
ContentType::VideoChatScheduled,
ContentType::VideoChatStarted,
ContentType::VideoChatEnded,
ContentType::VideoChatParticipantsInvited,
ContentType::WebAppData,
ContentType::Empty,
]
}
}
Expand Down Expand Up @@ -215,7 +221,7 @@ impl From<&Message> for ContentType {
Message::Pinned(_) => ContentType::PinnedMessage,
Message::Invoice(_) => ContentType::Invoice,
Message::SuccessfulPayment(_) => ContentType::SuccessfulPayment,
Message::UserShared(_) => ContentType::UserShared,
Message::UsersShared(_) => ContentType::UserShared,
Message::ChatShared(_) => ContentType::ChatShared,
Message::ConnectedWebsite(_) => ContentType::ConnectedWebsite,
Message::WriteAccessAllowed(_) => ContentType::WriteAccessAllowed,
Expand All @@ -227,12 +233,15 @@ impl From<&Message> for ContentType {
Message::ForumTopicReopened(_) => ContentType::ForumTopicReopened,
Message::GeneralForumTopicHidden(_) => ContentType::GeneralForumTopicHidden,
Message::GeneralForumTopicUnhidden(_) => ContentType::GeneralForumTopicUnhidden,
Message::GiveawayCreated(_) => ContentType::GiveawayCreated,
Message::Giveaway(_) => ContentType::Giveaway,
Message::GiveawayWinners(_) => ContentType::GiveawayWinners,
Message::GiveawayCompleted(_) => ContentType::GiveawayCompleted,
Message::VideoChatScheduled(_) => ContentType::VideoChatScheduled,
Message::VideoChatStarted(_) => ContentType::VideoChatStarted,
Message::VideoChatEnded(_) => ContentType::VideoChatEnded,
Message::VideoChatParticipantsInvited(_) => ContentType::VideoChatParticipantsInvited,
Message::WebAppData(_) => ContentType::WebAppData,
Message::Empty(_) => ContentType::Empty,
}
}
}
14 changes: 13 additions & 1 deletion src/enums/observer_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub enum Telegram {
EditedMessage,
#[strum(serialize = "edited_channel_post")]
EditedChannelPost,
#[strum(serialize = "message_reaction")]
MessageReaction,
#[strum(serialize = "message_reaction_count")]
MessageReactionCount,
#[strum(serialize = "shipping_query")]
ShippingQuery,
#[strum(serialize = "pre_checkout_query")]
Expand All @@ -31,13 +35,17 @@ pub enum Telegram {
ChatMember,
#[strum(serialize = "chat_join_request")]
ChatJoinRequest,
#[strum(serialize = "chat_boost")]
ChatBoost,
#[strum(serialize = "removed_chat_boost")]
RemovedChatBoost,
#[strum(serialize = "update")]
Update,
}

impl Telegram {
#[must_use]
pub const fn all() -> [Telegram; 15] {
pub const fn all() -> [Telegram; 19] {
[
Telegram::Message,
Telegram::InlineQuery,
Expand All @@ -46,13 +54,17 @@ impl Telegram {
Telegram::ChannelPost,
Telegram::EditedMessage,
Telegram::EditedChannelPost,
Telegram::MessageReaction,
Telegram::MessageReactionCount,
Telegram::ShippingQuery,
Telegram::PreCheckoutQuery,
Telegram::Poll,
Telegram::PollAnswer,
Telegram::MyChatMember,
Telegram::ChatMember,
Telegram::ChatJoinRequest,
Telegram::ChatBoost,
Telegram::RemovedChatBoost,
Telegram::Update,
]
}
Expand Down
17 changes: 16 additions & 1 deletion src/enums/update_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub enum UpdateType {
EditedMessage,
#[strum(serialize = "edited_channel_post")]
EditedChannelPost,
#[strum(serialize = "message_reaction")]
MessageReaction,
#[strum(serialize = "message_reaction_count")]
MessageReactionCount,
#[strum(serialize = "shipping_query")]
ShippingQuery,
#[strum(serialize = "pre_checkout_query")]
Expand All @@ -36,11 +40,15 @@ pub enum UpdateType {
ChatMember,
#[strum(serialize = "chat_join_request")]
ChatJoinRequest,
#[strum(serialize = "chat_boost")]
ChatBoost,
#[strum(serialize = "removed_chat_boost")]
RemovedChatBoost,
}

impl UpdateType {
#[must_use]
pub const fn all() -> &'static [UpdateType; 14] {
pub const fn all() -> &'static [UpdateType; 17] {
&[
UpdateType::Message,
UpdateType::InlineQuery,
Expand All @@ -49,13 +57,16 @@ impl UpdateType {
UpdateType::ChannelPost,
UpdateType::EditedMessage,
UpdateType::EditedChannelPost,
UpdateType::MessageReaction,
UpdateType::ShippingQuery,
UpdateType::PreCheckoutQuery,
UpdateType::Poll,
UpdateType::PollAnswer,
UpdateType::MyChatMember,
UpdateType::ChatMember,
UpdateType::ChatJoinRequest,
UpdateType::ChatBoost,
UpdateType::RemovedChatBoost,
]
}
}
Expand Down Expand Up @@ -85,6 +96,8 @@ impl<'a> From<&'a UpdateKind> for UpdateType {
UpdateKind::EditedMessage(_) => UpdateType::EditedMessage,
UpdateKind::ChannelPost(_) => UpdateType::ChannelPost,
UpdateKind::EditedChannelPost(_) => UpdateType::EditedChannelPost,
UpdateKind::MessageReaction(_) => UpdateType::MessageReaction,
UpdateKind::MessageReactionCount(_) => UpdateType::MessageReactionCount,
UpdateKind::InlineQuery(_) => UpdateType::InlineQuery,
UpdateKind::ChosenInlineResult(_) => UpdateType::ChosenInlineResult,
UpdateKind::CallbackQuery(_) => UpdateType::CallbackQuery,
Expand All @@ -95,6 +108,8 @@ impl<'a> From<&'a UpdateKind> for UpdateType {
UpdateKind::MyChatMember(_) => UpdateType::MyChatMember,
UpdateKind::ChatMember(_) => UpdateType::ChatMember,
UpdateKind::ChatJoinRequest(_) => UpdateType::ChatJoinRequest,
UpdateKind::ChatBoost(_) => UpdateType::ChatBoost,
UpdateKind::RemovedChatBoost(_) => UpdateType::RemovedChatBoost,
}
}
}
Expand Down
57 changes: 37 additions & 20 deletions src/extractors/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ use crate::{
context::Context,
errors::ConvertToTypeError,
types::{
CallbackQuery, ChatJoinRequest, ChatMemberUpdated, ChosenInlineResult, InlineQuery,
Message, MessageAnimation, MessageAudio, MessageChannelChatCreated, MessageChatShared,
MessageConnectedWebsite, MessageContact, MessageDeleteChatPhoto, MessageDice,
MessageDocument, MessageEmpty, MessageForumTopicClosed, MessageForumTopicCreated,
MessageForumTopicEdited, MessageForumTopicReopened, MessageForward, MessageForwardedFrom,
MessageGame, MessageGeneralForumTopicHidden, MessageGeneralForumTopicUnhidden,
CallbackQuery, ChatBoostRemoved, ChatBoostUpdated, ChatJoinRequest, ChatMemberUpdated,
ChosenInlineResult, InlineQuery, Message, MessageAnimation, MessageAudio,
MessageChannelChatCreated, MessageChatShared, MessageConnectedWebsite, MessageContact,
MessageDeleteChatPhoto, MessageDice, MessageDocument, MessageForumTopicClosed,
MessageForumTopicCreated, MessageForumTopicEdited, MessageForumTopicReopened, MessageGame,
MessageGeneralForumTopicHidden, MessageGeneralForumTopicUnhidden, MessageGiveaway,
MessageGiveawayCompleted, MessageGiveawayCreated, MessageGiveawayWinners,
MessageGroupChatCreated, MessageInvoice, MessageLeftChatMember, MessageLocation,
MessageMessageAutoDeleteTimerChanged, MessageMigrateFromChat, MessageMigrateToChat,
MessageNewChatMembers, MessageNewChatPhoto, MessageNewChatTitle, MessagePassportData,
MessagePhoto, MessagePinned, MessagePoll, MessageProximityAlertTriggered, MessageSticker,
MessageStory, MessageSuccessfulPayment, MessageSupergroupChatCreated, MessageText,
MessageUserShared, MessageVenue, MessageVideo, MessageVideoChatEnded,
MessageVideoChatParticipantsInvited, MessageVideoChatScheduled, MessageVideoChatStarted,
MessageVideoNote, MessageVoice, MessageWebAppData, MessageWriteAccessAllowed, Poll,
PollAnswer, PollQuiz, PollRegular, PreCheckoutQuery, ShippingQuery, Update, UpdateKind,
MessagePhoto, MessagePinned, MessagePoll, MessageProximityAlertTriggered,
MessageReactionCountUpdated, MessageReactionUpdated, MessageSticker, MessageStory,
MessageSuccessfulPayment, MessageSupergroupChatCreated, MessageText, MessageUsersShared,
MessageVenue, MessageVideo, MessageVideoChatEnded, MessageVideoChatParticipantsInvited,
MessageVideoChatScheduled, MessageVideoChatStarted, MessageVideoNote, MessageVoice,
MessageWebAppData, MessageWriteAccessAllowed, Poll, PollAnswer, PollQuiz, PollRegular,
PreCheckoutQuery, ShippingQuery, Update, UpdateKind,
},
};

Expand Down Expand Up @@ -107,7 +109,7 @@ try_from_update!([Client], MessageText);
try_from_update!([Client], MessageAnimation);
try_from_update!([Client], MessageAudio);
try_from_update!([Client], MessageChannelChatCreated);
try_from_update!([Client], MessageUserShared);
try_from_update!([Client], MessageUsersShared);
try_from_update!([Client], MessageChatShared);
try_from_update!([Client], MessageConnectedWebsite);
try_from_update!([Client], MessageContact);
Expand All @@ -118,8 +120,6 @@ try_from_update!([Client], MessageForumTopicClosed);
try_from_update!([Client], MessageForumTopicCreated);
try_from_update!([Client], MessageForumTopicEdited);
try_from_update!([Client], MessageForumTopicReopened);
try_from_update!([Client], MessageForward);
try_from_update!([Client], MessageForwardedFrom);
try_from_update!([Client], MessageGame);
try_from_update!([Client], MessageGeneralForumTopicHidden);
try_from_update!([Client], MessageGeneralForumTopicUnhidden);
Expand Down Expand Up @@ -152,7 +152,12 @@ try_from_update!([Client], MessageVideoNote);
try_from_update!([Client], MessageVoice);
try_from_update!([Client], MessageWebAppData);
try_from_update!([Client], MessageWriteAccessAllowed);
try_from_update!([Client], MessageEmpty);
try_from_update!([Client], MessageGiveawayCreated);
try_from_update!([Client], MessageGiveaway);
try_from_update!([Client], MessageGiveawayCompleted);
try_from_update!([Client], MessageGiveawayWinners);
try_from_update!([Client], MessageReactionUpdated);
try_from_update!([Client], MessageReactionCountUpdated);

// To be able to use [`Poll`] and all [`PollKind`] variants in handler arguments
try_from_update!([Client], Poll);
Expand Down Expand Up @@ -183,6 +188,12 @@ try_from_update!([Client], ChatJoinRequest);
// To be able to use [`InlineQuery`] in handler arguments
try_from_update!([Client], InlineQuery);

// To be able to use [`ChatBoostUpdated`] in handler arguments
try_from_update!([Client], ChatBoostUpdated);

// To be able to use [`ChatBoostRemoved`] in handler arguments
try_from_update!([Client], ChatBoostRemoved);

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -212,7 +223,7 @@ mod tests {
assert_impl_handler(|_: MessageAnimation| async { unreachable!() });
assert_impl_handler(|_: MessageAudio| async { unreachable!() });
assert_impl_handler(|_: MessageChannelChatCreated| async { unreachable!() });
assert_impl_handler(|_: MessageUserShared| async { unreachable!() });
assert_impl_handler(|_: MessageUsersShared| async { unreachable!() });
assert_impl_handler(|_: MessageChatShared| async { unreachable!() });
assert_impl_handler(|_: MessageConnectedWebsite| async { unreachable!() });
assert_impl_handler(|_: MessageContact| async { unreachable!() });
Expand All @@ -223,8 +234,6 @@ mod tests {
assert_impl_handler(|_: MessageForumTopicCreated| async { unreachable!() });
assert_impl_handler(|_: MessageForumTopicEdited| async { unreachable!() });
assert_impl_handler(|_: MessageForumTopicReopened| async { unreachable!() });
assert_impl_handler(|_: MessageForward| async { unreachable!() });
assert_impl_handler(|_: MessageForwardedFrom| async { unreachable!() });
assert_impl_handler(|_: MessageGame| async { unreachable!() });
assert_impl_handler(|_: MessageGeneralForumTopicHidden| async { unreachable!() });
assert_impl_handler(|_: MessageGeneralForumTopicUnhidden| async { unreachable!() });
Expand Down Expand Up @@ -257,7 +266,13 @@ mod tests {
assert_impl_handler(|_: MessageVoice| async { unreachable!() });
assert_impl_handler(|_: MessageWebAppData| async { unreachable!() });
assert_impl_handler(|_: MessageWriteAccessAllowed| async { unreachable!() });
assert_impl_handler(|_: MessageEmpty| async { unreachable!() });
assert_impl_handler(|_: MessageGiveawayCreated| async { unreachable!() });
assert_impl_handler(|_: MessageGiveaway| async { unreachable!() });
assert_impl_handler(|_: MessageGiveawayCompleted| async { unreachable!() });
assert_impl_handler(|_: MessageGiveawayWinners| async { unreachable!() });
assert_impl_handler(|_: MessageUsersShared| async { unreachable!() });
assert_impl_handler(|_: MessageReactionUpdated| async { unreachable!() });
assert_impl_handler(|_: MessageReactionCountUpdated| async { unreachable!() });
assert_impl_handler(|_: Poll| async { unreachable!() });
assert_impl_handler(|_: PollRegular| async { unreachable!() });
assert_impl_handler(|_: PollQuiz| async { unreachable!() });
Expand All @@ -269,6 +284,8 @@ mod tests {
assert_impl_handler(|_: ChatMemberUpdated| async { unreachable!() });
assert_impl_handler(|_: ChatJoinRequest| async { unreachable!() });
assert_impl_handler(|_: InlineQuery| async { unreachable!() });
assert_impl_handler(|_: ChatBoostUpdated| async { unreachable!() });
assert_impl_handler(|_: ChatBoostRemoved| async { unreachable!() });
}

#[allow(clippy::too_many_lines)]
Expand Down
Loading

0 comments on commit dc9cb1b

Please sign in to comment.