Beispiel #1
0
        /// <summary>
        /// IRC event: a raw message was received by us.
        /// This is where custom parsing needs to take place.
        /// </summary>
        private void Client_RawMessageReceived(object sender, IrcRawMessageEventArgs e)
        {
            TmiLog.Debug("<<<", e.RawContent);

            if (e.RawContent.StartsWith('@'))
            {
                // Looks like a TMI message with state info that we can parse & process
                var tmiMsg = TmiMessageParser.Parse(e.RawContent);

                if (tmiMsg is TmiChatMessage)
                {
                    if (OnChatMessage != null)
                    {
                        OnChatMessage.Invoke(this, new TmiChatMessageEventArgs((TmiChatMessage)tmiMsg));
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when a raw text was received. Only override if you need control over the message parsing
        /// and forwarding process. This should normally not be necessary.
        /// </summary>
        /// <param name="raw">the raw text</param>
        protected virtual void OnRawReceived(string raw)
        {
            RawReceived?.Invoke(this, raw);

            TmiMessage msg     = null;
            var        success = false;

            try
            {
                msg     = Parser.Parse(raw);
                success = true;
            }
            catch (Exception e)
            {
                if (Invalid == null)
                {
                    throw;
                }
                OnInvalid(new InvalidMessageEventArgs(raw, e));
            }
            if (!success)
            {
                return;
            }

            Action <TmiMessage> handler;

            if (commandRegistry.TryGetValue(msg.Command, out handler))
            {
                handler(msg);
            }
            else
            {
                OnUnknown(msg);
            }
        }