From d6c1a753a1dd67fa2baf8f5cb8077500d0f9e095 Mon Sep 17 00:00:00 2001 From: drendog <53359960+drendog@users.noreply.github.com> Date: Sat, 24 Jun 2023 00:20:32 +0200 Subject: [PATCH 1/2] feat: add missing arg on doc --- modules/utils/keyboard_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/utils/keyboard_util.py b/modules/utils/keyboard_util.py index a5392cca..14c7913b 100644 --- a/modules/utils/keyboard_util.py +++ b/modules/utils/keyboard_util.py @@ -119,6 +119,7 @@ def get_paused_kb(page: int, items_per_page: int) -> InlineKeyboardMarkup: Args: page: page of the autoreplies + items_per_page: number of items per page Returns: autoreplies keyboard append with resume button From fe89672f858c855df9c208b796438490a9c20d8b Mon Sep 17 00:00:00 2001 From: drendog <53359960+drendog@users.noreply.github.com> Date: Tue, 27 Jun 2023 00:02:15 +0200 Subject: [PATCH 2/2] feat: show username on approval when user enable credits --- modules/handlers/callback_handlers.py | 6 +++++- modules/utils/info_util.py | 11 +++++++---- modules/utils/keyboard_util.py | 22 +++++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/modules/handlers/callback_handlers.py b/modules/handlers/callback_handlers.py index 8a85e655..4ab06449 100644 --- a/modules/handlers/callback_handlers.py +++ b/modules/handlers/callback_handlers.py @@ -127,8 +127,12 @@ def approve_status_callback(info: EventInfo, pending_post = PendingPost.from_group( group_id=info.chat_id, g_message_id=info.message_id) if pending_post: + user = User(pending_post.user_id) + username = None + if user.is_credited: + username = user.username keyboard = update_approve_kb( - get_approve_kb().inline_keyboard, pending_post) + get_approve_kb(username).inline_keyboard, pending_post) else: logger.error("confirm_callback: invalid arg '%s'", arg) diff --git a/modules/utils/info_util.py b/modules/utils/info_util.py index 7220ab6e..783385d4 100644 --- a/modules/utils/info_util.py +++ b/modules/utils/info_util.py @@ -241,7 +241,10 @@ def send_post_to_admins(self) -> bool: message = self.__message.reply_to_message group_id = Config.meme_get('group_id') poll = message.poll # if the message is a poll, get its reference - + user = User(message.from_user.id) + username = None + if user.is_credited: + username = message.from_user.username try: if poll: # makes sure the poll is anonym g_message_id = self.__bot.send_poll(chat_id=group_id, @@ -250,19 +253,19 @@ def send_post_to_admins(self) -> bool: type=poll.type, allows_multiple_answers=poll.allows_multiple_answers, correct_option_id=poll.correct_option_id, - reply_markup=get_approve_kb()).message_id + reply_markup=get_approve_kb(username)).message_id elif message.text and message.entities: # maintains the previews, if present show_preview = self.user_data.get('show_preview', True) g_message_id = self.__bot.send_message(chat_id=group_id, text=message.text, - reply_markup=get_approve_kb(), + reply_markup=get_approve_kb(username), entities=message.entities, disable_web_page_preview=not show_preview).message_id else: g_message_id = self.__bot.copy_message(chat_id=group_id, from_chat_id=message.chat_id, message_id=message.message_id, - reply_markup=get_approve_kb()).message_id + reply_markup=get_approve_kb(username)).message_id except BadRequest as ex: logger.error("Sending the post on send_post_to: %s", ex) return False diff --git a/modules/utils/keyboard_util.py b/modules/utils/keyboard_util.py index 14c7913b..cef20290 100644 --- a/modules/utils/keyboard_util.py +++ b/modules/utils/keyboard_util.py @@ -80,16 +80,28 @@ def get_stats_kb() -> InlineKeyboardMarkup: return InlineKeyboardMarkup(keyboard) -def get_approve_kb() -> InlineKeyboardMarkup: +def get_approve_kb(username: Optional[str] = None) -> InlineKeyboardMarkup: """Generates the InlineKeyboard for the pending post + Args: + username: username of the user only if is credited + Returns: new inline keyboard """ - return InlineKeyboardMarkup([[ - InlineKeyboardButton("🟢 0", callback_data="meme_approve_yes,"), - InlineKeyboardButton("🔴 0", callback_data="meme_approve_no,") - ], [InlineKeyboardButton("⏹ Stop", callback_data="meme_approve_status,pause,0")]]) + kb = [] + + if username: + kb.append([InlineKeyboardButton(f"Credits: {username}", callback_data=f"meme_credit,{username}")]) + + kb.extend([ + [ + InlineKeyboardButton("🟢 0", callback_data="meme_approve_yes,"), + InlineKeyboardButton("🔴 0", callback_data="meme_approve_no,") + ], + [InlineKeyboardButton("⏹ Stop", callback_data="meme_approve_status,pause,0")] + ]) + return InlineKeyboardMarkup(kb) def get_autoreply_kb(page: int, items_per_page: int) -> List[List[InlineKeyboardButton]]: """Generates the keyboard for the autoreplies