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 a5392cca..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 @@ -119,6 +131,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