Show who voted when the image is forwarded.

This commit is contained in:
Ceda EI 2019-01-07 17:37:02 +05:30
parent d04ddba9a3
commit b71174918b
1 changed files with 24 additions and 0 deletions

24
bot.py
View File

@ -71,8 +71,32 @@ def update_message(bot, db, callback_id):
reply_markup=keyboard) 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"<a href='tg://user?id={i[0]}'>{i[1]}</a>\n"
bot.send_message(chat_id=update.message.chat_id, text=text,
parse_mode="HTML")
def post(bot, update, db): def post(bot, update, db):
chat_id = update.message.chat_id 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: if chat_id in config.allowed_users:
callback_id = get_callback_id(db) callback_id = get_callback_id(db)
photo = update.message.photo[0] photo = update.message.photo[0]