Ejemplo n.º 1
0
        private void parseMessage(string message)
        {
            string type = JObject.Parse(message).SelectToken("type")?.ToString();

            switch (type.ToLower())
            {
            case "response":
                Models.PubSub.Responses.Response resp = new Models.PubSub.Responses.Response(message);
                if (previousRequest != null && previousRequest.Nonce.ToLower() == resp.Nonce.ToLower())
                {
                    OnListenResponse?.Invoke(this, new OnListenResponseArgs {
                        Response = resp, Topic = previousRequest.Topic, Successful = resp.Successful
                    });
                    return;
                }
                break;

            case "message":
                Models.PubSub.Responses.Message msg = new Models.PubSub.Responses.Message(message);
                switch (msg.Topic.Split('.')[0])
                {
                case "whispers":
                    Whisper whisper = (Whisper)msg.messageData;
                    OnWhisper?.Invoke(this, new OnWhisperArgs {
                        Whisper = whisper
                    });
                    return;

                case "chat_moderator_actions":
                    ChatModeratorActions cMA = (ChatModeratorActions)msg.messageData;
                    string reason            = "";
                    switch (cMA.ModerationAction.ToLower())
                    {
                    case "timeout":
                        if (cMA.Args.Count > 2)
                        {
                            reason = cMA.Args[2];
                        }
                        OnTimeout?.Invoke(this, new OnTimeoutArgs {
                            TimedoutBy      = cMA.CreatedBy, TimedoutUser = cMA.Args[0],
                            TimeoutDuration = TimeSpan.FromSeconds(int.Parse(cMA.Args[1])), TimeoutReason = reason
                        });
                        return;

                    case "ban":
                        if (cMA.Args.Count > 1)
                        {
                            reason = cMA.Args[1];
                        }
                        OnBan?.Invoke(this, new OnBanArgs {
                            BannedBy = cMA.CreatedBy, BannedUser = cMA.Args[0], BanReason = reason
                        });
                        return;

                    case "unban":
                        OnUnban?.Invoke(this, new OnUnbanArgs {
                            UnbannedBy = cMA.CreatedBy, UnbannedUser = cMA.Args[0]
                        });
                        return;

                    case "untimeout":
                        OnUntimeout?.Invoke(this, new OnUntimeoutArgs {
                            UntimeoutedBy = cMA.CreatedBy, UntimeoutedUser = cMA.Args[0]
                        });
                        return;

                    case "host":
                        OnHost?.Invoke(this, new OnHostArgs {
                            HostedChannel = cMA.Args[0], Moderator = cMA.CreatedBy
                        });
                        return;

                    case "subscribers":
                        OnSubscribersOnly?.Invoke(this, new OnSubscribersOnlyArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "subscribersoff":
                        OnSubscribersOnlyOff?.Invoke(this, new OnSubscribersOnlyOffArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "clear":
                        OnClear?.Invoke(this, new OnClearArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "emoteonly":
                        OnEmoteOnly?.Invoke(this, new OnEmoteOnlyArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "emoteonlyoff":
                        OnEmoteOnlyOff?.Invoke(this, new OnEmoteOnlyOffArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "r9kbeta":
                        OnR9kBeta?.Invoke(this, new OnR9kBetaArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "r9kbetaoff":
                        OnR9kBetaOff?.Invoke(this, new OnR9kBetaOffArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;
                    }
                    break;

                case "channel-bitsevents":
                    ChannelBitsEvents cBE = (ChannelBitsEvents)msg.messageData;
                    OnBitsReceived?.Invoke(this, new OnBitsReceivedArgs {
                        BitsUsed    = cBE.BitsUsed, ChannelId = cBE.ChannelId, ChannelName = cBE.ChannelName,
                        ChatMessage = cBE.ChatMessage, Context = cBE.Context, Time = cBE.Time, TotalBitsUsed = cBE.TotalBitsUsed, UserId = cBE.UserId, Username = cBE.Username
                    });
                    return;

                case "video-playback":
                    VideoPlayback vP = (VideoPlayback)msg.messageData;
                    switch (vP.Type)
                    {
                    case Enums.VideoPlaybackType.StreamDown:
                        OnStreamDown?.Invoke(this, new OnStreamDownArgs {
                            PlayDelay = vP.PlayDelay, ServerTime = vP.ServerTime
                        });
                        return;

                    case Enums.VideoPlaybackType.StreamUp:
                        OnStreamUp?.Invoke(this, new OnStreamUpArgs {
                            PlayDelay = vP.PlayDelay, ServerTime = vP.ServerTime
                        });
                        return;

                    case Enums.VideoPlaybackType.ViewCount:
                        OnViewCount?.Invoke(this, new OnViewCountArgs {
                            ServerTime = vP.ServerTime, Viewers = vP.Viewers
                        });
                        return;
                    }
                    break;
                }
                break;
            }
            if (logging)
            {
                unaccountedFor(message);
            }
        }
Ejemplo n.º 2
0
        private void ParseMessage(string message)
        {
            var type = JObject.Parse(message).SelectToken("type")?.ToString();

            switch (type?.ToLower())
            {
            case "response":
                var resp = new Models.PubSub.Responses.Response(message);
                if (_previousRequests.Count != 0)
                {
                    foreach (var request in _previousRequests)
                    {
                        if (string.Equals(request.Nonce, resp.Nonce, StringComparison.CurrentCultureIgnoreCase))
                        {
                            OnListenResponse?.Invoke(this, new OnListenResponseArgs {
                                Response = resp, Topic = request.Topic, Successful = resp.Successful
                            });
                        }
                    }
                    return;
                }
                break;

            case "message":
                var msg = new Models.PubSub.Responses.Message(message);
                switch (msg.Topic.Split('.')[0])
                {
                case "channel-subscribe-events-v1":
                    var subscription = msg.messageData as ChannelSubscription;
                    OnChannelSubscription?.Invoke(this, new OnChannelSubscriptionArgs {
                        Subscription = subscription
                    });
                    return;

                case "whispers":
                    var whisper = (Whisper)msg.messageData;
                    OnWhisper?.Invoke(this, new OnWhisperArgs {
                        Whisper = whisper
                    });
                    return;

                case "chat_moderator_actions":
                    var cMA    = msg.messageData as ChatModeratorActions;
                    var reason = "";
                    switch (cMA?.ModerationAction.ToLower())
                    {
                    case "timeout":
                        if (cMA.Args.Count > 2)
                        {
                            reason = cMA.Args[2];
                        }
                        OnTimeout?.Invoke(this, new OnTimeoutArgs
                        {
                            TimedoutBy      = cMA.CreatedBy,
                            TimedoutById    = cMA.CreatedByUserId,
                            TimedoutUserId  = cMA.TargetUserId,
                            TimeoutDuration = TimeSpan.FromSeconds(int.Parse(cMA.Args[1])),
                            TimeoutReason   = reason,
                            TimedoutUser    = cMA.Args[0]
                        });
                        return;

                    case "ban":
                        if (cMA.Args.Count > 1)
                        {
                            reason = cMA.Args[1];
                        }
                        OnBan?.Invoke(this, new OnBanArgs {
                            BannedBy = cMA.CreatedBy, BannedByUserId = cMA.CreatedByUserId, BannedUserId = cMA.TargetUserId, BanReason = reason, BannedUser = cMA.Args[0]
                        });
                        return;

                    case "unban":
                        OnUnban?.Invoke(this, new OnUnbanArgs {
                            UnbannedBy = cMA.CreatedBy, UnbannedByUserId = cMA.CreatedByUserId, UnbannedUserId = cMA.TargetUserId
                        });
                        return;

                    case "untimeout":
                        OnUntimeout?.Invoke(this, new OnUntimeoutArgs {
                            UntimeoutedBy = cMA.CreatedBy, UntimeoutedByUserId = cMA.CreatedByUserId, UntimeoutedUserId = cMA.TargetUserId
                        });
                        return;

                    case "host":
                        OnHost?.Invoke(this, new OnHostArgs {
                            HostedChannel = cMA.Args[0], Moderator = cMA.CreatedBy
                        });
                        return;

                    case "subscribers":
                        OnSubscribersOnly?.Invoke(this, new OnSubscribersOnlyArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "subscribersoff":
                        OnSubscribersOnlyOff?.Invoke(this, new OnSubscribersOnlyOffArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "clear":
                        OnClear?.Invoke(this, new OnClearArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "emoteonly":
                        OnEmoteOnly?.Invoke(this, new OnEmoteOnlyArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "emoteonlyoff":
                        OnEmoteOnlyOff?.Invoke(this, new OnEmoteOnlyOffArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "r9kbeta":
                        OnR9kBeta?.Invoke(this, new OnR9kBetaArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;

                    case "r9kbetaoff":
                        OnR9kBetaOff?.Invoke(this, new OnR9kBetaOffArgs {
                            Moderator = cMA.CreatedBy
                        });
                        return;
                    }
                    break;

                case "channel-bits-events-v1":
                    var cBE = msg.messageData as ChannelBitsEvents;
                    if (cBE != null)
                    {
                        OnBitsReceived?.Invoke(this, new OnBitsReceivedArgs
                        {
                            BitsUsed      = cBE.BitsUsed,
                            ChannelId     = cBE.ChannelId,
                            ChannelName   = cBE.ChannelName,
                            ChatMessage   = cBE.ChatMessage,
                            Context       = cBE.Context,
                            Time          = cBE.Time,
                            TotalBitsUsed = cBE.TotalBitsUsed,
                            UserId        = cBE.UserId,
                            Username      = cBE.Username
                        });
                    }
                    return;

                case "video-playback":
                    var vP = msg.messageData as VideoPlayback;
                    switch (vP?.Type)
                    {
                    case VideoPlaybackType.StreamDown:
                        OnStreamDown?.Invoke(this, new OnStreamDownArgs {
                            ServerTime = vP.ServerTime
                        });
                        return;

                    case VideoPlaybackType.StreamUp:
                        OnStreamUp?.Invoke(this, new OnStreamUpArgs {
                            PlayDelay = vP.PlayDelay, ServerTime = vP.ServerTime
                        });
                        return;

                    case VideoPlaybackType.ViewCount:
                        OnViewCount?.Invoke(this, new OnViewCountArgs {
                            ServerTime = vP.ServerTime, Viewers = vP.Viewers
                        });
                        return;
                    }
                    break;
                }
                break;
            }
            if (_logging)
            {
                UnaccountedFor(message);
            }
        }
Ejemplo n.º 3
0
        private void parseMessage(string message)
        {
            string type = JObject.Parse(message).SelectToken("type")?.ToString();

            switch(type.ToLower())
            {
                case "response":
                    Models.PubSub.Responses.Response resp = new Models.PubSub.Responses.Response(message);
                    if (previousRequest != null && previousRequest.Nonce.ToLower() == resp.Nonce.ToLower())
                    {
                       OnListenResponse?.Invoke(this, new OnListenResponseArgs { Response = resp, Topic = previousRequest.Topic, Successful = resp.Successful });
                        return;
                    }
                    break;
                case "message":
                    Models.PubSub. Responses.Message msg = new Models.PubSub.Responses.Message(message);
                    switch(msg.Topic.Split('.')[0])
                    {
                        case "whispers":
                            Whisper whisper = (Whisper)msg.messageData;
                            OnWhisper?.Invoke(this, new OnWhisperArgs { Whisper = whisper });
                            return;
                        case "chat_moderator_actions":
                            ChatModeratorActions cMA = (ChatModeratorActions)msg.messageData;
                            string reason = "";
                            switch (cMA.ModerationAction.ToLower())
                            {
                                case "timeout":
                                    if (cMA.Args.Count > 2)
                                        reason = cMA.Args[2];
                                   OnTimeout?.Invoke(this, new OnTimeoutArgs { TimedoutBy = cMA.CreatedBy, TimedoutUser = cMA.Args[0],
                                        TimeoutDuration = TimeSpan.FromSeconds(int.Parse(cMA.Args[1])), TimeoutReason = reason });
                                    return;
                                case "ban":
                                    if (cMA.Args.Count > 1)
                                        reason = cMA.Args[1];
                                   OnBan?.Invoke(this, new OnBanArgs { BannedBy = cMA.CreatedBy, BannedUser = cMA.Args[0], BanReason = reason });
                                    return;
                                case "unban":
                                   OnUnban?.Invoke(this, new OnUnbanArgs { UnbannedBy = cMA.CreatedBy, UnbannedUser = cMA.Args[0] });
                                    return;
                                case "untimeout":
                                   OnUntimeout?.Invoke(this, new OnUntimeoutArgs { UntimeoutedBy = cMA.CreatedBy, UntimeoutedUser = cMA.Args[0] });
                                    return;
                                case "host":
                                   OnHost?.Invoke(this, new OnHostArgs { HostedChannel = cMA.Args[0], Moderator = cMA.CreatedBy });
                                    return;
                                case "subscribers":
                                   OnSubscribersOnly?.Invoke(this, new OnSubscribersOnlyArgs { Moderator = cMA.CreatedBy });
                                    return;
                                case "subscribersoff":
                                   OnSubscribersOnlyOff?.Invoke(this, new OnSubscribersOnlyOffArgs { Moderator = cMA.CreatedBy });
                                    return;
                                case "clear":
                                   OnClear?.Invoke(this, new OnClearArgs { Moderator = cMA.CreatedBy });
                                    return;
                                case "emoteonly":
                                   OnEmoteOnly?.Invoke(this, new OnEmoteOnlyArgs { Moderator = cMA.CreatedBy });
                                    return;
                                case "emoteonlyoff":
                                   OnEmoteOnlyOff?.Invoke(this, new OnEmoteOnlyOffArgs { Moderator = cMA.CreatedBy });
                                    return;
                                case "r9kbeta":
                                   OnR9kBeta?.Invoke(this, new OnR9kBetaArgs { Moderator = cMA.CreatedBy });
                                    return;
                                case "r9kbetaoff":
                                   OnR9kBetaOff?.Invoke(this, new OnR9kBetaOffArgs { Moderator = cMA.CreatedBy });
                                    return;

                            }
                            break;
                        case "channel-bitsevents":
                            ChannelBitsEvents cBE = (ChannelBitsEvents)msg.messageData;
                            OnBitsReceived?.Invoke(this, new OnBitsReceivedArgs { BitsUsed = cBE.BitsUsed, ChannelId = cBE.ChannelId, ChannelName = cBE.ChannelName,
                                ChatMessage = cBE.ChatMessage, Context = cBE.Context, Time = cBE.Time, TotalBitsUsed = cBE.TotalBitsUsed, UserId = cBE.UserId, Username = cBE.Username});
                            return;
                        case "video-playback":
                            VideoPlayback vP = (VideoPlayback)msg.messageData;
                            switch(vP.Type)
                            {
                                case VideoPlayback.TypeEnum.StreamDown:
                                   OnStreamDown?.Invoke(this, new OnStreamDownArgs { PlayDelay = vP.PlayDelay, ServerTime = vP.ServerTime });
                                    return;
                                case VideoPlayback.TypeEnum.StreamUp:
                                   OnStreamUp?.Invoke(this, new OnStreamUpArgs { PlayDelay = vP.PlayDelay, ServerTime = vP.ServerTime });
                                    return;
                                case VideoPlayback.TypeEnum.ViewCount:
                                   OnViewCount?.Invoke(this, new OnViewCountArgs { ServerTime = vP.ServerTime, Viewers = vP.Viewers });
                                    return;
                            }
                            break;
                    }
                    break;
            }
            if (logging)
                unaccountedFor(message);
        }