示例#1
0
 public static void ROOMSTATE(TwitchMessage twitchMsg, MatchCollection tags)
 {
     foreach (Match t in tags)
     {
         ParseRoomstateTag(t, twitchMsg.channelName);
     }
 }
示例#2
0
        public static void USERSTATE(TwitchMessage twitchMsg, MatchCollection tags)
        {
            foreach (Match t in tags)
            {
                ParseMessageTag(t, ref twitchMsg);
            }

            TwitchWebSocketClient.OurTwitchUser = twitchMsg.user;
        }
示例#3
0
        public static void JOIN(TwitchMessage twitchMsg, MatchCollection tags)
        {
            if (!TwitchWebSocketClient.ChannelInfo.ContainsKey(twitchMsg.channelName))
            {
                TwitchWebSocketClient.ChannelInfo.Add(twitchMsg.channelName, new TwitchRoom(twitchMsg.channelName));
            }

            Plugin.Log($"Success joining channel #{twitchMsg.channelName}");
        }
示例#4
0
        public static void CLEARMSG(TwitchMessage twitchMsg, MatchCollection tags)
        {
            string msgId = String.Empty;

            foreach (Match t in tags)
            {
                if (t.Groups["Tag"].Value == "target-msg-id")
                {
                    msgId = t.Groups["target-msg-id"].Value;
                    break;
                }
            }
            ChatHandler.Instance.PurgeChatMessageById(msgId);
        }
示例#5
0
        public static void CLEARCHAT(TwitchMessage twitchMsg, MatchCollection tags)
        {
            string userId = String.Empty;

            foreach (Match t in tags)
            {
                if (t.Groups["Tag"].Value == "target-user-id")
                {
                    userId = t.Groups["target-user-id"].Value;
                    break;
                }
            }
            ChatHandler.Instance.PurgeMessagesFromUser(userId);
        }
示例#6
0
        public static void PRIVMSG(TwitchMessage twitchMsg, MatchCollection tags)
        {
            twitchMsg.user.displayName = twitchMsg.hostString.Split('!')[0];
            foreach (Match t in tags)
            {
                ParseMessageTag(t, ref twitchMsg);
            }

            MessageParser.Parse(new ChatMessage(Utilities.StripHTML(twitchMsg.message), twitchMsg));
            if (Config.Instance.SongRequestBot)
            {
                RequestBot.Parse(twitchMsg.user, twitchMsg.message);
            }
        }
示例#7
0
        private static void Ws_OnMessage(object sender, WebSocketSharp.MessageEventArgs ev)
        {
            if (!ev.IsText)
            {
                return;
            }

            string rawMessage = ev.Data.TrimEnd();

            if (rawMessage.StartsWith("PING"))
            {
                Plugin.Log("Ping... Pong.");
                _ws.Send("PONG :tmi.twitch.tv");
            }

            var messageType = _twitchMessageRegex.Match(rawMessage);

            if (messageType.Length == 0)
            {
                Plugin.Log($"Unhandled message: {rawMessage}");
                return;
            }

            string channelName = messageType.Groups["ChannelName"].Value;

            if (channelName != Config.Instance.TwitchChannelName)
            {
                return;
            }

            // Instantiate our twitch message
            TwitchMessage twitchMsg = new TwitchMessage();

            twitchMsg.rawMessage  = rawMessage;
            twitchMsg.message     = _messageRegex.Match(twitchMsg.rawMessage).Groups["Message"].Value;
            twitchMsg.hostString  = messageType.Groups["HostName"].Value;
            twitchMsg.messageType = messageType.Groups["MessageType"].Value;
            twitchMsg.channelName = channelName;

            // Find all the message tags
            var tags = _tagRegex.Matches(rawMessage);

            // Call the appropriate handler for this messageType
            if (_messageHandlers.ContainsKey(twitchMsg.messageType))
            {
                _messageHandlers[twitchMsg.messageType]?.Invoke(twitchMsg, tags);
            }
        }
示例#8
0
        public static void USERNOTICE(TwitchMessage twitchMsg, MatchCollection tags)
        {
            foreach (Match t in tags)
            {
                ParseMessageTag(t, ref twitchMsg);
            }

            string msgId = String.Empty, systemMsg = String.Empty;

            foreach (Match t in tags)
            {
                switch (t.Groups["Tag"].Value)
                {
                case "msg-id":
                    msgId = t.Groups["Value"].Value;
                    break;

                case "system-msg":
                    systemMsg = t.Groups["Value"].Value.Replace("\\s", " ");
                    break;

                default:
                    break;
                }
            }
            switch (msgId)
            {
            case "sub":
            case "resub":
            case "subgift":
            case "anonsubgift":
                MessageParser.Parse(new ChatMessage($"{systemMsg.Substring(systemMsg.IndexOf(" ") + 1).Split(new char[] { '\n' }, 2)[0]}", twitchMsg));
                if (twitchMsg.message != String.Empty)
                {
                    MessageParser.Parse(new ChatMessage(twitchMsg.message, twitchMsg));
                }
                break;

            case "raid":
                break;

            case "ritual":
                break;
            }
        }
示例#9
0
        private static void ParseMessageTag(Match t, ref TwitchMessage twitchMsg)
        {
            switch (t.Groups["Tag"].Value)
            {
            case "id":
                twitchMsg.id = t.Groups["Value"].Value;
                break;

            case "emotes":
                twitchMsg.emotes = t.Groups["Value"].Value;
                break;

            case "badges":
                twitchMsg.user.badges        = t.Groups["Value"].Value;
                twitchMsg.user.isBroadcaster = twitchMsg.user.badges.Contains("broadcaster/");
                twitchMsg.user.isSub         = twitchMsg.user.badges.Contains("subscriber/");
                twitchMsg.user.isTurbo       = twitchMsg.user.badges.Contains("turbo/");
                twitchMsg.user.isMod         = twitchMsg.user.badges.Contains("moderator/");
                break;

            case "color":
                twitchMsg.user.color = t.Groups["Value"].Value;
                break;

            case "display-name":
                twitchMsg.user.displayName = t.Groups["Value"].Value;
                break;

            case "user-id":
                twitchMsg.user.id = t.Groups["Value"].Value;
                break;

            case "bits":
                twitchMsg.bits = int.Parse(t.Groups["Value"].Value);
                break;
                //case "flags":
                //    twitchMsg.user.flags = t.Groups["Value"].Value;
                //    break;
                //case "emotes-only":
                //    twitchMsg.emotesOnly = t.Groups["Value"].Value == "1";
                //    break;
            }
        }
示例#10
0
 public static void MODE(TwitchMessage twitchMsg, MatchCollection tags)
 {
     //Plugin.Log("MODE message received!");
 }
示例#11
0
 public ChatMessage(string msg, TwitchMessage messageInfo)
 {
     this.msg           = msg;
     this.twitchMessage = messageInfo;
 }