diff --git a/ChatSharp/IrcMessage.cs b/ChatSharp/IrcMessage.cs
index d23c1a5..f273af1 100644
--- a/ChatSharp/IrcMessage.cs
+++ b/ChatSharp/IrcMessage.cs
@@ -25,6 +25,10 @@ namespace ChatSharp
/// Additional parameters supplied with the message.
///
public string[] Parameters { get; private set; }
+ ///
+ /// The message tags.
+ ///
+ public KeyValuePair[] Tags { get; private set; }
///
/// Initializes and decodes an IRC message, given the raw message from the server.
@@ -33,6 +37,31 @@ namespace ChatSharp
{
RawMessage = rawMessage;
+ if (rawMessage.StartsWith("@"))
+ {
+ var rawTags = rawMessage.Substring(1, rawMessage.IndexOf(' ') - 1);
+ rawMessage = rawMessage.Substring(rawMessage.IndexOf(' ') + 1);
+
+ // Parse tags as key value pairs
+ var tags = new List>();
+ foreach (string rawTag in rawTags.Split(';'))
+ {
+ var replacedTag = rawTag.Replace(@"\:", ";");
+ KeyValuePair tag = new KeyValuePair(replacedTag, string.Empty);
+
+ if (replacedTag.Contains("="))
+ {
+ string key = replacedTag.Substring(0, replacedTag.IndexOf("="));
+ string value = replacedTag.Substring(replacedTag.IndexOf("=") + 1);
+ tag = new KeyValuePair(key, value);
+ }
+
+ tags.Add(tag);
+ }
+
+ Tags = tags.ToArray();
+ }
+
if (rawMessage.StartsWith(":"))
{
Prefix = rawMessage.Substring(1, rawMessage.IndexOf(' ') - 1);
diff --git a/ChatSharpTests/IrcMessageTests.cs b/ChatSharpTests/IrcMessageTests.cs
index c0be504..8539847 100644
--- a/ChatSharpTests/IrcMessageTests.cs
+++ b/ChatSharpTests/IrcMessageTests.cs
@@ -1,6 +1,7 @@
using System;
using ChatSharp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Collections.Generic;
namespace ChatSharp.Tests
{
@@ -41,5 +42,44 @@ namespace ChatSharp.Tests
string[] compareParams = new string[] { "target", "Lorem ipsum dolor sit amet" };
CollectionAssert.AreEqual(fromMessage.Parameters, compareParams);
}
+
+ [TestMethod]
+ public void NewValidMessage_Tags()
+ {
+ IrcMessage fromMessage = new IrcMessage("@a=123;b=456;c=789 :user!~ident@host PRIVMSG target :Lorem ipsum dolor sit amet");
+ KeyValuePair[] compareTags = new KeyValuePair[]
+ {
+ new KeyValuePair("a", "123"),
+ new KeyValuePair("b", "456"),
+ new KeyValuePair("c", "789")
+ };
+ CollectionAssert.AreEqual(fromMessage.Tags, compareTags);
+ }
+
+ [TestMethod]
+ public void NewValidMessage_Tags02()
+ {
+ IrcMessage fromMessage = new IrcMessage("@aaa=bbb;ccc;example.com/ddd=eee :nick!ident@host.com PRIVMSG me :Hello");
+ KeyValuePair[] compareTags = new KeyValuePair[]
+ {
+ new KeyValuePair("aaa", "bbb"),
+ new KeyValuePair("ccc", ""),
+ new KeyValuePair("example.com/ddd", "eee"),
+ };
+ CollectionAssert.AreEqual(fromMessage.Tags, compareTags);
+ }
+
+ [TestMethod]
+ public void NewValidMessage_TagsWithSemicolon()
+ {
+ IrcMessage fromMessage = new IrcMessage(@"@a=123\:456;b=456\:789;c=789\:123 :user!~ident@host PRIVMSG target :Lorem ipsum dolor sit amet");
+ KeyValuePair[] compareTags = new KeyValuePair[]
+ {
+ new KeyValuePair("a", "123;456"),
+ new KeyValuePair("b", "456;789"),
+ new KeyValuePair("c", "789;123"),
+ };
+ CollectionAssert.AreEqual(fromMessage.Tags, compareTags);
+ }
}
}