def clear_gbans(bot: Bot, update: Update): banned = sql.get_gban_list() deleted = 0 update.message.reply_text( "*Beginning to cleanup deleted users from global ban database...*\nThis process might take a while...", parse_mode=ParseMode.MARKDOWN) for user in banned: id = user["user_id"] time.sleep(0.1) # Reduce floodwait try: bot.get_chat(id) except BadRequest: deleted += 1 sql.ungban_user(id) update.message.reply_text("Done! {} deleted accounts were removed " \ "from the gbanlist.".format(deleted), parse_mode=ParseMode.MARKDOWN)
def gbanlist(bot: Bot, update: Update): banned_users = sql.get_gban_list() if not banned_users: update.effective_message.reply_text( "There aren't any gbanned users! You're kinder than I expected...") return banfile = 'Gbanned users:\n' for user in banned_users: banfile += "[x] {} - {}\n".format(user["name"], user["user_id"]) if user["reason"]: banfile += "Reason: {}\n".format(user["reason"]) with BytesIO(str.encode(banfile)) as output: output.name = "gbanlist.txt" update.effective_message.reply_document( document=output, filename="gbanlist.txt", caption="Here is the list of currently gbanned users.")