mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Bugfix in /vote
This commit is contained in:
parent
0cfbce8b6b
commit
2e0b2f498a
1 changed files with 8 additions and 2 deletions
|
@ -280,17 +280,23 @@ def on_callback_query(bot: Bot, update: Update):
|
||||||
if user is None:
|
if user is None:
|
||||||
bot.answer_callback_query(update.callback_query.id, show_alert=True,
|
bot.answer_callback_query(update.callback_query.id, show_alert=True,
|
||||||
text="⚠ Il tuo account Telegram non è registrato al RYGdb!"
|
text="⚠ Il tuo account Telegram non è registrato al RYGdb!"
|
||||||
" Registrati con `/register@royalgamesbot <nomeutenteryg>`.", parse_mode="Markdown")
|
" Registrati con `/register@royalgamesbot <nomeutenteryg>`.",
|
||||||
|
parse_mode="Markdown")
|
||||||
return
|
return
|
||||||
question = session.query(db.VoteQuestion).filter_by(message_id=update.callback_query.message.message_id).one()
|
question = session.query(db.VoteQuestion).filter_by(message_id=update.callback_query.message.message_id).one()
|
||||||
answer = session.query(db.VoteAnswer).filter_by(question=question, user=user).one_or_none()
|
answer = session.query(db.VoteAnswer).filter_by(question=question, user=user).one_or_none()
|
||||||
if answer is None:
|
if answer is None:
|
||||||
answer = db.VoteAnswer(question=question, choice=choice, user=user)
|
answer = db.VoteAnswer(question=question, choice=choice, user=user)
|
||||||
session.add(answer)
|
session.add(answer)
|
||||||
|
bot.answer_callback_query(update.callback_query.id, text=f"Hai votato {emoji}.", cache_time=1)
|
||||||
|
elif answer.choice == choice:
|
||||||
|
session.delete(answer)
|
||||||
|
bot.answer_callback_query(update.callback_query.id, text=f"Hai ritratto il tuo voto.", cache_time=1)
|
||||||
else:
|
else:
|
||||||
answer.choice = choice
|
answer.choice = choice
|
||||||
|
bot.answer_callback_query(update.callback_query.id, text=f"Hai cambiato il tuo voto in {emoji}.",
|
||||||
|
cache_time=1)
|
||||||
session.commit()
|
session.commit()
|
||||||
bot.answer_callback_query(update.callback_query.id, text=f"Hai votato {emoji}.", cache_time=1)
|
|
||||||
inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("🔵 Sì", callback_data="vote_yes")],
|
inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("🔵 Sì", callback_data="vote_yes")],
|
||||||
[InlineKeyboardButton("🔴 No", callback_data="vote_no")],
|
[InlineKeyboardButton("🔴 No", callback_data="vote_no")],
|
||||||
[InlineKeyboardButton("⚫️ Astieniti", callback_data="vote_abstain")]])
|
[InlineKeyboardButton("⚫️ Astieniti", callback_data="vote_abstain")]])
|
||||||
|
|
Loading…
Reference in a new issue