user_in_chat.py 文件源码

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

项目:democracybot 作者: LiaungYip 项目源码 文件源码
def user_is_in_chat(uid: int, cid: int, bot: telegram.Bot):
    # Returns True if the specified user_id is in the specified chat_id.
    #
    # Returns False if:
    # * the bot isn't in the chat (so it can't see the members), or;
    # * the chat doesn't exist, or;
    # * the user isn't in the chat, or;
    # * the user doesn't exist.

    try:
        user = bot.get_chat_member(chat_id=cid, user_id=uid)
    except telegram.error.BadRequest as err:
        if "chat not found" in err.message.lower():
            logger.info(err_chat_not_found % (uid, cid))
            return False
        elif "user not found" in err.message.lower():
            logger.info(err_user_not_found % (uid, cid))
            return False
        else:
            logger.exception("Unhandled exception")
            raise
    logger.info("User %s is in chat %s" % (uid, cid))
    return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号