public void Deserialize_TestSingleMessage_msg8()
        {
            var parser   = new IRCParser();
            var messages = parser.Deserialize(msg8);

            Assert.AreEqual(2, messages.Length);

            // message 0
            Assert.IsNotNull(messages[0], "IRC msg is null.");
            Assert.IsNull(messages[0].Tags, "Tags is not null.");
            Assert.AreEqual("[email protected]", messages[0].Prefix);
            Assert.AreEqual("JOIN", messages[0].Command, "Command is not equal msg2.");
            Assert.AreEqual(1, messages[0].Middle.Length);
            Assert.AreEqual("#qwerty", messages[0].Middle[0]);
            Assert.IsNull(messages[0].Trailing, "Trailing is not null.");

            // message 1
            Assert.IsNotNull(messages[1], "IRC msg is null.");
            Assert.IsNull(messages[1].Tags, "Tags is not null.");
            Assert.AreEqual("[email protected]", messages[1].Prefix);
            Assert.AreEqual("FOO", messages[1].Command, "Command is not equal msg2.");
            Assert.AreEqual(1, messages[1].Middle.Length);
            Assert.AreEqual("#test", messages[1].Middle[0]);
            Assert.IsNull(messages[1].Trailing, "Trailing is not null.");
        }
        public void Serialize_Test_msg7()
        {
            var parser  = new IRCParser();
            var msg     = new IRCMessage("JOIN", null, "[email protected]", new[] { "#qwerty" }, null);
            var message = parser.Serialize(msg);

            Assert.AreEqual(msg7, message);
        }
        public void Serialize_Test_msg5()
        {
            var parser = new IRCParser();
            var msg    = new IRCMessage("FOO", null, null, null, "This is a test");

            var message = parser.Serialize(msg);

            Assert.AreEqual(msg5, message);
        }
        public void Serialize_Test_msg4()
        {
            var parser = new IRCParser();
            var msg    = new IRCMessage("FOO", null, null, new[] { "qwerty" }, null);

            var message = parser.Serialize(msg);

            Assert.AreEqual(msg4, message);
        }
        public void Serialize_Test_msg2()
        {
            var parser = new IRCParser();
            var msg    = new IRCMessage("FOO", null, "[email protected]", null, null);

            var message = parser.Serialize(msg);

            Assert.AreEqual(msg2, message);
        }
        public void Serialize_Test_msg6()
        {
            var parser = new IRCParser();
            var msg    = new IRCMessage("366", null, null, new[] { "test1", "test2" }, "This is a test");

            var message = parser.Serialize(msg);

            Assert.AreEqual(msg6, message);
        }
        public void Serialize_Test_msg0()
        {
            var parser = new IRCParser();
            var msg    = new IRCMessage("FOO", new Dictionary <string, string>()
            {
                { "test", "super" }, { "single", "0" }
            }, "[email protected]", null, "This is a test");

            var message = parser.Serialize(msg);

            Assert.AreEqual(msg0, message);
        }
        public void Deserialize_TestSingleMessage_msg5()
        {
            var parser  = new IRCParser();
            var message = parser.Deserialize(msg5)[0];

            Assert.IsNotNull(message, "IRC msg is null.");
            Assert.IsNull(message.Tags, "Tags is not null.");
            Assert.IsNull(message.Prefix, $"Prefix is not null. Prefix = '{message.Prefix}'");
            Assert.AreEqual("FOO", message.Command, "Command is not equal msg5.");
            Assert.IsNull(message.Middle, "Middle is not null");
            Assert.AreEqual("This is a test", message.Trailing);
        }
        public void Deserialize_TestSingleMessage_msg2()
        {
            var parser  = new IRCParser();
            var message = parser.Deserialize(msg2)[0];

            Assert.IsNotNull(message, "IRC msg is null.");
            Assert.IsNull(message.Tags, "Tags is not null.");
            Assert.AreEqual("[email protected]", message.Prefix);
            Assert.AreEqual("FOO", message.Command, "Command is not equal msg2.");
            Assert.IsNull(message.Middle, "Middle is not null");
            Assert.IsNull(message.Trailing, "Trailing is not null.");
        }
        public void Deserialize_TestSingleMessage_msg7()
        {
            var parser  = new IRCParser();
            var message = parser.Deserialize(msg7)[0];

            Assert.IsNotNull(message, "IRC msg is null.");
            Assert.IsNull(message.Tags, "Tags is not null.");
            Assert.AreEqual("[email protected]", message.Prefix);
            Assert.AreEqual("JOIN", message.Command, "Command is not equal msg2.");
            Assert.AreEqual(1, message.Middle.Length);
            Assert.AreEqual("#qwerty", message.Middle[0]);
            Assert.IsNull(message.Trailing, "Trailing is not null.");
        }
        public void Deserialize_TestSingleMessage_msg4()
        {
            var parser  = new IRCParser();
            var message = parser.Deserialize(msg4)[0];

            Assert.IsNotNull(message, "IRC msg is null.");
            Assert.IsNull(message.Tags, "Tags is not null.");
            Assert.IsNull(message.Prefix, $"Prefix is not null. Prefix = '{message.Prefix}'");
            Assert.AreEqual("FOO", message.Command, "Command is not equal msg4.");
            Assert.AreEqual(1, message.Middle.Length);
            Assert.AreEqual("qwerty", message.Middle[0]);
            Assert.IsNull(message.Trailing, "Trailing is not null.");
        }
        public void Deserialize_TestSingleMessage_msg3()
        {
            var parser  = new IRCParser();
            var message = parser.Deserialize(msg3)[0];

            Assert.IsNotNull(message, "IRC msg is null.");
            Assert.AreEqual("super", message.Tags["test"]);
            Assert.AreEqual("0", message.Tags["single"]);
            Assert.IsNull(message.Prefix, $"Prefix is not null. Prefix = '{message.Prefix}'");
            Assert.AreEqual("FOO", message.Command, "Command is not equal msg3.");
            Assert.IsNull(message.Middle, "Middle is not null");
            Assert.IsNull(message.Trailing, "Trailing is not null.");
        }
        public void Deserialize_TestSingleMessage_msg0()
        {
            var parser  = new IRCParser();
            var message = parser.Deserialize(msg0)[0];

            Assert.IsNotNull(message);
            Assert.AreEqual("super", message.Tags["test"]);
            Assert.AreEqual("0", message.Tags["single"]);
            Assert.AreEqual("[email protected]", message.Prefix);
            Assert.AreEqual("FOO", message.Command, "Command is not equal msg0.");
            Assert.IsNull(message.Middle, "Middle is not null");
            Assert.AreEqual("This is a test", message.Trailing);
        }
Beispiel #14
0
        public UserState(string ircRawMessage)
        {
            // RawMessage IRC string
            RawMessage = ircRawMessage;
            // Channel notice was sent in
            int startIndex = ircRawMessage.IndexOf('#') + 1;

            Channel = ircRawMessage.Substring(startIndex);
            // Badges
            Badges = new BadgeCollection(IRCParser.GetTwitchTagsValue(ircRawMessage, "@badges"));
            // Color
            ColorHex = IRCParser.GetTwitchTagsValue(ircRawMessage, "color");
            // Display Name
            DisplayName = IRCParser.GetTwitchTagsValue(ircRawMessage, "display-name").Replace(" ", "");
            // Mod Status
            Mod = IRCParser.GetTwitchTagsValue(ircRawMessage, "mod") == "1";
        }
        public void Serialize_Test_msg8()
        {
            var parser   = new IRCParser();
            var messages = new IRCMessage[]
            {
                new IRCMessage("JOIN", null, "[email protected]", new[] { "#qwerty" }, null),
                new IRCMessage("FOO", null, "[email protected]", new[] { "#test" }, null)
            };

            var fullMessage = string.Empty;

            foreach (var message in messages)
            {
                fullMessage += parser.Serialize(message);
            }

            Assert.AreEqual(msg8, fullMessage);
        }
Beispiel #16
0
        private void ParseResponse(string ircRawMessage)
        {
            //Console.WriteLine(ircRawMessage);

            foreach (string channelName in m_channelsJoined)
            {
                IRCParser.TwitchChannelMessageType channelMessageType = IRCParser.GetChannelMessageType(ircRawMessage, channelName);

                if (channelMessageType != IRCParser.TwitchChannelMessageType.None)
                {
                    HandleChannelMessage(ircRawMessage, channelName, channelMessageType);
                    return;
                }
            }

            IRCParser.TwitchMessageType twitchMessageType = IRCParser.GetNonChannelMessageType(ircRawMessage, Credentials.TwitchUsername);
            HandleNonChannelMessage(ircRawMessage, twitchMessageType);
        }
Beispiel #17
0
        public UserNotice(string ircRawMessage)
        {
            // RawMessage IRC string
            RawMessage = ircRawMessage;

            // Channel notice was sent in
            int startIndex = ircRawMessage.IndexOf('#', ircRawMessage.IndexOf("USERNOTICE")) + 1;
            int length     = ircRawMessage.IndexOf(':', startIndex);

            if (length == -1)
            {
                length = ircRawMessage.Length;
            }
            Channel = ircRawMessage.Substring(startIndex, length - startIndex);

            // Badges
            Badges = new BadgeCollection(IRCParser.GetTwitchTagsValue(ircRawMessage, "@badges"));
            // Color
            ColorHex = IRCParser.GetTwitchTagsValue(ircRawMessage, "color");
            // Display Name
            DisplayName = IRCParser.GetTwitchTagsValue(ircRawMessage, "display-name").Replace(" ", "");
            // Emotes Used
            Emotes = new EmoteCollection(IRCParser.GetTwitchTagsValue(ircRawMessage, "emotes"));
            // Message
            string[] messageSplit = ircRawMessage.Split(new string[] { $"#{Channel} :" }, System.StringSplitOptions.None);
            Message = messageSplit[0].Replace($"{messageSplit[0]}#{Channel} :", "");
            // Mod Status
            Mod = IRCParser.GetTwitchTagsValue(ircRawMessage, "mod") == "1";

            // Message ID
            string messageIdRaw = IRCParser.GetTwitchTagsValue(ircRawMessage, "msg-id");

            switch (messageIdRaw)
            {
            case "sub":
            {
                MessageID = SubscriptionType.Sub;
                break;
            }

            case "resub":
            {
                MessageID = SubscriptionType.Resub;
                break;
            }

            case "subgift":
            {
                MessageID = SubscriptionType.Gift;
                break;
            }

            case "charity":
            {
                MessageID = SubscriptionType.Charity;
                break;
            }
            }
            // Resub Consecutive Months
            if (int.TryParse(IRCParser.GetTwitchTagsValue(ircRawMessage, "msg-param-months"), out int resubCount))
            {
                ResubConsecutiveMonths = resubCount;
            }

            // Sub Plan
            string subPlanRaw = IRCParser.GetTwitchTagsValue(ircRawMessage, "msg-param-sub-plan");

            switch (subPlanRaw.ToLower())
            {
            case "prime":
            {
                SubPlan = SubscriptionPlan.Prime;
                break;
            }

            case "1000":
            {
                // Tier 1
                SubPlan = SubscriptionPlan.Tier1;
                break;
            }

            case "2000":
            {
                // Tier 2
                SubPlan = SubscriptionPlan.Tier2;
                break;
            }

            case "3000":
            {
                // Tier 3
                SubPlan = SubscriptionPlan.Tier3;
                break;
            }
            }
            // Sub Gift Recipient Name
            GiftedSubscriptionRecipientName = IRCParser.GetTwitchTagsValue(ircRawMessage, "msg-param-recipient-display-name");
            // Gifted Subscription Count
            if (int.TryParse(IRCParser.GetTwitchTagsValue(ircRawMessage, "msg-param-sender-count"), out int giftedSubCount))
            {
                GiftedSubscriptionsCount = giftedSubCount + 1;
            }
            // Sub Plan Name
            SubscriptionPlanName = IRCParser.GetTwitchTagsValue(ircRawMessage, "msg-param-sub-plan-name").Replace("\\s", " ");
            // Channel ID (Room ID)
            ChannelID = int.Parse(IRCParser.GetTwitchTagsValue(ircRawMessage, "room-id"));
            // Subscriber Status
            Subscriber = IRCParser.GetTwitchTagsValue(ircRawMessage, "subscriber") == "1";
            // System Message
            SystemMessage = IRCParser.GetTwitchTagsValue(ircRawMessage, "system-msg");
            // Twitch Turbo/Prime Status
            Turbo = IRCParser.GetTwitchTagsValue(ircRawMessage, "turbo") == "1";
            // User ID
            UserID = int.Parse(IRCParser.GetTwitchTagsValue(ircRawMessage, "user-id"));
            // User Type
            string userTypeRaw = IRCParser.GetTwitchTagsValue(ircRawMessage, "user-type");

            switch (userTypeRaw)
            {
            case "mod":
            {
                UsersType = UserType.Moderator;
                break;
            }

            case "global_mod":
            {
                UsersType = UserType.GlobalModerator;
                break;
            }

            case "admin":
            {
                UsersType = UserType.Admin;
                break;
            }

            case "staff":
            {
                UsersType = UserType.Staff;
                break;
            }

            default:
            {
                UsersType = UserType.Viewer;
                break;
            }
            }

            Username = DisplayName;
        }
Beispiel #18
0
        public ChatMessage(string ircRawMessage)
        {
            // RawMessage IRC string
            RawMessage = ircRawMessage;
            // Channel notice was sent in
            Channel = ircRawMessage.Substring(ircRawMessage.IndexOf('#', ircRawMessage.IndexOf("PRIVMSG")) + 1, ircRawMessage.IndexOf(' ', ircRawMessage.IndexOf('#', ircRawMessage.IndexOf("PRIVMSG")) + 1) - (ircRawMessage.IndexOf('#', ircRawMessage.IndexOf("PRIVMSG")) + 1));
            // Bits (Total)
            int numberOfBits = 0;

            Int32.TryParse(IRCParser.GetTwitchTagsValue(ircRawMessage, "bits"), out numberOfBits);
            Bits = numberOfBits;
            // Badges
            Badges = new BadgeCollection(IRCParser.GetTwitchTagsValue(ircRawMessage, "@badges"));
            // Color
            ColorHex = IRCParser.GetTwitchTagsValue(ircRawMessage, "color");
            // Display Name
            DisplayName = IRCParser.GetTwitchTagsValue(ircRawMessage, "display-name").Replace(" ", "");
            // Emotes Used
            Emotes = new EmoteCollection(IRCParser.GetTwitchTagsValue(ircRawMessage, "emotes"));
            // Message
            string[] messageSplit = ircRawMessage.Split(new string[] { $"#{Channel} :" }, System.StringSplitOptions.None);
            Message = messageSplit[1];
            // Mod Status
            Mod = IRCParser.GetTwitchTagsValue(ircRawMessage, "mod") == "1";
            // Channel ID (Room ID)
            ChannelId = int.Parse(IRCParser.GetTwitchTagsValue(ircRawMessage, "room-id"));
            // Subscriber Status
            Subscriber = IRCParser.GetTwitchTagsValue(ircRawMessage, "subscriber") == "1";
            // Username
            string[] tagSplit = ircRawMessage.Split(' ');
            Username = tagSplit[1].Substring(tagSplit[1].IndexOf('!') + 1, (tagSplit[1].IndexOf('@')) - (tagSplit[1].IndexOf('!') + 1));
            // Twitch Turbo/Prime Status
            Turbo = IRCParser.GetTwitchTagsValue(ircRawMessage, "turbo") == "1";
            // User ID
            UserId = int.Parse(IRCParser.GetTwitchTagsValue(ircRawMessage, "user-id"));
            // User Type
            string userTypeRaw = IRCParser.GetTwitchTagsValue(ircRawMessage, "user-type");

            switch (userTypeRaw)
            {
            case "mod":
            {
                UsersType = UserType.Moderator;
                break;
            }

            case "global_mod":
            {
                UsersType = UserType.GlobalModerator;
                break;
            }

            case "admin":
            {
                UsersType = UserType.Admin;
                break;
            }

            case "staff":
            {
                UsersType = UserType.Staff;
                break;
            }

            default:
            {
                UsersType = UserType.Viewer;
                break;
            }
            }
        }
Beispiel #19
0
        public WhisperMessage(string ircRawMessage)
        {
            // RawMessage IRC string
            RawMessage = ircRawMessage;

            // Badges
            Badges = new BadgeCollection(IRCParser.GetTwitchTagsValue(ircRawMessage, "@badges"));
            // Color
            ColorHex = IRCParser.GetTwitchTagsValue(ircRawMessage, "color");
            // Display Name
            DisplayName = IRCParser.GetTwitchTagsValue(ircRawMessage, "display-name").Replace(" ", "");
            // Emotes Used
            Emotes = new EmoteCollection(IRCParser.GetTwitchTagsValue(ircRawMessage, "emotes"));
            // Message ID
            ID = int.Parse(IRCParser.GetTwitchTagsValue(ircRawMessage, "id"));
            // Twitch Turbo/Prime Status
            Turbo = IRCParser.GetTwitchTagsValue(ircRawMessage, "turbo") == "1";
            // User ID
            UserID = int.Parse(IRCParser.GetTwitchTagsValue(ircRawMessage, "user-id"));
            // User Type
            string userTypeRaw = IRCParser.GetTwitchTagsValue(ircRawMessage, "user-type");

            switch (userTypeRaw)
            {
            case "mod":
            {
                UsersType = UserType.Moderator;
                break;
            }

            case "global_mod":
            {
                UsersType = UserType.GlobalModerator;
                break;
            }

            case "admin":
            {
                UsersType = UserType.Admin;
                break;
            }

            case "staff":
            {
                UsersType = UserType.Staff;
                break;
            }

            default:
            {
                UsersType = UserType.Viewer;
                break;
            }
            }

            string[] userTagSplit = ircRawMessage.Split('!');
            string[] tmiSplit     = userTagSplit[1].Split('@');
            Username = tmiSplit[0];

            Message = ircRawMessage.Replace($"{userTagSplit[0]}!{Username}@{Username}.tmi.twitch.tv WHISPER {TwitchClient.GetInstance().Credentials.TwitchUsername.ToLower()} :", "");
        }