From ecf4f94dcabe54d15e7b849475350a58da5bb12d Mon Sep 17 00:00:00 2001 From: eleksir Date: Sun, 16 Apr 2023 16:00:36 +0300 Subject: [PATCH] Add general support for BotAPI v6.4 --- lib/Teapot/Bot/Brain.pm | 33 +++---- lib/Teapot/Bot/Object/Chat.pm | 9 +- lib/Teapot/Bot/Object/ForumTopicEdited.pm | 55 +++++++++++ .../Bot/Object/GeneralForumTopicHidden.pm | 51 ++++++++++ .../Bot/Object/GeneralForumTopicUnhidden.pm | 51 ++++++++++ lib/Teapot/Bot/Object/Message.pm | 92 +++++++++++-------- lib/Teapot/Bot/Object/WriteAccessAllowed.pm | 51 ++++++++++ 7 files changed, 286 insertions(+), 56 deletions(-) create mode 100644 lib/Teapot/Bot/Object/ForumTopicEdited.pm create mode 100644 lib/Teapot/Bot/Object/GeneralForumTopicHidden.pm create mode 100644 lib/Teapot/Bot/Object/GeneralForumTopicUnhidden.pm create mode 100644 lib/Teapot/Bot/Object/WriteAccessAllowed.pm diff --git a/lib/Teapot/Bot/Brain.pm b/lib/Teapot/Bot/Brain.pm index 6c7b33b..c9a1314 100644 --- a/lib/Teapot/Bot/Brain.pm +++ b/lib/Teapot/Bot/Brain.pm @@ -568,8 +568,9 @@ sub deleteMessage { return $ret; } - $send_args->{chat_id} = $args->{chat_id}; - $send_args->{message_id} = $args->{message_id}; + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{message_id} = $args->{message_id}; + $send_args->{message_thread_id} = $args->{message_thread_id} if exists $args->{message_thread_id}; # TODO: fix canDeleteMessage() && export it in this fle if (Teapot::Bot::Object::ChatMember->canDeleteMessage($self, $args->{chat_id})) { @@ -667,20 +668,20 @@ sub sendChatAction { return $ret; } - $args->{action} = 'typing' unless (defined $args->{action}); - - $send_args->{chat_id} = $args->{chat_id}; - $send_args->{action} = 'typing'; - $send_args->{action} = 'upload_photo' if ($args->{action} eq 'upload_photo'); - $send_args->{action} = 'record_video' if ($args->{action} eq 'record_video'); - $send_args->{action} = 'upload_video' if ($args->{action} eq 'upload_video'); - $send_args->{action} = 'record_voice' if ($args->{action} eq 'record_voice'); - $send_args->{action} = 'upload_voice' if ($args->{action} eq 'upload_voice'); - $send_args->{action} = 'upload_document' if ($args->{action} eq 'upload_document'); - $send_args->{action} = 'find_location' if ($args->{action} eq 'find_location'); - $send_args->{action} = 'record_video_note' if ($args->{action} eq 'record_video_note'); - $send_args->{action} = 'upload_video_note' if ($args->{action} eq 'upload_video_note'); - $send_args->{action} = 'choose_sticker' if ($args->{action} eq 'choose_sticker'); + $args->{action} = 'typing' unless (defined $args->{action}); + $send_args->{message_thread_id} = $args->{message_thread_id} if exists $args->{message_thread_id}; + $send_args->{chat_id} = $args->{chat_id}; + $send_args->{action} = 'typing'; + $send_args->{action} = 'upload_photo' if ($args->{action} eq 'upload_photo'); + $send_args->{action} = 'record_video' if ($args->{action} eq 'record_video'); + $send_args->{action} = 'upload_video' if ($args->{action} eq 'upload_video'); + $send_args->{action} = 'record_voice' if ($args->{action} eq 'record_voice'); + $send_args->{action} = 'upload_voice' if ($args->{action} eq 'upload_voice'); + $send_args->{action} = 'upload_document' if ($args->{action} eq 'upload_document'); + $send_args->{action} = 'find_location' if ($args->{action} eq 'find_location'); + $send_args->{action} = 'record_video_note' if ($args->{action} eq 'record_video_note'); + $send_args->{action} = 'upload_video_note' if ($args->{action} eq 'upload_video_note'); + $send_args->{action} = 'choose_sticker' if ($args->{action} eq 'choose_sticker'); my $url = sprintf 'https://api.telegram.org/bot%s/sendChatAction', $self->token; diff --git a/lib/Teapot/Bot/Object/Chat.pm b/lib/Teapot/Bot/Object/Chat.pm index c3b9bfe..b940ff0 100644 --- a/lib/Teapot/Bot/Object/Chat.pm +++ b/lib/Teapot/Bot/Object/Chat.pm @@ -38,6 +38,10 @@ has 'permissions'; # Teapot::Bot::Object::ChatPermissions. Optional has 'slow_mode_delay'; # Optional. Returned only in getChat. has 'message_auto_delete_time'; # Optional. The time after which all messages sent to the chat will be automatically # deleted; in seconds. Returned only in getChat. +has 'has_aggressive_anti_spam_enabled'; # Optional. True, if aggressive anti-spam checks are enabled in the supergroup. + # The field is only available to chat administrators. Returned only in getChat. +has 'has_hidden_members'; # Optional. True, if non-administrators can only get the list of bots and administrators + # in the chat. Returned only in getChat. has 'has_protected_content'; # Optional. True, if messages from the chat can't be forwarded to other chats. # Returned only in getChat. has 'sticker_set_name'; # Optional. Returned only in getChat. @@ -50,8 +54,9 @@ sub fields { 'scalar' => [qw/id type title username first_name last_name is_forum emoji_status_custom_emoji_id bio has_private_forwards description invite_link slow_mode_delay - message_auto_delete_time has_protected_content - sticker_set_name can_set_sticker_set linked_chat_id/], + message_auto_delete_time has_aggressive_anti_spam_enabled + has_hidden_members has_protected_content sticker_set_name + can_set_sticker_set linked_chat_id/], 'Teapot::Bot::Object::ChatPhoto' => [qw/photo/], 'Teapot::Bot::Object::Message' => [qw/pinned_message/], 'Teapot::Bot::Object::ChatPermissions' => [qw/permissions/], diff --git a/lib/Teapot/Bot/Object/ForumTopicEdited.pm b/lib/Teapot/Bot/Object/ForumTopicEdited.pm new file mode 100644 index 0000000..84c5507 --- /dev/null +++ b/lib/Teapot/Bot/Object/ForumTopicEdited.pm @@ -0,0 +1,55 @@ +package Teapot::Bot::Object::ForumTopicEdited; +# ABSTRACT: The base class for Telegram message 'ForumTopicEdited' type. + +use strict; +use warnings; +use 5.018; ## no critic (ProhibitImplicitImport) +use utf8; + +use Mojo::Base 'Teapot::Bot::Object::Base'; + +$Teapot::Bot::Object::ForumTopicEdited::VERSION = '0.025'; + +has 'name'; +has 'icon_custom_emoji_id'; + +sub fields { + return { + 'scalar' => [qw/name icon_custom_emoji_id/], + }; +} + +1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +Teapot::Bot::Object::ForumTopicEdited - The base class for Telegram message 'ForumTopicEdited' type + +=head1 VERSION + +version 0.025 + +=head1 DESCRIPTION +The base class for Telegram message 'ForumTopicEdited' type. + +See L for details of the +attributes available for C objects. + +=head1 AUTHOR + +Sergei Fedosov + +=head1 LICENSE AND COPYRIGHT + +This software is copyright (c) 2023 by Sergei Fedosov . + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut diff --git a/lib/Teapot/Bot/Object/GeneralForumTopicHidden.pm b/lib/Teapot/Bot/Object/GeneralForumTopicHidden.pm new file mode 100644 index 0000000..4471365 --- /dev/null +++ b/lib/Teapot/Bot/Object/GeneralForumTopicHidden.pm @@ -0,0 +1,51 @@ +package Teapot::Bot::Object::GeneralForumTopicHidden; +# ABSTRACT: The base class for Telegram message 'GeneralForumTopicHidden' type. + +use strict; +use warnings; +use 5.018; ## no critic (ProhibitImplicitImport) +use utf8; + +use Mojo::Base 'Teapot::Bot::Object::Base'; + +$Teapot::Bot::Object::GeneralForumTopicHidden::VERSION = '0.025'; + + +sub fields { + return { }; +} + +1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +Teapot::Bot::Object::GeneralForumTopicHidden - The base class for Telegram message 'GeneralForumTopicHidden' type + +=head1 VERSION + +version 0.025 + +=head1 DESCRIPTION +The base class for Telegram message 'GeneralForumTopicHidden' type. + +See L for details of the +attributes available for C objects. + +=head1 AUTHOR + +Sergei Fedosov + +=head1 LICENSE AND COPYRIGHT + +This software is copyright (c) 2023 by Sergei Fedosov . + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut diff --git a/lib/Teapot/Bot/Object/GeneralForumTopicUnhidden.pm b/lib/Teapot/Bot/Object/GeneralForumTopicUnhidden.pm new file mode 100644 index 0000000..c7189e1 --- /dev/null +++ b/lib/Teapot/Bot/Object/GeneralForumTopicUnhidden.pm @@ -0,0 +1,51 @@ +package Teapot::Bot::Object::GeneralForumTopicUnhidden; +# ABSTRACT: The base class for Telegram message 'GeneralForumTopicUnhidden' type. + +use strict; +use warnings; +use 5.018; ## no critic (ProhibitImplicitImport) +use utf8; + +use Mojo::Base 'Teapot::Bot::Object::Base'; + +$Teapot::Bot::Object::GeneralForumTopicUnhidden::VERSION = '0.025'; + + +sub fields { + return { }; +} + +1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +Teapot::Bot::Object::GeneralForumTopicUnhidden - The base class for Telegram message 'GeneralForumTopicUnhidden' type + +=head1 VERSION + +version 0.025 + +=head1 DESCRIPTION +The base class for Telegram message 'GeneralForumTopicUnhidden' type. + +See L for details of the +attributes available for C objects. + +=head1 AUTHOR + +Sergei Fedosov + +=head1 LICENSE AND COPYRIGHT + +This software is copyright (c) 2023 by Sergei Fedosov . + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut diff --git a/lib/Teapot/Bot/Object/Message.pm b/lib/Teapot/Bot/Object/Message.pm index 839560f..f3dcc7e 100644 --- a/lib/Teapot/Bot/Object/Message.pm +++ b/lib/Teapot/Bot/Object/Message.pm @@ -30,7 +30,14 @@ use Teapot::Bot::Object::PhotoSize (); use Teapot::Bot::Object::Invoice (); use Teapot::Bot::Object::Venue (); use Teapot::Bot::Object::SuccessfulPayment (); +use Teapot::Bot::Object::WriteAccessAllowed (); use Teapot::Bot::Object::PassportData (); +use Teapot::Bot::Object::ForumTopicCreated (); +use Teapot::Bot::Object::ForumTopicEdited (); +use Teapot::Bot::Object::ForumTopicClosed (); +use Teapot::Bot::Object::ForumTopicReopened (); +use Teapot::Bot::Object::GeneralForumTopicHidden (); +use Teapot::Bot::Object::GeneralForumTopicUnhidden (); use Teapot::Bot::Object::InlineKeyboardMarkup (); use Teapot::Bot::Object::ProximityAlertTriggered (); use Teapot::Bot::Object::Dice (); @@ -76,6 +83,7 @@ has 'video_note'; # VideoNote has 'voice'; # Voice has 'caption'; has 'caption_entities'; # Array of MessageEntity +has 'has_media_spoiler'; has 'contact'; # Contact has 'dice'; has 'game'; @@ -97,11 +105,15 @@ has 'pinned_message'; # Message has 'invoice'; # Invoice has 'successful_payment'; # SuccessfulPayment has 'connected_website'; +has 'write_access_allowed'; # WriteAccessAllowed has 'passport_data'; # PassportData has 'proximity_alert_triggered'; has 'forum_topic_created'; # ForumTopicCreated +has 'forum_topic_edited'; # ForumTopicEdited has 'forum_topic_closed'; # ForumTopicClosed has 'forum_topic_reopened'; # ForumTopicReopened +has 'general_forum_topic_hidden'; # GeneralForumTopicHidden +has 'general_forum_topic_unhidden'; # GeneralForumTopicUnhidden has 'video_chat_scheduled'; has 'video_chat_started'; has 'video_chat_ended'; @@ -111,51 +123,55 @@ has 'reply_markup'; # Array of InlineKeyboardMarkup sub fields { return { - 'scalar' => [qw/message_id message_thread_id date forward_from_message_id - forward_signature forward_sender_name forward_date - is_topic_message is_automatic_forward edit_date - has_protected_content media_group_id author_signature text - caption new_chat_title delete_chat_photo - group_chat_created supergroup_chat_created - channel_chat_created migrate_to_chat_id - migrate_from_chat_id connected_website/], - 'Teapot::Bot::Object::User' => [qw/from forward_from via_bot new_chat_members left_chat_member /], + 'scalar' => [qw/message_id message_thread_id date forward_from_message_id + forward_signature forward_sender_name forward_date + is_topic_message is_automatic_forward edit_date + has_protected_content media_group_id author_signature text + caption has_media_spoiler new_chat_title delete_chat_photo + group_chat_created supergroup_chat_created + channel_chat_created migrate_to_chat_id + migrate_from_chat_id connected_website/], + 'Teapot::Bot::Object::User' => [qw/from forward_from via_bot new_chat_members left_chat_member /], - 'Teapot::Bot::Object::Chat' => [qw/sender_chat chat forward_from_chat/], - 'Teapot::Bot::Object::Message' => [qw/reply_to_message pinned_message/], - 'Teapot::Bot::Object::MessageEntity' => [qw/entities caption_entities /], + 'Teapot::Bot::Object::Chat' => [qw/sender_chat chat forward_from_chat/], + 'Teapot::Bot::Object::Message' => [qw/reply_to_message pinned_message/], + 'Teapot::Bot::Object::MessageEntity' => [qw/entities caption_entities /], - 'Teapot::Bot::Object::Audio' => [qw/audio/], - 'Teapot::Bot::Object::Document' => [qw/document/], - 'Teapot::Bot::Object::Animation' => [qw/animation/], - 'Teapot::Bot::Object::Game' => [qw/game/], - 'Teapot::Bot::Object::PhotoSize' => [qw/photo new_chat_photo/], - 'Teapot::Bot::Object::Sticker' => [qw/sticker/], - 'Teapot::Bot::Object::Video' => [qw/video/], - 'Teapot::Bot::Object::Voice' => [qw/voice/], - 'Teapot::Bot::Object::VideoNote' => [qw/video_note/], + 'Teapot::Bot::Object::Audio' => [qw/audio/], + 'Teapot::Bot::Object::Document' => [qw/document/], + 'Teapot::Bot::Object::Animation' => [qw/animation/], + 'Teapot::Bot::Object::Game' => [qw/game/], + 'Teapot::Bot::Object::PhotoSize' => [qw/photo new_chat_photo/], + 'Teapot::Bot::Object::Sticker' => [qw/sticker/], + 'Teapot::Bot::Object::Video' => [qw/video/], + 'Teapot::Bot::Object::Voice' => [qw/voice/], + 'Teapot::Bot::Object::VideoNote' => [qw/video_note/], - 'Teapot::Bot::Object::Contact' => [qw/contact/], - 'Teapot::Bot::Object::Location' => [qw/location/], - 'Teapot::Bot::Object::Venue' => [qw/venue/], + 'Teapot::Bot::Object::Contact' => [qw/contact/], + 'Teapot::Bot::Object::Location' => [qw/location/], + 'Teapot::Bot::Object::Venue' => [qw/venue/], - 'Teapot::Bot::Object::Poll' => [qw/poll/], + 'Teapot::Bot::Object::Poll' => [qw/poll/], - 'Teapot::Bot::Object::Invoice' => [qw/invoice/], - 'Teapot::Bot::Object::SuccessfulPayment' => [qw/successful_payment/], - 'Teapot::Bot::Object::PassportData' => [qw/passport_data/], - 'Teapot::Bot::Object::ForumTopicCreated' => [qw/forum_topic_created/], - 'Teapot::Bot::Object::ForumTopicClosed' => [qw/forum_topic_closed/], - 'Teapot::Bot::Object::ForumTopicReopened' => [qw/forum_topic_reopened/], - 'Teapot::Bot::Object::InlineKeyboardMarkup' => [qw/reply_markup/], - 'Teapot::Bot::Object::ProximityAlertTriggered' => [qw/proximity_alert_triggered/], - 'Teapot::Bot::Object::Dice' => [qw/dice/], + 'Teapot::Bot::Object::Invoice' => [qw/invoice/], + 'Teapot::Bot::Object::SuccessfulPayment' => [qw/successful_payment/], + 'Teapot::Bot::Object::WriteAccessAllowed' => [qw/write_access_allowed/], + 'Teapot::Bot::Object::PassportData' => [qw/passport_data/], + 'Teapot::Bot::Object::ForumTopicCreated' => [qw/forum_topic_created/], + 'Teapot::Bot::Object::ForumTopicEdited' => [qw/forum_topic_edited/], + 'Teapot::Bot::Object::ForumTopicClosed' => [qw/forum_topic_closed/], + 'Teapot::Bot::Object::ForumTopicReopened' => [qw/forum_topic_reopened/], + 'Teapot::Bot::Object::GeneralForumTopicHidden' => [qw/general_forum_topic_unhidden/], + 'Teapot::Bot::Object::GeneralForumTopicUnhidden' => [qw/general_forum_topic_unhidden/], + 'Teapot::Bot::Object::InlineKeyboardMarkup' => [qw/reply_markup/], + 'Teapot::Bot::Object::ProximityAlertTriggered' => [qw/proximity_alert_triggered/], + 'Teapot::Bot::Object::Dice' => [qw/dice/], 'Teapot::Bot::Object::MessageAutoDeleteTimerChanged' => [qw/message_auto_delete_timer_changed/], - 'Teapot::Bot::Object::VideoChatScheduled' => [qw/video_chat_scheduled/], - 'Teapot::Bot::Object::VideoChatStarted' => [qw/video_chat_started/], - 'Teapot::Bot::Object::VideoChatEnded' => [qw/video_chat_ended/], + 'Teapot::Bot::Object::VideoChatScheduled' => [qw/video_chat_scheduled/], + 'Teapot::Bot::Object::VideoChatStarted' => [qw/video_chat_started/], + 'Teapot::Bot::Object::VideoChatEnded' => [qw/video_chat_ended/], 'Teapot::Bot::Object::VideoChatParticipantsInvited' => [qw/video_chat_participants_invited/], - 'Teapot::Bot::Object::WebAppData' => [qw/web_app_data/], + 'Teapot::Bot::Object::WebAppData' => [qw/web_app_data/], }; } diff --git a/lib/Teapot/Bot/Object/WriteAccessAllowed.pm b/lib/Teapot/Bot/Object/WriteAccessAllowed.pm new file mode 100644 index 0000000..2a90338 --- /dev/null +++ b/lib/Teapot/Bot/Object/WriteAccessAllowed.pm @@ -0,0 +1,51 @@ +package Teapot::Bot::Object::WriteAccessAllowed; +# ABSTRACT: The base class for Telegram message 'WriteAccessAllowed' type. + +use strict; +use warnings; +use 5.018; ## no critic (ProhibitImplicitImport) +use utf8; + +use Mojo::Base 'Teapot::Bot::Object::Base'; + +$Teapot::Bot::Object::WriteAccessAllowed::VERSION = '0.025'; + + +sub fields { + return { }; +} + +1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +Teapot::Bot::Object::WriteAccessAllowed - The base class for Telegram message 'WriteAccessAllowed' type + +=head1 VERSION + +version 0.025 + +=head1 DESCRIPTION +The base class for Telegram message 'WriteAccessAllowed' type. + +See L for details of the +attributes available for C objects. + +=head1 AUTHOR + +Sergei Fedosov + +=head1 LICENSE AND COPYRIGHT + +This software is copyright (c) 2023 by Sergei Fedosov . + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut