diff --git a/bot.py b/bot.py index f766cc8..f6ac0ab 100644 --- a/bot.py +++ b/bot.py @@ -71,8 +71,32 @@ def update_message(bot, db, callback_id): reply_markup=keyboard) +def send_stats(bot, update, db): + cursor = db.cursor() + query = ("SELECT user_id, name FROM poll NATURAL JOIN message_ids WHERE " + "message_id = ?") + cursor.execute(query, (update.message.forward_from_message_id,)) + voters = [] + for row in cursor: + voters.append(row) + if len(voters) == 0: + bot.send_message(chat_id=update.message.chat_id, text="No Votes") + else: + text = "Voters\n" + for i in voters: + text += f"{i[1]}\n" + bot.send_message(chat_id=update.message.chat_id, text=text, + parse_mode="HTML") + + def post(bot, update, db): chat_id = update.message.chat_id + user_id = update.message.from_user.id + if (update.message.forward_from_chat and + update.message.forward_from_chat.id == config.channel_id and + user_id in config.allowed_users): + send_stats(bot, update, db) + return if chat_id in config.allowed_users: callback_id = get_callback_id(db) photo = update.message.photo[0]