def _admin_buttons(send_botlist_button=False, logs_button=False): n_unapproved = len(Bot.select().where(Bot.approved == False, Bot.disabled == False)) n_suggestions = len(Suggestion.select_all()) n_pending = len(Bot.select_pending_update()) second_row = list() if n_unapproved > 0: second_row.append( KeyboardButton( captions.APPROVE_BOTS + " {}🆕".format(mdformat.number_as_emoji(n_unapproved)))) if n_suggestions > 0: second_row.append( KeyboardButton( captions.APPROVE_SUGGESTIONS + " {}⁉️".format(mdformat.number_as_emoji(n_suggestions)))) buttons = [ [KeyboardButton(captions.EXIT), KeyboardButton(captions.REFRESH)], [ KeyboardButton(captions.FIND_OFFLINE), KeyboardButton(captions.SEND_CONFIG_FILES), ], ] update_row = list() if n_pending > 0: update_row.append( KeyboardButton(captions.PENDING_UPDATE + " {}{}".format( mdformat.number_as_emoji(n_pending), captions.SUGGESTION_PENDING_EMOJI, ))) if send_botlist_button: update_row.append(KeyboardButton(captions.SEND_BOTLIST)) if logs_button: update_row.append(KeyboardButton(captions.SEND_ACTIVITY_LOGS)) if len(update_row) > 0: buttons.insert(1, update_row) if len(second_row) > 0: buttons.insert(1, second_row) return buttons
def approve_suggestions(bot, update, page=0): uid = util.uid_from_update(update) suggestions = Suggestion.select_all() if page * settings.PAGE_SIZE_SUGGESTIONS_LIST >= len(suggestions): # old item deleted, list now too small page = page - 1 if page > 0 else 0 start = page * settings.PAGE_SIZE_SUGGESTIONS_LIST end = start + settings.PAGE_SIZE_SUGGESTIONS_LIST has_prev_page = page > 0 has_next_page = (page + 1) * settings.PAGE_SIZE_SUGGESTIONS_LIST < len( suggestions) suggestions = suggestions[start:end] if len(suggestions) == 0: bot.formatter.send_or_edit(uid, "No more suggestions available.", to_edit=util.mid_from_update(update)) return buttons = [] count = 1 text = "Please choose suggestions to accept.\n" for x in suggestions: number = str(count) + "." text += "\n{} {}".format(number, str(x)) row = [] # Should the suggestion be editable and is it too long? if x.action in Suggestion.TEXTUAL_ACTIONS: row.append( InlineKeyboardButton( "{} {}📝".format(number, Emoji.WHITE_HEAVY_CHECK_MARK), callback_data=util.callback_for_action( CallbackActions.CHANGE_SUGGESTION, { "id": x.id, "page": page }), )) else: row.append( InlineKeyboardButton( "{} {}".format(number, Emoji.WHITE_HEAVY_CHECK_MARK), callback_data=util.callback_for_action( CallbackActions.ACCEPT_SUGGESTION, { "id": x.id, "page": page }), )) row.append( InlineKeyboardButton( "{} {}".format(number, Emoji.CROSS_MARK), callback_data=util.callback_for_action( CallbackActions.REJECT_SUGGESTION, { "id": x.id, "page": page }), )) buttons.append(row) count += 1 page_arrows = list() if has_prev_page: page_arrows.append( InlineKeyboardButton( Emoji.LEFTWARDS_BLACK_ARROW, callback_data=util.callback_for_action( CallbackActions.SWITCH_SUGGESTIONS_PAGE, {"page": page - 1}), )) if has_next_page: page_arrows.append( InlineKeyboardButton( Emoji.BLACK_RIGHTWARDS_ARROW, callback_data=util.callback_for_action( CallbackActions.SWITCH_SUGGESTIONS_PAGE, {"page": page + 1}), )) buttons.append(page_arrows) reply_markup = InlineKeyboardMarkup(buttons) bot.formatter.send_or_edit( uid, util.action_hint(text), reply_markup=reply_markup, to_edit=util.mid_from_update(update), disable_web_page_preview=True, ) return CallbackStates.APPROVING_BOTS