vote.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:democracybot 作者: LiaungYip 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号