Beispiel #1
0
        internal static Task HandleUserstateMessage(IrcClient client, IrcMessage message)
        {
            string        channelName = message.Parameters[0].Substring(1);
            TwitchChannel channel     = (TwitchChannel)client.Channels[channelName];

            if (message.Tags.ContainsKey("badges") && message.Tags["badges"].Length > 0)
            {
                Dictionary <string, int> badges = TwitchUtils.ParseBadges(message.Tags["badges"]);

                if (badges.ContainsKey("subscriber"))
                {
                    channel.IsSubscriber = true;
                }
            }

            if (message.Tags.ContainsKey("mod") && int.TryParse(message.Tags["mod"], out int isModerator))
            {
                channel.IsModerator = isModerator == 1;
            }

            return(Task.CompletedTask);
        }
Beispiel #2
0
        private void Init(Dictionary <string, string> tags)
        {
            if (tags.ContainsKey("badges"))
            {
                if (tags["badges"].Length > 0)
                {
                    Dictionary <string, int> badges = TwitchUtils.ParseBadges(tags["badges"]);

                    if (badges.ContainsKey("admin"))
                    {
                        IsAdmin = true;
                    }

                    if (badges.ContainsKey("bits"))
                    {
                        IsBitsDonator = true;
                    }

                    if (badges.ContainsKey("broadcaster"))
                    {
                        IsBroadcaster = true;
                    }

                    if (badges.ContainsKey("global_mod"))
                    {
                        IsGlobalMod = true;
                    }

                    if (badges.ContainsKey("moderator"))
                    {
                        IsMod = true;
                    }

                    if (badges.ContainsKey("subscriber"))
                    {
                        IsSubscriber = true;
                    }

                    if (badges.ContainsKey("staff"))
                    {
                        IsStaff = true;
                    }

                    if (badges.ContainsKey("turbo"))
                    {
                        IsTurbo = true;
                    }
                }
            }
            else
            {
                Debug.WriteLine("Missing badges tag in twitch irc message");
            }

            if (tags.ContainsKey("badge-info"))
            {
                if (tags["badge-info"].Length > 0)
                {
                    var badgeInfo = TwitchUtils.ParseBadges(tags["badge-info"]);

                    if (badgeInfo.ContainsKey("subscriber"))
                    {
                        MonthsSubscribed = Convert.ToInt32(badgeInfo["subscriber"]);
                    }
                }
            }
            else
            {
                Debug.WriteLine("Missing badge-info tag in twitch irc message");
            }

            if (tags.ContainsKey("display-name"))
            {
                DisplayName = tags["display-name"];
            }
            else
            {
                Debug.WriteLine("Missing display-name tag in twitch irc message");
            }

            if (tags.ContainsKey("user-id"))
            {
                if (int.TryParse(tags["user-id"], out int userID))
                {
                    ID = userID;
                }
                else
                {
                    Debug.WriteLine("user-id is not an integer.");
                }
            }
            else
            {
                Debug.WriteLine("Missing user-id tag in twitch irc message");
            }
        }