示例#1
0
        void ReadChat()
        {
            if (_twitchClient.Available > 0)
            {
                string msg = _twitchReader.ReadLine();
                print(msg);

#if UNITY_EDITOR
                LogWriter.Instance.Write(msg, true);
#endif

                if (msg.Contains("PING"))
                {
                    _twitchWriter.WriteLine("PONG");
                    _twitchWriter.Flush();
                    return;
                }

                if (msg.Contains("PRIVMSG"))
                {
                    var splitPoint = msg.IndexOf("!", 1);
                    print(splitPoint);
                    var author = msg.Substring(0, splitPoint);
                    print(author);
                    author = author.Substring(1);
                    print(author);

                    // users msg
                    splitPoint = msg.IndexOf(":", 1);
                    print(splitPoint);
                    msg = msg.Substring(splitPoint + 1);

                    print(msg);
                    if (msg.StartsWith(TwitchCommandData.Prefix))
                    {
                        // get the first word
                        splitPoint = msg.IndexOf(" ", 1);
                        string             command     = msg.Substring(1, splitPoint);
                        string             chat        = msg.Substring(splitPoint + 1);
                        DocsaTwitchCommand commandEnum = StringValue.GetEnumValue <DocsaTwitchCommand>(command);
                        DocsaSakkiManager.instance.ExecuteCommand(
                            new TwitchCommandData {
                            Author  = author,
                            Command = commandEnum,
                            Time    = System.DateTime.Now,
                            Chat    = chat,
                        });
                    }
                }
            }
        }