Skip to content

Commit

Permalink
liker auto enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
lavadk committed Apr 5, 2021
1 parent 1c00bc8 commit 6f95dcf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,17 +25,20 @@ 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

channel_dict = self.enabled_channels.get_channel_dict(str_channel_id)
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,
Expand All @@ -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
Expand Down Expand Up @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6f95dcf

Please sign in to comment.