-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e1233c
commit 163ccae
Showing
4 changed files
with
34 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import logging | ||
|
||
from telegram import Update | ||
from telegram.ext import ContextTypes | ||
|
||
|
||
async def receive_poll_answer( | ||
update: Update, context: ContextTypes.DEFAULT_TYPE | ||
) -> None: | ||
# TODO save polls to db and query them instead saving them to bot_data | ||
"""Summarize a users poll vote""" | ||
answer = update.poll_answer | ||
if not answer.option_ids: | ||
return # It's retake poll action, ignore it | ||
if not answer.option_ids: # Poll retract, delete previous vote | ||
del context.bot_data[answer.poll_id]["results"][update.effective_user.id] | ||
return | ||
if context.bot_data: | ||
answered_poll = context.bot_data[answer.poll_id] | ||
user_id = update.effective_user.id | ||
result = answered_poll["questions"][answer.option_ids[0]] | ||
context.bot_data[answer.poll_id]["results"][user_id] = result | ||
else: | ||
# failed to save poll answer. | ||
# Ussually happens for polls that are sent to the bot before it started and not updated | ||
# TODO save polls to db and query them instead saving them to bot_data | ||
return | ||
logging.error( | ||
"Failed to save poll answer. Usually happens for polls that are sent to the bot before it " | ||
"started and not updated", | ||
exc_info=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters