Beispiel #1
0
async def __populate_additional_details(
        event: Event,
        discussions_json: object,
        db_name: str = SCRAPER_DB_NAME) -> None:
    """Populates additional details in the given event from the beatmapset discussion json (e.g. who voted)."""
    if event.discussion and (not event.discussion.user
                             or not event.discussion.content):
        if not __complete_discussion_context(event.discussion,
                                             db_name=db_name):
            # After being deleted, many properties of discussions are inaccessible without referring to cached information.
            # Without cached information, we skip the event, since this its context is no longer visible to the public anyway.
            event.marked_for_deletion = True
            return

    if event.type in [types.NOMINATE]:
        # Nominate/qualify content should reflect recent praise/hype/note content.
        event.content = get_nomination_comment(event, discussions_json)

    if event.type in [types.DISQUALIFY, types.RESET]:
        # Event content should reflect discussion content.
        if event.discussion:  # Discussion may have been deleted.
            event.content = event.discussion.content

    if not discussions_json:
        # Mapset has no discussion, probably associated with some legacy thread (e.g. ranked before modding v2).
        return

    beatmapset_json = discussions_json["beatmapset"]
    for page_event in get_map_page_event_jsons(event.beatmapset,
                                               discussions_json):
        # Likelihood that two same type of events happen in the same second is very unlikely,
        # so this'll work as identification (we have no access to actual event ids on scraping side, so can't use that).
        same_time = event.time == from_string(page_event["created_at"])
        same_type = event.type == page_event["type"]
        if same_time and same_type:
            if event.type in [types.RESOLVE, types.REOPEN]:
                # Event user should be whoever resolved or reopened, rather than the discussion author.
                post_author = discussion_parser.parse_discussion_post_author(
                    page_event["comment"]["beatmap_discussion_post_id"],
                    beatmapset_json)
                event.user = post_author

            if event.type in [types.KUDOSU_GAIN, types.KUDOSU_LOSS]:
                # Event user should be whoever gave or removed the kudosu, not the discssion author.
                kudosu_author = discussion_parser.parse_user(
                    page_event["comment"]["new_vote"]["user_id"],
                    beatmapset_json)
                event.user = kudosu_author
Beispiel #2
0
async def populate_from_bnsite(event: Event) -> None:
    """Populates the given event using the bnsite API if possible."""
    if event.type in [types.REMOVE, types.ADD]:
        # Group removal content should reflect the bnsite removal reason (e.g. Kicked/Resigned)
        event.content = get_group_bnsite_comment(event)
        event.group.mode = get_group_bnsite_mode(event)