Hardly.Library.Twitch.TwitchChatEvent.Parse C# (CSharp) Method

Parse() static private method

static private Parse ( ITwitchFactory factory, string chatEventCommand ) : TwitchChatEvent
factory ITwitchFactory
chatEventCommand string
return TwitchChatEvent
        internal static TwitchChatEvent Parse(ITwitchFactory factory, string chatEventCommand)
        {
            string command;

            // TODO, support Mod events -- e.g. :jtv MODE #hardlysober +o arbedii

            if(chatEventCommand.StartsWith("PING")) {
                command = "PING";
            } else {
                command = chatEventCommand.GetBetween(" ", " ");
            }

            if(command.Equals("PRIVMSG")) {
                TwitchChannel channel = ParseChannel(factory, chatEventCommand);
                TwitchUser user = ParseUser(factory, chatEventCommand);
                string message = chatEventCommand.GetAfter("#" + channel.user.userName + " :");

                return new TwitchChatMessage(channel, user, message);
            } else if(command.Equals("WHISPER")) {
                TwitchUser user = ParseUser(factory, chatEventCommand);
                string message = chatEventCommand.GetAfter(" :");

                return new TwitchChatWhisper(user, message);
            } else if(command.Equals("PING")) {
                return new TwitchChatPing();
            } else {
                return new TwitchChatUnknownEvent(chatEventCommand);
            }
        }

Usage Example

コード例 #1
0
        private TwitchChatEvent GetNextChatEvent()
        {
            string chatEventCommand = ircClient.ReadNextLine_BLOCKING();

            if (chatEventCommand == null)
            {
                if (Reconnect())
                {
                    return(GetNextChatEvent());
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                return(TwitchChatEvent.Parse(factory, chatEventCommand));
            }
        }