From 6f95dcfa16087af80af4ba6aef44aeac8e23f016 Mon Sep 17 00:00:00 2001 From: lavadk Date: Mon, 5 Apr 2021 18:15:13 +0300 Subject: [PATCH] liker auto enabling --- .../channel_post_handler.py} | 15 +++++++++++---- .../{button => custom_markup}/comment_handler.py | 0 .../markup_synchronizer.py | 0 liker/{button => custom_markup}/markup_utils.py | 0 4 files changed, 11 insertions(+), 4 deletions(-) rename liker/{button/button_handler.py => custom_markup/channel_post_handler.py} (93%) rename liker/{button => custom_markup}/comment_handler.py (100%) rename liker/{button => custom_markup}/markup_synchronizer.py (100%) rename liker/{button => custom_markup}/markup_utils.py (100%) diff --git a/liker/button/button_handler.py b/liker/custom_markup/channel_post_handler.py similarity index 93% rename from liker/button/button_handler.py rename to liker/custom_markup/channel_post_handler.py index a1420d0..9eefdf1 100644 --- a/liker/button/button_handler.py +++ b/liker/custom_markup/channel_post_handler.py @@ -14,7 +14,7 @@ logger = logging.getLogger(__file__) -class ButtonHandler(TelegramInboxHandler): +class ChannelPostHandler(TelegramInboxHandler): config = inject.attr(Config) hasher = inject.attr(Hasher) telegram_bot = inject.attr(TelegramBot) @@ -25,9 +25,12 @@ class ButtonHandler(TelegramInboxHandler): def channel_post(self, channel_post: types.Message) -> bool: channel_id: int = channel_post.chat.id + str_channel_id = str(channel_id) if not self.enabled_channels.is_enabled(str_channel_id): - return False + is_enabled = self._try_enable_for_channel(channel_id) + if not is_enabled: + return False message_id = channel_post.id @@ -35,7 +38,7 @@ def channel_post(self, channel_post: types.Message) -> bool: enabled_reactions = channel_dict['reactions'] reply_markup = markup_utils.build_reply_markup(enabled_reactions=enabled_reactions, state_dict=None, - handler=constants.BUTTON_HANDLER, + handler=constants.CHANNEL_POST_HANDLER, case_id='') self.markup_synchronizer.add(channel_id=channel_id, message_id=message_id, @@ -48,7 +51,7 @@ def callback_query(self, callback_query: types.CallbackQuery) -> bool: if not telegram_utils.is_button_data_encoded(button_data): return False handler, _case_id, reaction = telegram_utils.decode_button_data(button_data) - if handler != constants.BUTTON_HANDLER: + if handler != constants.CHANNEL_POST_HANDLER: return False if callback_query.message is None: return False @@ -99,3 +102,7 @@ def callback_query(self, callback_query: types.CallbackQuery) -> bool: logger.info(f'Cannot answer callback query, most likely it is expired: {ex}') return True + + def _try_enable_for_channel(self, channel_id: int) -> bool: + + pass diff --git a/liker/button/comment_handler.py b/liker/custom_markup/comment_handler.py similarity index 100% rename from liker/button/comment_handler.py rename to liker/custom_markup/comment_handler.py diff --git a/liker/button/markup_synchronizer.py b/liker/custom_markup/markup_synchronizer.py similarity index 100% rename from liker/button/markup_synchronizer.py rename to liker/custom_markup/markup_synchronizer.py diff --git a/liker/button/markup_utils.py b/liker/custom_markup/markup_utils.py similarity index 100% rename from liker/button/markup_utils.py rename to liker/custom_markup/markup_utils.py