コード例 #1
0
        public static IInternalMessage Parse(string raw)
        {
            var match = Regex.Match(raw, "\"t\":\"?(\\d+)");

            if (!match.Success)
            {
                throw new ParseException(raw);
            }
            IInternalMessage internalMessage;
            var type = match.Groups[1].Value;

            switch (type)
            {
            case "1":
                internalMessage = new T1(raw);
                break;

            case "2":
                internalMessage = new T2(raw);
                break;

            case "6":
                internalMessage = new T6(raw);
                break;

            case "8":
                internalMessage = null;
                break;

            default:
                //"MSG\t6ce05f:8Jvx9D6M\t{\"created_at\":1561899486,\"t\":100}"
                //"MSG\t6ce05f:8Jvx9D6M\t{\"telops\":[{\"color\":{\"r\":255,\"b\":255,\"g\":255},\"text\":\"最高です!ありがとう!ファミマ行けー!\",\"type\":\"user\"}],\"telop\":\"最高です!ありがとう!ファミマ行けー!\",\"interval\":6000,\"t\":8,\"api\":\"https://www.showroom-live.com/live/telop?live_id=7135327\"}"
                throw new ParseException(raw);
            }
            return(internalMessage);
        }
コード例 #2
0
        public static IInternalMessage Parse(string raw)
        {
            var arr = raw.Split('\t');

            if (arr.Length == 0)
            {
                throw new ParseException(raw);
            }
            var command = arr[0];
            IInternalMessage internalMessage;

            switch (command)
            {
            case "MSG":
            {
                var match = Regex.Match(raw, "\"t\":\"?(\\d+)");
                if (!match.Success)
                {
                    //MSG	70724a:VGEKqmGT	{"av":1010794,"d":8,"ac":"@LTFismar_","cm":"頑張って...
                    //MSG	70724a:VGEKqmGT	{"av":1018790,"d":0,"ac":"やいず216","cm":"みさきちゃん頑張ろうね!
                    throw new ParseException(raw);
                }
                var type = match.Groups[1].Value;
                switch (type)
                {
                case "1":
                    internalMessage = new T1(raw);
                    break;

                case "2":            //throwGifts
                    internalMessage = new T2(raw);
                    break;

                //case "3"://startVote
                //    internalMessage = null;
                //    break;
                //case "4"://endVote
                //    internalMessage = null;
                //    break;
                case "5":
                    //"MSG\t73d189:UPpINjdV\t{\"created_at\":1567284520,\"c\":0,\"p\":69484,\"t\":5}"
                    internalMessage = null;
                    break;

                case "6":
                    internalMessage = new T6(raw);
                    break;

                case "8":            //setTelop
                    //"MSG\t73d189:UPpINjdV\t{\"telops\":[{\"color\":{\"r\":255,\"b\":255,\"g\":255},\"text\":\"更新あり6:30迄.:*・゜次枠→8時\",\"type\":\"user\"}],\"telop\":\"更新あり6:30迄.:*・゜次枠→8時\",\"interval\":6000,\"t\":8,\"api\":\"https://www.showroom-live.com/live/telop?live_id=7590281\"}"
                    internalMessage = null;
                    break;

                //case "9"://hideTelop
                //    internalMessage = null;
                //    break;
                case "11":            //addGiftLog
                    //"MSG\t73d1db:FspoWUsJ\t{\"n\":100,\"av\":1012144,\"d\":0,\"ac\":\"PHYSALIS RX78GP02A strike back\",\"u\":2755708,\"created_at\":1567285801,\"g\":4,\"t\":11}"
                    internalMessage = null;
                    break;

                case "100":            //fetchAvatar
                    //"MSG\t73d189:UPpINjdV\t{\"created_at\":1567284607,\"t\":100}"
                    internalMessage = null;
                    break;

                case "101":            //endLive
                    //"MSG\t73d1db:FspoWUsJ\t{\"created_at\":1567287018,\"n\":1567288800,\"a\":0,\"t\":101}"
                    internalMessage = null;
                    break;

                case "104":            //startLive
                    //"MSG\tff123f20bfa089e3ea99adad05ce4d66760491380eec06f704be0e69a6cd1faf\t{\"created_at\":1567292533,\"t\":104}"
                    internalMessage = null;
                    break;

                //case "302"://enterOwner
                //    internalMessage = null;
                //    break;
                //case "303"://leaveOwner
                //    internalMessage = null;
                //    break;
                default:
                    //"MSG\t6ce05f:8Jvx9D6M\t{\"created_at\":1561899486,\"t\":100}"
                    //"MSG\t6ce05f:8Jvx9D6M\t{\"telops\":[{\"color\":{\"r\":255,\"b\":255,\"g\":255},\"text\":\"最高です!ありがとう!ファミマ行けー!\",\"type\":\"user\"}],\"telop\":\"最高です!ありがとう!ファミマ行けー!\",\"interval\":6000,\"t\":8,\"api\":\"https://www.showroom-live.com/live/telop?live_id=7135327\"}"
                    throw new ParseException(raw);
                }
            }
            break;

            case "PING":
                internalMessage = new Ping(raw);
                break;

            case "PONG":
                internalMessage = new Pong(raw);
                break;

            case "ACK":
                //"ACK\tshowroom"
                internalMessage = null;
                break;

            default:
                throw new ParseException(raw);
            }
            if (internalMessage == null)
            {
                throw new ParseException(raw);
            }
            return(internalMessage);
        }