def get_polls(user_id: int, bot: telegram.Bot):
# Gets a list of polls that the given user_id is allowed to vote in.
# * The poll must be active.
# * The user must belong to the poll's target_chat. (This is determined
# by asking the Telegram API - "Does user 123 belong to chat -456?")
all_polls = polls_db.all()
# Convert to set to get unique values
target_chats = set([p['target_chat'] for p in all_polls
if p['active'] == True])
# Ask telegram API - is user 123 in chat -456?
chats_user_is_in = [c for c in target_chats
if user_is_in_chat(user_id, c, bot)]
valid_polls = [p for p in all_polls
if p['target_chat'] in chats_user_is_in
and p['active'] == True]
return valid_polls
评论列表
文章目录