Ejemplo n.º 1
0
 private void OnMessageReceivedTask(TwitchConnection obj, TwitchMessage msg)
 {
     foreach (KeyValuePair <string, RegisteredPlugin> kvp in RegisteredPlugins)
     {
         try
         {
             kvp.Value.OnMessageReceived(obj, msg);
         }
         catch (Exception e)
         {
             Console.WriteLine($"An exception occured while trying to call OnMessageReceived for plugin {kvp.Key} (Exception: {e.ToString()})");
         }
     }
 }
Ejemplo n.º 2
0
        public override void ProcessMessage(byte[] msg)
        {
            _logger.Trace("Entered into subclass.");
            string stringMsg = "";

            try
            {
                stringMsg = Utf8NoBom.GetString(msg);
                Task.Run(() => OnRawMessageReceivedTask(stringMsg));
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }

            _logger.Trace(stringMsg);

            if (stringMsg == "PING :tmi.twitch.tv")
            {
                _logger.Trace("Received ping, sending pong.");
                Send("PONG :tmi.twitch.tv");
            }
            string channel = "";

            try
            {
                if (_channelName.IsMatch(stringMsg))
                {
                    channel = _channelName.Match(stringMsg).Groups["Channel"].Value;
                }
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }

            //if (FilterJoinPart(stringMsg, channel)) return;
            if (_roomStateRX.IsMatch(stringMsg))
            {
                _logger.Trace("Roomstate Found.");
                try
                {
                    FilterRoomState(stringMsg, channel);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                Task.Run(() => OnRoomStateChangedTask(this, RoomStates[channel]));
                return;
            }

            _logger.Trace("Parsing message.");
            TwitchMessage message = new TwitchMessage();

            string[] splitMsg = stringMsg.Split(new[] { " :" }, 3, StringSplitOptions.RemoveEmptyEntries);
            if (splitMsg.Length >= 3)
            {
                message.Content = splitMsg[2];
            }
            message.RawMessage = stringMsg;
            splitMsg           = splitMsg[0].Split(';');

            if (RoomStates.ContainsKey(channel))
            {
                foreach (string msgTag in splitMsg)
                {
                    string[] splitTag = msgTag.Split('=');
                    if (splitMsg.Length < 1)
                    {
                        break;
                    }
                    if (splitTag.Length < 2)
                    {
                        continue;
                    }
                    switch (splitTag[0])
                    {
                    case "bits":
                        message.GaveBits  = true;
                        message.BitAmount = int.Parse(splitTag[1]);
                        break;

                    case "display-name":
                        message.Author = FindChatUser(splitTag[1], stringMsg, channel);
                        break;

                    case "emotes":
                        if (_emoteRX.IsMatch(stringMsg))
                        {
                            message.Emotes = ParseEmotes(splitTag[1]);
                        }
                        break;

                    case "id":
                        message.Id = splitTag[1];
                        break;
                    }
                }
                message.Room = RoomStates[channel];
            }

            Task.Run(() => OnMessageReceivedTask(this, message));
        }
Ejemplo n.º 3
0
 public void OnMessageReceived(TwitchConnection obj, TwitchMessage msg)
 {
     _onMessageReceived?.Invoke(obj, msg);
 }
Ejemplo n.º 4
0
        public static void PRIVMSG(RawMessage rawMessage)
        {
            TwitchMessage message = Parsers.ParseTwitchMessage(rawMessage.Message);

            TwitchConnection.OnMessage?.Invoke(TwitchConnection.Instance, message);
        }