public void FilterMessage_ManyCtcp()
        {
            int count   = 10;
            var builder = new StringBuilder();

            for (int n = 0; n < count; n++)
            {
                builder.Append(CtcpDelimiter);
                builder.Append("TEST" + n + " " + "content" + n);
            }
            builder.Append(CtcpDelimiter);

            var message = new IrcMessage(this._user, "PRIVMSG", new string[] { "someone" }, builder.ToString());

            var res = CtcpUtils.FilterMessage(message);

            Assert.AreEqual(0, res.IrcMessages.Count);
            Assert.AreEqual(count, res.CtcpMessages.Count);
            for (int n = 0; n < count; n++)
            {
                Assert.AreEqual(message.Sender, res.CtcpMessages[n].Sender);
                Assert.AreEqual("TEST" + n, res.CtcpMessages[n].Command, true);
                Assert.AreEqual("content" + n, res.CtcpMessages[n].Content);
            }
        }
        public void FilterMessage_OneCtcpMessage()
        {
            var message = new IrcMessage(this._user, "PRIVMSG", new string[] { "someone" }, CtcpDelimiter + "PING abc" + CtcpDelimiter);

            var res = CtcpUtils.FilterMessage(message);

            Assert.AreEqual(0, res.IrcMessages.Count);
            Assert.AreEqual(1, res.CtcpMessages.Count);
            Assert.AreEqual(message.Sender, res.CtcpMessages[0].Sender);
            Assert.AreEqual("PING", res.CtcpMessages[0].Command, true);
            Assert.AreEqual("abc", res.CtcpMessages[0].Content);
        }
        public void FilterMessage_CtcpThenIrc()
        {
            var message = new IrcMessage(this._user, "PRIVMSG", new string[] { "someone" }, CtcpDelimiter + "FINGER" + CtcpDelimiter + "Hi!");

            var res = CtcpUtils.FilterMessage(message);

            Assert.AreEqual(1, res.IrcMessages.Count);
            Assert.AreEqual(message.Sender, res.IrcMessages[0].Sender);
            Assert.AreEqual(message.Command, res.IrcMessages[0].Command, true);
            Assert.AreEqual(message.CommandArguments, res.IrcMessages[0].CommandArguments);
            Assert.AreEqual("Hi!", res.IrcMessages[0].Content);
            Assert.AreEqual(1, res.CtcpMessages.Count);
            Assert.AreEqual(message.Sender, res.CtcpMessages[0].Sender);
            Assert.AreEqual("FINGER", res.CtcpMessages[0].Command, true);
            Assert.AreEqual(string.Empty, res.CtcpMessages[0].Content);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Interprets an <see cref="IrcMessage"/> and returns the <see cref="IrcMessage"/>s that should be interpreted by an <see cref="IrcClient"/>.
        /// </summary>
        internal IEnumerable <IrcMessage> InterpretMessage(IrcMessage message)
        {
            if (!CtcpUtils.IsCtcpMessage(message))
            {
                return(new[] { message });
            }

            var info = CtcpUtils.FilterMessage(message);

            foreach (var ctcpMessage in info.CtcpMessages)
            {
                this.HandleMessage(ctcpMessage);
            }

            return(info.IrcMessages);
        }