osu.py 文件源码

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

项目:pcbot 作者: pckv 项目源码 文件源码
def update_user_data():
    """ Go through all registered members playing osu!, and update their data. """
    global osu_tracking

    # Go through each member playing and give them an "old" and a "new" subsection
    # for their previous and latest user data
    for member_id, profile in osu_config.data["profiles"].items():
        member = discord.utils.find(lambda m: check_playing(m, member_id), client.get_all_members())

        # If the member is not playing anymore, remove them from the tracking data
        if not member:
            if member_id in osu_tracking:
                del osu_tracking[member_id]

            continue

        mode = get_mode(member_id).value
        try:
            user_data = await api.get_user(u=profile, type="id", m=mode)
        except ServerDisconnectedError:
            continue
        except asyncio.TimeoutError:
            logging.warning("Timed out when retrieving osu! info from {} ({})".format(member, profile))
            continue

        # Sleep after using get_user as to not put too much strain on the API at once
        await asyncio.sleep(.2)

        # Just in case something goes wrong, we skip this member (these things are usually one-time occurrences)
        if user_data is None:
            logging.info("Could not retrieve osu! info from {} ({})".format(member, profile))
            continue

        # User is already tracked
        if member_id in osu_tracking:
            # Move the "new" data into the "old" data of this user
            osu_tracking[member_id]["old"] = osu_tracking[member_id]["new"]
        else:
            # If this is the first time, update the user's list of scores for later
            user_scores = await api.get_user_best(u=profile, type="id", limit=score_request_limit, m=mode)
            osu_tracking[member_id] = dict(member=member, scores=user_scores)

        # Update the "new" data
        osu_tracking[member_id]["new"] = user_data
        osu_tracking[member_id]["new"]["ripple"] = True if api.ripple_pattern.match(profile) else False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号