예제 #1
0
파일: MainBot.cs 프로젝트: Luth/TwitchBot
        public void ListnerThread()
        {
            while (true)
            {
                MessageBundle msg = _irc.parseMessage();
                switch (msg.type)
                {
                case MessageBundle.Type.UNKNOWN:
#if DEBUG
                    Console.WriteLine("Unknown: " + msg.message);
#endif
                    break;

                case MessageBundle.Type.JOIN:
                    Console.WriteLine("Joined: " + msg.message);
                    break;

                case MessageBundle.Type.TEXT:
                    if (msg.message[0] == '!')
                    {
                        handleCommand(msg);
                    }
                    break;
                }
            }
        }
예제 #2
0
 private void handleCommand( MessageBundle msg )
 {
     string[] parts = msg.message.Split( ' ' );
     string cmd = parts[0];
     string[] opts = null;
     if ( parts.Length > 1 ) {
         opts = new string[parts.Length - 1];
         Array.Copy( parts, 1, opts, 0, parts.Length - 1 );
     }
     new PlayerCommand( msg.username ).whisperCommand( cmd, opts );
 }
예제 #3
0
        private void handleCommand(MessageBundle msg)
        {
            string[] parts = msg.message.Split(' ');
            string   cmd   = parts[0];

            string[] opts = null;
            if (parts.Length > 1)
            {
                opts = new string[parts.Length - 1];
                Array.Copy(parts, 1, opts, 0, parts.Length - 1);
            }
            new PlayerCommand(msg.username).whisperCommand(cmd, opts);
        }
예제 #4
0
 public void listnerThread()
 {
     while (true)
     {
         MessageBundle msg = _irc.parseMessage();
         switch (msg.type)
         {
         case MessageBundle.Type.WHISPER:
             if (msg.message[0] == '!')
             {
                 handleCommand(msg);
             }
             break;
         }
     }
 }
예제 #5
0
        public MessageBundle parseMessage()
        {
            string message = _inputStream.ReadLine();

            /*
             * ":tmi.twitch.tv 001 luthbot :Welcome, GLHF!"
             * ":tmi.twitch.tv 002 luthbot :Your host is tmi.twitch.tv"
             * ":[email protected] JOIN #luthbot"
             * ":luthbot.tmi.twitch.tv 353 luthbot = #luthbot :luthbot"
             * ":luthbot.tmi.twitch.tv 366 luthbot #luthbot :End of /NAMES list"
             * ":tmi.twitch.tv CAP * ACK :twitch.tv/membership"
             * ":luth_ac!luth_ac@luth_ac.tmi.twitch.tv JOIN #luthbot"
             * ":jtv MODE #luthbot +o luthbot"
             * "PING :tmi.twitch.tv"
             * @color=;display-name=Luth_AC;emotes=;mod=1;room-id=115341176;subscriber=0;turbo=0;user-id=94328712;user-type=mod :luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot :testing
             * @color=;display-name=Luth_AC;emotes=;mod=1;room-id=115341176;subscriber=0;turbo=0;user-id=94328712;user-type=mod :luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot :☺ACTION action☺
             * @color=;display-name=Luth_AC;emotes=51838:0-6;mod=1;room-id=115341176;subscriber=0;turbo=0;user-id=94328712;user-type=mod :luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot :ArgieB8
             * :luth_ac!luth_ac@luth_ac.tmi.twitch.tv WHISPER luthbot :testing whisper
             */

            MessageBundle msg = new MessageBundle();

            msg.message = message;

            try {
                // JOIN
                if (message.Contains(" JOIN #"))
                {
                    msg.type = MessageBundle.Type.JOIN;

                    string[] parts = message.Split(' ');

                    /*
                     * ":[email protected]
                     * JOIN
                     * #luthbot"
                     */
                    msg.message = parts[2];
                }
                // TEXT
                else if (message.Contains(" PRIVMSG #"))
                {
                    //TODO: filter ACTION
                    msg.type = MessageBundle.Type.TEXT;

                    string[] parts = message.Split(';');

                    /*
                     * @color=
                     * display-name=Luth_AC
                     * emotes=
                     * mod=1
                     * room-id=115341176
                     * subscriber=0
                     * turbo=0
                     * user-id=94328712
                     * user-type=mod :luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot :testing
                     */
                    for (int i = 0; i < parts.Length; i++)
                    {
                        string[] kv = parts[i].Split('=');
                        switch (kv[0])
                        {
                        case "mod":
                            int val;
                            if (Int32.TryParse(kv[1], out val))
                            {
                                msg.isMod = val != 0;
                            }
                            break;

                        case "display-name":
                            msg.display = kv[1];
                            break;
                        }
                    }

                    parts = message.Split(':');

                    /*
                     * @color=;display-name=Luth_AC;emotes=;mod=1;room-id=115341176;subscriber=0;turbo=0;user-id=94328712;user-type=mod
                     * luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot
                     * testing
                     */
                    msg.message = parts[2];

                    parts = parts[1].Split('!');

                    /*
                     * luth_ac
                     * luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot
                     */
                    msg.username = parts[0];
                }
                // WHISPER
                else if (message.Contains(" WHISPER " + _username + " "))
                {
                    msg.type = MessageBundle.Type.WHISPER;

                    string[] parts = message.Split(':');

                    /*
                     * <blank>
                     * luth_ac!luth_ac@luth_ac.tmi.twitch.tv WHISPER luthbot
                     * testing whisper
                     */
                    msg.message = parts[2];

                    parts        = parts[1].Split('!');
                    msg.username = parts[0];
                }
                // UNKNOWN
                else
                {
                    msg.message = message;
                }
            } catch (Exception ex) {
                Console.WriteLine("EXCEPTION: " + ex.ToString());
                msg         = new MessageBundle();
                msg.type    = MessageBundle.Type.EXCEPTION;
                msg.message = message;
            }

            return(msg);
        }
예제 #6
0
파일: IrcClient.cs 프로젝트: Luth/TwitchBot
        public MessageBundle parseMessage()
        {
            string message = _inputStream.ReadLine();
            /*
             * ":tmi.twitch.tv 001 luthbot :Welcome, GLHF!"
             * ":tmi.twitch.tv 002 luthbot :Your host is tmi.twitch.tv"
             * ":[email protected] JOIN #luthbot"
             * ":luthbot.tmi.twitch.tv 353 luthbot = #luthbot :luthbot"
             * ":luthbot.tmi.twitch.tv 366 luthbot #luthbot :End of /NAMES list"
             * ":tmi.twitch.tv CAP * ACK :twitch.tv/membership"
             * ":luth_ac!luth_ac@luth_ac.tmi.twitch.tv JOIN #luthbot"
             * ":jtv MODE #luthbot +o luthbot"
             * "PING :tmi.twitch.tv"
             * @color=;display-name=Luth_AC;emotes=;mod=1;room-id=115341176;subscriber=0;turbo=0;user-id=94328712;user-type=mod :luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot :testing
             * @color=;display-name=Luth_AC;emotes=;mod=1;room-id=115341176;subscriber=0;turbo=0;user-id=94328712;user-type=mod :luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot :☺ACTION action☺
             * @color=;display-name=Luth_AC;emotes=51838:0-6;mod=1;room-id=115341176;subscriber=0;turbo=0;user-id=94328712;user-type=mod :luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot :ArgieB8
             * :luth_ac!luth_ac@luth_ac.tmi.twitch.tv WHISPER luthbot :testing whisper
            */

            MessageBundle msg = new MessageBundle();
            msg.message = message;

            try {
                // JOIN
                if ( message.Contains( " JOIN #" ) ) {
                    msg.type = MessageBundle.Type.JOIN;

                    string[] parts = message.Split( ' ' );
                    /*
                     * ":[email protected]
                     * JOIN
                     * #luthbot"
                     */
                    msg.message = parts[2];
                }
                // TEXT
                else if ( message.Contains( " PRIVMSG #" ) ) {
                    //TODO: filter ACTION
                    msg.type = MessageBundle.Type.TEXT;

                    string[] parts = message.Split( ';' );
                    /*
                     * @color=
                     * display-name=Luth_AC
                     * emotes=
                     * mod=1
                     * room-id=115341176
                     * subscriber=0
                     * turbo=0
                     * user-id=94328712
                     * user-type=mod :luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot :testing
                     */
                    for ( int i = 0; i < parts.Length; i++ ) {
                        string[] kv = parts[i].Split( '=' );
                        switch ( kv[0] ) {
                            case "mod":
                                int val;
                                if ( Int32.TryParse( kv[1], out val ) )
                                    msg.isMod = val != 0;
                                break;

                            case "display-name":
                                msg.display = kv[1];
                                break;
                        }
                    }

                    parts = message.Split( ':' );
                    /*
                     * @color=;display-name=Luth_AC;emotes=;mod=1;room-id=115341176;subscriber=0;turbo=0;user-id=94328712;user-type=mod
                     * luth_ac!luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot
                     * testing
                     */
                    msg.message = parts[2];

                    parts = parts[1].Split( '!' );
                    /*
                     * luth_ac
                     * luth_ac@luth_ac.tmi.twitch.tv PRIVMSG #luthbot
                     */
                    msg.username = parts[0];
                }
                // WHISPER
                else if ( message.Contains( " WHISPER " + _username + " " ) ) {
                    msg.type = MessageBundle.Type.WHISPER;

                    string[] parts = message.Split( ':' );
                    /*
                     * <blank>
                     * luth_ac!luth_ac@luth_ac.tmi.twitch.tv WHISPER luthbot
                     * testing whisper
                     */
                    msg.message = parts[2];

                    parts = parts[1].Split( '!' );
                    msg.username = parts[0];
                }
                // UNKNOWN
                else {
                    msg.message = message;
                }
            } catch ( Exception ex ) {
                Console.WriteLine( "EXCEPTION: " + ex.ToString() );
                msg = new MessageBundle();
                msg.type = MessageBundle.Type.EXCEPTION;
                msg.message = message;
            }

            return msg;
        }