Beispiel #1
0
        private void Client_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            var ircMessage = new IrcMessage(e.Message);

            switch (ircMessage.Command)
            {
            case "001":
                OnLoggedIn();
                break;

            case "JOIN":
            {
                string userName = ircMessage.GetUserName();
                string channel  = ircMessage.GetChannel();

                if (UserName.Equals(userName))
                {
                    OnChannelJoined(channel);
                }
                else
                {
                    OnUserJoined(userName, channel);
                }
                break;
            }

            case "PART":
            {
                string userName = ircMessage.GetUserName();
                string channel  = ircMessage.GetChannel();

                if (UserName.Equals(userName))
                {
                    OnChannelParted(channel);
                }
                else
                {
                    OnUserParted(userName, channel);
                }
                break;
            }

            case "PING":
                string serverAddress = ircMessage.GetParameterByIndex(0);
                OnPingReceived(serverAddress);
                break;

            case "MODE":
                var channelMode = new ChannelMode(ircMessage);
                OnChannelModeReceived(channelMode);
                break;

            default:
                OnUnprocessedIrcMessageReceived(ircMessage);
                break;
            }
            OnIrcMessageReceived(ircMessage);
        }
        protected override void OnUnprocessedIrcMessageReceived(IrcMessage message)
        {
            switch (message.Command)
            {
            case "GLOBALUSERSTATE":
                var globalUserState = new TwitchGlobalUserState(message);
                OnGlobalUserStateReceived(globalUserState);
                break;

            case "PRIVMSG":
                if (message.GetUserName().Equals("jtv"))
                {
                    var hostedChannel = new TwitchHostedChannel(message);
                    OnChannelBeingHosted(hostedChannel);
                }
                else
                {
                    var chatMessage = new TwitchChatMessage(message);
                    OnChatMessageReceived(chatMessage);
                }
                break;

            case "WHISPER":
                var whisperMessage = new TwitchWhisperMessage(message);
                OnWhisperMessageReceived(whisperMessage);
                break;

            case "ROOMSTATE":
                var channelState = new TwitchChannelState(message);
                OnChannelStateChanged(channelState);
                break;

            case "USERSTATE":
                var userState = new TwitchUserState(message);
                OnUserStateReceived(userState);
                break;

            case "USERNOTICE":
                FireAnEventBasedOnUserNoticeType(message);
                break;

            case "HOSTTARGET":
                var channelHost = new TwitchChannelHost(message);
                if (!string.IsNullOrEmpty(channelHost.TargetChannel))
                {
                    OnChannelHostingStarted(channelHost);
                }
                else
                {
                    OnChannelHostingStopped(channelHost);
                }
                break;

            case "CLEARCHAT":
                if (message.Tags.ContainsKey("ban-duration"))
                {
                    var userTimeout = new TwitchUserTimeout(message);
                    OnUserTimedOut(userTimeout);
                }
                else if (message.Tags.ContainsKey("ban-reason"))
                {
                    var userBan = new TwitchUserBan(message);
                    OnUserBanned(userBan);
                }
                else
                {
                    string channel = message.GetChannel();
                    OnChatCleared(channel);
                }
                break;

            default:
                base.OnUnprocessedIrcMessageReceived(message);
                break;
            }
        }