detectedHostLeft() публичный статический Метод

Parse function to detect host leaving.
public static detectedHostLeft ( string message, List channels ) : DetectionReturn
message string
channels List
Результат TwitchLib.Models.Client.DetectionReturn
Пример #1
0
        private void OnReadLine(object sender, ReadLineEventArgs e)
        {
            // Hack to accomodate at least cyrillic characters, possibly more
            string decodedMessage = Encoding.UTF8.GetString(Encoding.Default.GetBytes(e.Line));

            if (_logging)
            {
                Console.WriteLine(decodedMessage);
            }

            #region Chat Parsing
            // On Connected
            if (ChatParsing.detectConnected(decodedMessage))
            {
                _connected = true;
                OnConnected?.Invoke(null, new OnConnectedArgs {
                    Channel = _channel, Username = TwitchUsername
                });
                return;
            }

            // On New Subscriber
            if (ChatParsing.detectNewSubscriber(decodedMessage, _channel))
            {
                OnNewSubscriber?.Invoke(null, new OnNewSubscriberArgs {
                    Subscriber = new NewSubscriber(decodedMessage), Channel = _channel
                });
                return;
            }

            // On Command Received (PURPOSELY DROP THROUGH WITHOUT RETURN)
            if (ChatParsing.detectCommandReceived(decodedMessage, _channel, _channelEmotes, WillReplaceEmotes, _chatCommandIdentifiers))
            {
                var    chatMessage       = new ChatMessage(decodedMessage, ref _channelEmotes, WillReplaceEmotes);
                string command           = chatMessage.Message.Split(' ')?[0].Substring(1, chatMessage.Message.Split(' ')[0].Length - 1) ?? chatMessage.Message.Substring(1, chatMessage.Message.Length - 1);
                var    argumentsAsList   = chatMessage.Message.Split(' ')?.Where(arg => arg != chatMessage.Message[0] + command).ToList <string>() ?? new List <string>();
                string argumentsAsString = chatMessage.Message.Replace(chatMessage.Message.Split(' ')?[0] +" ", "") ?? "";
                OnChatCommandReceived?.Invoke(null, new OnChatCommandReceivedArgs {
                    Command = command, ChatMessage = chatMessage, Channel = _channel, ArgumentsAsList = argumentsAsList, ArgumentsAsString = argumentsAsString
                });
                // purposely drop through without return
            }

            // On Message Received
            if (ChatParsing.detectMessageReceived(decodedMessage, _channel))
            {
                var chatMessage = new ChatMessage(decodedMessage, ref _channelEmotes, WillReplaceEmotes);
                _previousMessage = chatMessage;
                OnMessageReceived?.Invoke(null, new OnMessageReceivedArgs {
                    ChatMessage = chatMessage
                });
                return;
            }

            // On Viewer Joined
            if (ChatParsing.detectViewerJoined(decodedMessage, _channel))
            {
                OnViewerJoined?.Invoke(null, new OnViewerJoinedArgs {
                    Username = decodedMessage.Split('!')[1].Split('@')[0], Channel = _channel
                });
                return;
            }

            // On Viewer Left
            if (ChatParsing.detectedViewerLeft(decodedMessage, _channel))
            {
                OnViewerLeft?.Invoke(null, new OnViewerLeftArgs {
                    Username = decodedMessage.Split(':')[1].Split('!')[0], Channel = _channel
                });
                return;
            }

            // On Moderator Joined
            if (ChatParsing.detectedModeratorJoined(decodedMessage, _channel))
            {
                OnModeratorJoined?.Invoke(null, new OnModeratorJoinedArgs {
                    Username = decodedMessage.Split(' ')[4], Channel = _channel
                });
                return;
            }

            // On Moderator Left
            if (ChatParsing.detectedModeatorLeft(decodedMessage, _channel))
            {
                OnModeratorLeft?.Invoke(null, new OnModeratorLeftArgs {
                    Username = decodedMessage.Split(' ')[4], Channel = _channel
                });
                return;
            }

            // On Incorrect login
            if (ChatParsing.detectedIncorrectLogin(decodedMessage, _channel))
            {
                _client.Disconnect();
                OnIncorrectLogin?.Invoke(null, new OnIncorrectLoginArgs {
                    Exception = new ErrorLoggingInException(decodedMessage, _credentials.TwitchUsername)
                });
                return;
            }

            // On Host Left
            if (ChatParsing.detectedHostLeft(decodedMessage, _channel))
            {
                OnHostLeft?.Invoke(null, null);
                return;
            }

            // On Channel State Changed
            if (ChatParsing.detectedChannelStateChanged(decodedMessage, _channel))
            {
                OnChannelStateChanged?.Invoke(null, new OnChannelStateChangedArgs {
                    ChannelState = new ChannelState(decodedMessage)
                });
                return;
            }

            // On User State Changed
            if (ChatParsing.detectedUserStateChanged(decodedMessage, _channel))
            {
                OnUserStateChanged?.Invoke(null, new OnUserStateChangedArgs {
                    UserState = new UserState(decodedMessage)
                });
                return;
            }

            // On ReSubscriber
            if (ChatParsing.detectedReSubscriber(decodedMessage, _channel))
            {
                OnReSubscriber?.Invoke(null, new OnReSubscriberArgs {
                    ReSubscriber = new ReSubscriber(decodedMessage)
                });
                return;
            }

            // On PING received
            if (ChatParsing.detectedPing(decodedMessage) && !DisableAutoPong)
            {
                SendRaw("PONG :tmi.twitch.tv");
                return;
            }

            // On Hosting Stopped
            if (ChatParsing.detectedHostingStopped(decodedMessage))
            {
                int viewers;
                int.TryParse(decodedMessage.Split(' ')[4], out viewers);
                OnHostingStopped?.Invoke(null, new OnHostingStoppedArgs()
                {
                    Viewers = viewers, HostingChannel = decodedMessage.Split(' ')[2].Remove(0, 1)
                });
                return;
            }

            // On Hosting Started
            if (ChatParsing.detectedHostingStarted(decodedMessage))
            {
                int viewers;
                int.TryParse(decodedMessage.Split(' ')[4], out viewers);
                OnHostingStarted?.Invoke(null, new OnHostingStartedArgs()
                {
                    Viewers = viewers, HostingChannel = decodedMessage.Split(' ')[2].Remove(0, 1), TargetChannel = decodedMessage.Split(' ')[3].Remove(0, 1)
                });
                return;
            }

            // On Existing Users Detected
            if (ChatParsing.detectedExistingUsers(decodedMessage, _credentials.TwitchUsername))
            {
                var parsedUsers = decodedMessage.Replace($":{_credentials.TwitchUsername}.tmi.twitch.tv 353 {_credentials.TwitchUsername} = #{_channel} :", "").Split(' ');
                OnExistingUsersDetected?.Invoke(null, new OnExistingUsersDetectedArgs {
                    Channel       = _channel,
                    ExistingUsers = decodedMessage.Replace($":{_credentials.TwitchUsername}.tmi.twitch.tv 353 {_credentials.TwitchUsername} = #{_channel} :", "").Split(' ').ToList <string>()
                });
                return;
            }
            #endregion

            #region Whisper Parsing
            if (decodedMessage.Split(' ').Count() > 2 && (decodedMessage.Split(' ')[1] == "WHISPER" || decodedMessage.Split(' ')[2] == "WHISPER"))
            {
                // On Whisper Message Received
                if (WhisperParsing.detectedWhisperReceived(decodedMessage, _credentials.TwitchUsername))
                {
                    OnWhisperReceived?.Invoke(null, new OnWhisperReceivedArgs {
                        WhisperMessage = new WhisperMessage(decodedMessage, _credentials.TwitchUsername)
                    });
                    return;
                }

                // On Whisper Command Received
                if (WhisperParsing.detectedWhisperCommandReceived(decodedMessage, _credentials.TwitchUsername, _whisperCommandIdentifiers))
                {
                    var    whisperMessage    = new WhisperMessage(decodedMessage, _credentials.TwitchUsername);
                    string command           = whisperMessage.Message.Split(' ')?[0].Substring(1, whisperMessage.Message.Split(' ')[0].Length - 1) ?? whisperMessage.Message.Substring(1, whisperMessage.Message.Length - 1);
                    var    argumentsAsList   = whisperMessage.Message.Split(' ')?.Where(arg => arg != whisperMessage.Message[0] + command).ToList <string>() ?? new List <string>();
                    string argumentsAsString = whisperMessage.Message.Replace(whisperMessage.Message.Split(' ')?[0] +" ", "") ?? "";
                    OnWhisperCommandReceived?.Invoke(null, new OnWhisperCommandReceivedArgs {
                        Command = command, WhisperMessage = whisperMessage, ArgumentsAsList = argumentsAsList, ArgumentsAsString = argumentsAsString
                    });
                }
            }
            #endregion

            // Any other messages here
            if (_logging)
            {
                Console.WriteLine($"Unaccounted for: {decodedMessage}");
            }
        }