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)
        {
            var 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);
            var model = new OnChatCommandReceivedArgs()
            {
                Command = new ChatCommand(msg, commandText, argumentsAsString, argumentsAsList, commandIdentifier)
            };

            client.RaiseEvent("OnChatCommandReceived", model);
        }
示例#2
0
        public void PropertyTest()
        {
            Mock <ITwitchChannelLink> cLink = new Mock <ITwitchChannelLink>();

            EmoteSet    emoteSet    = new EmoteSet("0:2-1", "Hello World");
            ChatMessage chatMessage = new ChatMessage("SchwabenCode", "123", "BenAbt", "Benjamin Abt", "001122",
                                                      Color.Black, emoteSet,
                                                      "Hello World", UserType.Admin, "BenAbt", "1", true, 1, "123", true, true, true, true, Noisy.True,
                                                      "Hello Irc World", ":-)", null, new CheerBadge(1), 1, 1);
            ChatCommand chatCommand = new ChatCommand(chatMessage);
            TwitchChatCommandReceivedNotification
                notification = new TwitchChatCommandReceivedNotification(cLink.Object, chatCommand);

            notification.ChannelLink.Should().NotBeNull();
            notification.ChannelLink.Should().Be(cLink.Object);
            notification.Command.Should().Be(chatCommand);
        }
示例#3
0
 public void AddRecord(List <EmoteSet> emoteSets, List <string> currentColumns, List <string> fields, bool isEmote)
 {
     if (isEmote)
     {
         var emote = new Emote();
         PopulateFields(emote, currentColumns, fields);
         var currentSet = emoteSets.LastOrDefault();
         if (currentSet == null)
         {
             Console.WriteLine($"SQLReader.AddRecord() - failed to add emote for unknown set");
             return;
         }
         emote.ValidBranches = Emote.GetValidBranches(emote.Type);
         currentSet.Add(emote);
     }
     else
     {
         var emoteSet = new EmoteSet();
         PopulateFields(emoteSet, currentColumns, fields);
         emoteSets.Add(emoteSet);
     }
 }
示例#4
0
        private async void Client_OnMessageReceivedAsync(object sender, OnMessageReceivedArgs e)
        {
            IEnumerable <IChatService> chatServices = serviceProvider.GetServices <IChatService>();
            string botResponse = string.Empty;

            foreach (IChatService chatService in chatServices)
            {
                botResponse = await chatService.ProcessMessageAsync(e.ChatMessage);

                if (!string.IsNullOrEmpty(botResponse))
                {
                    break;
                }
            }

            await _overlayHubContext.Clients.All.SendAsync("ReceiveNewChatMessage", new ChatHubMessage(e.ChatMessage));

            if (!string.IsNullOrEmpty(botResponse))
            {
                ChatHubMessage chatHubMessage = new ChatHubMessage(botResponse);
                await _overlayHubContext.Clients.All.SendAsync("ReceiveNewChatMessage", chatHubMessage);
            }

            EmoteSet emoteSet = e.ChatMessage.EmoteSet;

            if (emoteSet != null && emoteSet.Emotes.Count > 0)
            {
                List <EmoteSet.Emote> emotes = emoteSet.Emotes;

                foreach (EmoteSet.Emote emote in emotes)
                {
                    await _overlayHubContext.Clients.All.SendAsync("ReceiveNewEmoji", emote.ImageUrl);

                    await Task.Delay(500);
                }
            }
        }
示例#5
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 TwitchClientClasses.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 = Common.UserType.Moderator;
                        break;

                    case "global_mod":
                        UserType = Common.UserType.GlobalModerator;
                        break;

                    case "admin":
                        UserType = Common.UserType.Admin;
                        break;

                    case "staff":
                        UserType = Common.UserType.Staff;
                        break;

                    default:
                        UserType = Common.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      = Common.UserType.Broadcaster;
                IsBroadcaster = true;
            }
        }
示例#6
0
        /// <summary>
        /// Invokes the whisper received.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="badges">The badges.</param>
        /// <param name="colorHex">The color hexadecimal.</param>
        /// <param name="color">The color.</param>
        /// <param name="username">The username.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="emoteSet">The emote set.</param>
        /// <param name="threadId">The thread identifier.</param>
        /// <param name="messageId">The message identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="isTurbo">if set to <c>true</c> [is turbo].</param>
        /// <param name="botUsername">The bot username.</param>
        /// <param name="message">The message.</param>
        /// <param name="userType">Type of the user.</param>
        public static void InvokeWhisperReceived(this TwitchClient client, List <KeyValuePair <string, string> > badges, string colorHex, Color color, string username, string displayName, EmoteSet emoteSet, string threadId, string messageId,
                                                 string userId, bool isTurbo, string botUsername, string message, UserType userType)
        {
            OnWhisperReceivedArgs model = new OnWhisperReceivedArgs()
            {
                WhisperMessage = new WhisperMessage(badges, colorHex, color, username, displayName, emoteSet, threadId, messageId, userId, isTurbo, botUsername, message, userType)
            };

            client.RaiseEvent("OnWhisperReceived", model);
        }
示例#7
0
        /// <summary>
        /// Invokes the whisper command received.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="badges">The badges.</param>
        /// <param name="colorHex">The color hexadecimal.</param>
        /// <param name="color">The color.</param>
        /// <param name="username">The username.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="emoteSet">The emote set.</param>
        /// <param name="threadId">The thread identifier.</param>
        /// <param name="messageId">The message identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="isTurbo">if set to <c>true</c> [is turbo].</param>
        /// <param name="botUsername">The bot username.</param>
        /// <param name="message">The message.</param>
        /// <param name="userType">Type of the user.</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 InvokeWhisperCommandReceived(this TwitchClient client, List <KeyValuePair <string, string> > badges, string colorHex, Color color, string username, string displayName, EmoteSet emoteSet, string threadId, string messageId,
                                                        string userId, bool isTurbo, string botUsername, string message, UserType userType, string commandText, string argumentsAsString, List <string> argumentsAsList, char commandIdentifier)
        {
            WhisperMessage whisperMsg          = new WhisperMessage(badges, colorHex, color, username, displayName, emoteSet, threadId, messageId, userId, isTurbo, botUsername, message, userType);
            OnWhisperCommandReceivedArgs model = new OnWhisperCommandReceivedArgs()
            {
                Command = new WhisperCommand(whisperMsg, commandText, argumentsAsString, argumentsAsList, commandIdentifier)
            };

            client.RaiseEvent("OnWhisperCommandReceived", model);
        }
示例#8
0
        private ActionResult HandlePostback(Weenie model)
        {
            model.CleanDeletedAndEmptyProperties();

            switch (model.MvcAction)
            {
            case WeenieCommands.AddIntProperty:
                if (model.NewIntPropertyId == null)
                {
                    model.ErrorMessages.Add("You must select a Property to add.");
                }
                else
                {
                    model.IntProperties.Add(new IntProperty()
                    {
                        IntPropertyId = (int)model.NewIntPropertyId.Value
                    });
                }

                model.NewIntPropertyId = null;
                break;

            case WeenieCommands.AddStringProperty:
                if (model.NewStringPropertyId == null)
                {
                    model.ErrorMessages.Add("You must select a Property to add.");
                }
                else
                {
                    model.StringProperties.Add(new StringProperty()
                    {
                        StringPropertyId = (int)model.NewStringPropertyId.Value
                    });
                }

                model.NewStringPropertyId = null;
                break;

            case WeenieCommands.AddInt64Property:
                if (model.NewInt64PropertyId == null)
                {
                    model.ErrorMessages.Add("You must select a Property to add.");
                }
                else
                {
                    model.Int64Properties.Add(new Int64Property()
                    {
                        Int64PropertyId = (int)model.NewInt64PropertyId.Value
                    });
                }

                model.NewInt64PropertyId = null;
                break;

            case WeenieCommands.AddDoubleProperty:
                if (model.NewDoublePropertyId == null)
                {
                    model.ErrorMessages.Add("You must select a Property to add.");
                }
                else
                {
                    model.DoubleProperties.Add(new DoubleProperty()
                    {
                        DoublePropertyId = (int)model.NewDoublePropertyId.Value
                    });
                }

                model.NewDoublePropertyId = null;
                break;

            case WeenieCommands.AddDidProperty:
                if (model.NewDidPropertyId == null)
                {
                    model.ErrorMessages.Add("You must select a Property to add.");
                }
                else
                {
                    model.DidProperties.Add(new DataIdProperty()
                    {
                        DataIdPropertyId = (int)model.NewDidPropertyId.Value
                    });
                }

                model.NewDidPropertyId = null;
                break;

            case WeenieCommands.AddIidProperty:
                if (model.NewIidPropertyId == null)
                {
                    model.ErrorMessages.Add("You must select a Property to add.");
                }
                else
                {
                    model.IidProperties.Add(new InstanceIdProperty()
                    {
                        IidPropertyId = (int)model.NewIidPropertyId.Value
                    });
                }

                model.NewIidPropertyId = null;
                break;

            case WeenieCommands.AddBoolProperty:
                if (model.NewBoolPropertyId == null)
                {
                    model.ErrorMessages.Add("You must select a Property to add.");
                }
                else
                {
                    model.BoolProperties.Add(new BoolProperty()
                    {
                        BoolPropertyId = (int)model.NewBoolPropertyId.Value
                    });
                }

                model.NewBoolPropertyId = null;
                break;

            case WeenieCommands.AddSpell:
                if (model.NewSpellId == null)
                {
                    model.ErrorMessages.Add("You must select a Spell to add.");
                }
                else
                {
                    model.Spells.Add(new Spell()
                    {
                        SpellId = (int)model.NewSpellId.Value
                    });
                }

                model.NewSpellId = null;
                break;

            case WeenieCommands.AddPosition:
                if (model.NewPositionType == null)
                {
                    model.ErrorMessages.Add("You must select a Position Type to add.");
                }
                else
                {
                    model.Positions.Add(new Models.Shared.Position()
                    {
                        PositionType = (int)model.NewPositionType.Value
                    });
                }

                break;

            case WeenieCommands.AddBookPage:
                model.BookProperties.Add(new BookPage()
                {
                    Page = (uint)model.BookProperties.Count
                });
                break;

            case WeenieCommands.AddEmoteSet:
                model.EmoteTable.Add(new EmoteSet()
                {
                    EmoteCategoryId = (uint)model.NewEmoteCategory, EmoteSetGuid = Guid.NewGuid()
                });
                model.NewEmoteCategory = EmoteCategory.Invalid;
                break;

            case WeenieCommands.AddGeneratorTable:
                model.GeneratorTable.Add(new Models.Shared.GeneratorTable());
                break;

            case WeenieCommands.AddEmote:
                EmoteSet emoteSet = model.EmoteTable.FirstOrDefault(es => es.EmoteSetGuid == model.EmoteSetGuid);

                if (emoteSet == null)
                {
                    model.ErrorMessages.Add("You must select an Emote Type to add.");
                }
                else
                {
                    var order = emoteSet.Emotes.Max(e => e.SortOrder) + 1;
                    emoteSet.Emotes.Add(new Models.Shared.Emote()
                    {
                        EmoteSetGuid = emoteSet.EmoteSetGuid, EmoteType = emoteSet.NewEmoteType, EmoteGuid = Guid.NewGuid(), SortOrder = order
                    });
                    emoteSet.NewEmoteType = EmoteType.Invalid;
                }

                break;

            case WeenieCommands.AddSkill:
                if (model.NewSkillId == null)
                {
                    model.ErrorMessages.Add("You must select a skill to add.");
                }
                else
                {
                    model.Skills.Add(new Models.Shared.Skill()
                    {
                        SkillId = (int)model.NewSkillId.Value
                    });
                }

                break;

            case WeenieCommands.AddCreateItem:
                model.CreateList.Add(new CreationProfile()
                {
                    CreationProfileGuid = Guid.NewGuid(), OwnerId = model.DataObjectId
                });
                break;

            case WeenieCommands.AddBodyParts:
                model.BodyParts = new List <Models.Shared.BodyPart>
                {
                    new Models.Shared.BodyPart()
                    {
                        BodyPartType = 0
                    }
                };
                break;

            case WeenieCommands.AddBodyPart:
                model.BodyParts.Add(new Models.Shared.BodyPart()
                {
                    BodyPartType = model.NewBodyPartType ?? BodyPartType.Head
                });
                break;

            case null:
                return(null);
            }

            SortTheThings(model);
            model.MvcAction       = null;
            model.NewPositionType = null;
            return(View("Edit", model));
        }
 public IChatMessageEmoteResolver Get(EmoteSet emotes)
 {
     return(new TwitchChatMessageEmoteResolver(emotes, emoteRepository));
 }
示例#10
0
 public EmoteSetIndent(EmoteSet emoteSet, int indent = 0)
 {
     EmoteSet = emoteSet;
     Indent   = indent;
 }
示例#11
0
 public TwitchLibMessageBuilder WithEmoteSet(EmoteSet emoteSet)
 {
     EmoteSet = emoteSet;
     return(this);
 }