Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show username on approval when spot is with enabled credits #114

Draft
wants to merge 2 commits into
base: upgrade
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion modules/handlers/callback_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 7 additions & 4 deletions modules/utils/info_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
23 changes: 18 additions & 5 deletions modules/utils/keyboard_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down