Esempio n. 1
0
 def match_end(self, payload: EventPayload, user: DiscordUser):
     ws.send_notification('match_event', payload)
     game_id = str(payload['game_id'])
     try:
         match = TempMatch.objects.get(id=game_id)
         match.delete()
     except TempMatch.DoesNotExist:
         pass
Esempio n. 2
0
def twitch_stream_update(sender: WebSubView, webhook_name: str, uuid, data,
                         **kwargs):
    if not webhook_name == 'streams':
        return
    try:
        active = data != []
        ts = TwitchStream.objects.get(uuid=uuid)
        ts.extra_data = data
        ts.active = active
        ts.save()

        action = ws.types.STREAM_START if active else ws.types.STREAM_STOP
        ws.send_notification(action, TwitchStreamSerializer(ts).data)
    except TwitchStream.DoesNotExist:
        log.error(f"Missing TwitchStream object for {uuid}")
Esempio n. 3
0
def user_update(sender, instance, created, **kwargs):
    """
    Sends updates to the user model being changed. One common reason is
    updating a client heartbeat. Send this out.
    Parameters
    ----------
    sender
    instance
    created
    kwargs

    Returns
    -------

    """
    payload = DiscordUserSerializer(instance).data
    ws.send_notification(ws.types.USER_UPDATE, payload)
Esempio n. 4
0
def create(user, payload):
    m, created = get_or_create_match(payload)
    update_client(user, m, connected=True)

    players = payload.get('players')
    if isinstance(players, list):
        # Serialize object from profile id
        container = []
        for p in players:
            profile = get_or_create_profile(p['handle'])
            container.append(SC2ProfileSerializer(profile).data)
        payload['players'] = container

    if created:
        print("Notification Sent")
        ws.send_notification(payload)
    else:
        print("Match existed")
    return m
Esempio n. 5
0
def new_match(sender, instance: Match, **kwargs):
    """
    Fires whenever a new match is made. We'll serialize a response with this
    and Rosters as they are most commonly used.
    Parameters
    ----------
    sender
    instance
    kwargs

    Returns
    -------

    """
    log.debug('in new_match signal')
    match = serializers.MatchFullSerializer(instance).data
    streamers = serializers.MatchStreamersSerializer(instance.streamers,
                                                     many=True).data

    payload = {'match': match, 'streamers': streamers}
    log.debug('sending new match notification')
    ws.send_notification('new_match', payload)
Esempio n. 6
0
def stream_webhook_update(sender: WebSubView, webhook_name, uuid, data,
                          **kwargs):
    data = data.get('data')
    if webhook_name != 'streams':
        return
    if not isinstance(data, list):
        return
    try:
        ts = TwitchStream.objects.get(uuid=uuid)
        log.info(f"Got Twitchstream instance with {uuid}")
        ts.active = data != []
        ts.save()
        type = ws.types.STREAM_START if ts.active else ws.types.STREAM_STOP
        payload = {
            'type': type,
            'user_id': ts.user.id,
            'data': data,
        }
        ws.send_notification(type, payload)
    except TwitchStream.DoesNotExist:
        log.info(f"Could not get TwitchStream Instance with {uuid}")
        pass
    log.info("Got stream event. Populated Instance {request}")
Esempio n. 7
0
def match_delete(sender, instance: Match, **kwargs):
    serialized = serializers.BasicMatchSerializer(instance)
    ws.send_notification(ws.types.MATCH_DELETE, serialized.data)