예제 #1
0
        /// <summary>
        /// Invokes the message received.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="botUsername">The bot username.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="colorHex">The color hexadecimal.</param>
        /// <param name="color">The color.</param>
        /// <param name="emoteSet">The emote set.</param>
        /// <param name="message">The message.</param>
        /// <param name="userType">Type of the user.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="isSubscriber">if set to <c>true</c> [is subscriber].</param>
        /// <param name="subscribedMonthCount">The subscribed month count.</param>
        /// <param name="roomId">The room identifier.</param>
        /// <param name="isTurbo">if set to <c>true</c> [is turbo].</param>
        /// <param name="isModerator">if set to <c>true</c> [is moderator].</param>
        /// <param name="isMe">if set to <c>true</c> [is me].</param>
        /// <param name="isBroadcaster">if set to <c>true</c> [is broadcaster].</param>
        /// <param name="noisy">The noisy.</param>
        /// <param name="rawIrcMessage">The raw irc message.</param>
        /// <param name="emoteReplacedMessage">The emote replaced message.</param>
        /// <param name="badges">The badges.</param>
        /// <param name="cheerBadge">The cheer badge.</param>
        /// <param name="bits">The bits.</param>
        /// <param name="bitsInDollars">The bits in dollars.</param>
        public static void InvokeMessageReceived(this TwitchClient client, string botUsername, string userId, string userName, string displayName, string colorHex,
                                                 Color color, EmoteSet emoteSet, string message, UserType userType, string channel, string id, bool isSubscriber, int subscribedMonthCount, string roomId, bool isTurbo,
                                                 bool isModerator, bool isMe, bool isBroadcaster, bool isVip, bool isPartner, bool isStaff, Noisy noisy, string rawIrcMessage, string emoteReplacedMessage, List <KeyValuePair <string, string> > badges,
                                                 CheerBadge cheerBadge, int bits, double bitsInDollars)
        {
            OnMessageReceivedArgs model = new OnMessageReceivedArgs()
            {
                ChatMessage = new ChatMessage(botUsername, userId, userName, displayName, colorHex, color, emoteSet, message, userType, channel, id, isSubscriber,
                                              subscribedMonthCount, roomId, isTurbo, isModerator, isMe, isBroadcaster, isVip, isPartner, isStaff, noisy, rawIrcMessage, emoteReplacedMessage, badges, cheerBadge, bits,
                                              bitsInDollars)
            };

            client.RaiseEvent("OnMessageReceived", model);
        }
예제 #2
0
        /// <summary>
        /// Invokes the chat commands received.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="botUsername">The bot username.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="colorHex">The color hexadecimal.</param>
        /// <param name="color">The color.</param>
        /// <param name="emoteSet">The emote set.</param>
        /// <param name="message">The message.</param>
        /// <param name="userType">Type of the user.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="isSubscriber">if set to <c>true</c> [is subscriber].</param>
        /// <param name="subscribedMonthCount">The subscribed month count.</param>
        /// <param name="roomId">The room identifier.</param>
        /// <param name="isTurbo">if set to <c>true</c> [is turbo].</param>
        /// <param name="isModerator">if set to <c>true</c> [is moderator].</param>
        /// <param name="isMe">if set to <c>true</c> [is me].</param>
        /// <param name="isBroadcaster">if set to <c>true</c> [is broadcaster].</param>
        /// <param name="noisy">The noisy.</param>
        /// <param name="rawIrcMessage">The raw irc message.</param>
        /// <param name="emoteReplacedMessage">The emote replaced message.</param>
        /// <param name="badges">The badges.</param>
        /// <param name="cheerBadge">The cheer badge.</param>
        /// <param name="bits">The bits.</param>
        /// <param name="bitsInDollars">The bits in dollars.</param>
        /// <param name="commandText">The command text.</param>
        /// <param name="argumentsAsString">The arguments as string.</param>
        /// <param name="argumentsAsList">The arguments as list.</param>
        /// <param name="commandIdentifier">The command identifier.</param>
        public static void InvokeChatCommandsReceived(this TwitchClient client, string botUsername, string userId, string userName, string displayName,
                                                      string colorHex, Color color, EmoteSet emoteSet, string message, UserType userType, string channel, string id, bool isSubscriber, int subscribedMonthCount,
                                                      string roomId, bool isTurbo, bool isModerator, bool isMe, bool isBroadcaster, Noisy noisy, string rawIrcMessage, string emoteReplacedMessage,
                                                      List <KeyValuePair <string, string> > badges, CheerBadge cheerBadge, int bits, double bitsInDollars, string commandText, string argumentsAsString,
                                                      List <string> argumentsAsList, char commandIdentifier)
        {
            ChatMessage msg = new ChatMessage(botUsername, userId, userName, displayName, colorHex, color, emoteSet, message, userType, channel, id,
                                              isSubscriber, subscribedMonthCount, roomId, isTurbo, isModerator, isMe, isBroadcaster, noisy, rawIrcMessage, emoteReplacedMessage,
                                              badges, cheerBadge, bits, bitsInDollars);
            OnChatCommandReceivedArgs model = new OnChatCommandReceivedArgs()
            {
                Command = new ChatCommand(msg, commandText, argumentsAsString, argumentsAsList, commandIdentifier)
            };

            client.RaiseEvent("OnChatCommandReceived", model);
        }
예제 #3
0
        //Example IRC message: @badges=moderator/1,warcraft/alliance;color=;display-name=Swiftyspiffyv4;emotes=;mod=1;room-id=40876073;subscriber=0;turbo=0;user-id=103325214;user-type=mod :[email protected] PRIVMSG #swiftyspiffy :asd
        /// <summary>Constructor for ChatMessage object.</summary>
        /// <param name="botUsername">The username of the bot that received the message.</param>
        /// <param name="ircString">The raw string received from Twitch to be processed.</param>
        /// <param name="emoteCollection">The <see cref="MessageEmoteCollection"/> to register new emotes on and, if desired, use for emote replacement.</param>
        /// <param name="replaceEmotes">Whether to replace emotes for this chat message. Defaults to false.</param>
        public ChatMessage(string botUsername, string ircString, ref MessageEmoteCollection emoteCollection, bool replaceEmotes = false)
        {
            BotUsername = botUsername;
            RawIrcMessage = ircString;
            _emoteCollection = emoteCollection;
            foreach (var part in ircString.Split(';'))
            {
                if (part.Contains("!"))
                {
                    if (Channel == null)
                        Channel = part.Split('#')[1].Split(' ')[0];
                    if (Username == null)
                        Username = part.Split('!')[1].Split('@')[0];
                }
                else if(part.Contains("@badges="))
                {
                    Badges = new List<KeyValuePair<string, string>>();
                    string badges = part.Split('=')[1];
                    if(badges.Contains('/'))
                    {
                        if (!badges.Contains(","))
                            Badges.Add(new KeyValuePair<string, string>(badges.Split('/')[0], badges.Split('/')[1]));
                        else
                            foreach (string badge in badges.Split(','))
                                Badges.Add(new KeyValuePair<string, string>(badge.Split('/')[0], badge.Split('/')[1]));
                    }
                    // Iterate through saved badges for special circumstances
                    foreach(KeyValuePair<string, string> badge in Badges)
                    {
                        if (badge.Key == "bits")
                            CheerBadge = new CheerBadge(int.Parse(badge.Value));
                    }
                }
                else if(part.Contains("bits="))
                {
                    Bits = int.Parse(part.Split('=')[1]);
                    BitsInDollars = ConvertBitsToUSD(Bits);
                }
                else if (part.Contains("color="))
                {
                    if (ColorHex == null)
                        ColorHex = part.Split('=')[1];
                }
                else if (part.Contains("display-name"))
                {
                    if (DisplayName == null)
                        DisplayName = part.Split('=')[1];
                }
                else if (part.Contains("emotes="))
                {
                    if (EmoteSet == null)
                    {
                        EmoteSet = part.Split('=')[1]; ;
                    }

                }
                else if (part.Contains("subscriber="))
                {
                    Subscriber = part.Split('=')[1] == "1";
                }
                else if (part.Contains("turbo="))
                {
                    Turbo = part.Split('=')[1] == "1";
                }
                else if (part.Contains("user-id="))
                {
                    UserId = int.Parse(part.Split('=')[1]);
                }
                else if (part.Contains("user-type="))
                {
                    switch (part.Split('=')[1].Split(' ')[0])
                    {
                        case "mod":
                            UserType = Enums.UserType.Moderator;
                            break;
                        case "global_mod":
                            UserType = Enums.UserType.GlobalModerator;
                            break;
                        case "admin":
                            UserType = Enums.UserType.Admin;
                            break;
                        case "staff":
                            UserType = Enums.UserType.Staff;
                            break;
                        default:
                            UserType = Enums.UserType.Viewer;
                            break;
                    }
                }
                else if (part.Contains("mod="))
                {
                    IsModerator = part.Split('=')[1] == "1";
                }
            }
            Message = ircString.Split(new[] {$" PRIVMSG #{Channel} :"}, StringSplitOptions.None)[1];
            if ((byte)Message[0] == 1 && (byte)Message[Message.Length-1] == 1)
            {
              //Actions (/me {action}) are wrapped by byte=1 and prepended with "ACTION "
              //This setup clears all of that leaving just the action's text.
              //If you want to clear just the nonstandard bytes, use:
              //_message = _message.Substring(1, text.Length-2);
              Message = Message.Substring(8, Message.Length-9);
              IsMe = true;
            }

            //Parse the emoteSet
            if (EmoteSet != null && Message != null)
            {
                string[] uniqueEmotes = EmoteSet.Split('/');
                string id, text;
                int firstColon, firstComma, firstDash, low, high;
                foreach (string emote in uniqueEmotes)
                {
                    firstColon = emote.IndexOf(':');
                    firstComma = emote.IndexOf(',');
                    if (firstComma == -1) firstComma = emote.Length;
                    firstDash = emote.IndexOf('-');
                    if (firstColon > 0 && firstDash > firstColon && firstComma > firstDash)
                    {
                        if (Int32.TryParse(emote.Substring(firstColon + 1, (firstDash - firstColon) - 1), out low) &&
                            Int32.TryParse(emote.Substring(firstDash + 1, (firstComma - firstDash) - 1), out high))
                        {
                            if (low >= 0 && low < high && high < Message.Length)
                            {
                                //Valid emote, let's parse
                                id = emote.Substring(0, firstColon);
                                //Pull the emote text from the message
                                text = Message.Substring(low, (high - low) + 1);
                                _emoteCollection.Add(new MessageEmote(id, text));
                            }
                        }
                    }
                }
                if (replaceEmotes)
                {
                    EmoteReplacedMessage = _emoteCollection.ReplaceEmotes(Message);
                }
            }

            // Check if display name was set, and if it wasn't, set it to username
            if (string.IsNullOrEmpty(DisplayName))
                DisplayName = Username;

            // Check if message is from broadcaster
            if(Channel.ToLower() == Username.ToLower())
            {
                UserType = Enums.UserType.Broadcaster;
                IsBroadcaster = true;
            }
        }
예제 #4
0
 public ChatMessageBuilder WithCheerBadge(CheerBadge cheerBadge)
 {
     _cheerBadge = cheerBadge;
     return(this);
 }