Пример #1
0
    private void HandleAfkCommand(TwitchChatMessage chatMessage)
    {
        foreach (AfkCommandType type in AfkCommandTypes)
        {
            // ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
            foreach (string alias in AppSettings.CommandList[type].Alias)
            {
                Regex pattern = PatternCreator.Create(alias, chatMessage.Channel.Prefix, @"(\s|$)");

                // ReSharper disable once InvertIf
                if (pattern.IsMatch(chatMessage.Message))
                {
                    if (CooldownController.IsOnAfkCooldown(chatMessage.UserId))
                    {
                        return;
                    }

                    AfkCommandHandler.Handle(chatMessage, type);
                    CooldownController.AddAfkCooldown(chatMessage.UserId);
                    TwitchBot.CommandCount++;
                    return;
                }
            }
        }
    }
Пример #2
0
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage)
 {
     if (MessageHelper.IsCommand(chatMessage))
     {
         ((CommandType[])Enum.GetValues(typeof(CommandType))).ToList().ForEach(type =>
         {
             if (chatMessage.MatchesAnyAlias(type))
             {
                 if (!BotActions.IsOnCooldown(chatMessage.Username, type))
                 {
                     CommandHelper.GetCommand(type).Alias.ForEach(alias =>
                     {
                         if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"(\s|$)")))
                         {
                             BotActions.AddUserToCooldownDictionary(chatMessage.Username, type);
                             Type.GetType(CommandHelper.GetCommandClassName(type)).GetMethod(_handleName).Invoke(null, new object[] { twitchBot, chatMessage, alias });
                             BotActions.AddCooldown(chatMessage.Username, type);
                         }
                     });
                 }
             }
         });
         twitchBot.CommandCount++;
     }
     else if (MessageHelper.IsAfkCommand(chatMessage))
     {
         ((AfkCommandType[])Enum.GetValues(typeof(AfkCommandType))).ToList().ForEach(type =>
         {
             if (chatMessage.MatchesAnyAlias(type))
             {
                 if (!BotActions.IsOnAfkCooldown(chatMessage.Username))
                 {
                     CommandHelper.GetAfkCommand(type).Alias.ForEach(alias =>
                     {
                         if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"(\s|$)")))
                         {
                             BotActions.AddUserToAfkCooldownDictionary(chatMessage.Username);
                             AfkCommandHandler.Handle(twitchBot, chatMessage, type);
                             BotActions.AddAfkCooldown(chatMessage.Username);
                         }
                     });
                 }
             }
         });
         twitchBot.CommandCount++;
     }
 }