예제 #1
0
        public void CommandReceivedHandler(object sender, CommandReceivedEventArgs e)
        {
            if (!(sender is IChatClient chatClient))
            {
                return;
            }

            IBotCommand botCommand = _commandMessages.FirstOrDefault(c => c.ShouldExecute(e.CommandWord));

            if (botCommand == null)
            {
                return;
            }

            var cooldown = _usageTracker.GetActiveCooldown(e.ChatUser, botCommand);

            switch (cooldown)
            {
            case NoCooldown none:
                ProcessTheCommand(e, chatClient, botCommand);
                break;

            case UserCooldown userCooldown:
                chatClient.SendDirectMessage(e.ChatUser.DisplayName, userCooldown.Message);
                break;

            case UserCommandCooldown userCommandCooldown:
                chatClient.SendDirectMessage(e.ChatUser.DisplayName, userCommandCooldown.Message);
                break;

            case CommandCooldown commandCooldown:
                chatClient.SendMessage(commandCooldown.Message);
                break;
            }
        }
예제 #2
0
        public void CommandReceivedHandler(object sender, CommandReceivedEventArgs e)
        {
            if (!(sender is IChatClient chatClient))
            {
                return;
            }

            string userDisplayName = e.ChatUser.DisplayName;


            //List<CommandUsage> globalCooldownUsages = _usageTracker.GetUsagesByUserSubjectToGlobalCooldown(userDisplayName, DateTimeOffset.UtcNow);
            //if (globalCooldownUsages != null && globalCooldownUsages.Any() && !e.ChatUser.IsInThisRoleOrHigher(UserRole.Mod))
            //{
            //    if (!globalCooldownUsages.Any(x => x.WasUserWarned))
            //    {
            //        chatClient.SendMessage($"Whoa {userDisplayName}! Slow down there cowboy!");
            //        globalCooldownUsages.ForEach(x => x.WasUserWarned = true);
            //    }

            //    return;
            //}

            IBotCommand botCommand = _commandMessages.FirstOrDefault(c => c.ShouldExecute(e.CommandWord));

            if (botCommand == null)
            {
                return;
            }
            var cooldown = _usageTracker.GetActiveCooldown(e.ChatUser, botCommand);

            chatClient.SendMessage(cooldown.Message);
            // TODO: prevent running the command if there was a cooldown

            switch (cooldown)
            {
            case NoCooldown none:
                break;

            case UserCooldown userCooldown:
                chatClient.SendDirectMessage(e.ChatUser.DisplayName, userCooldown.Message);
                break;

            case UserCommandCooldown userCommandCooldown:
                chatClient.SendDirectMessage(e.ChatUser.DisplayName, userCommandCooldown.Message);
                break;

            case CommandCooldown commandCooldown:
                chatClient.SendMessage(commandCooldown.Message);
                break;

            default:
                break;
            }

            DoTheThing(e, chatClient, botCommand);
        }
예제 #3
0
        public void CommandReceivedHandler(object sender, CommandReceivedEventArgs e)
        {
            if (!(sender is IChatClient chatClient))
            {
                return;
            }

            IList <string> args       = new List <string>();
            IBotCommand    botCommand = _commandList.FirstOrDefault(c => c.ShouldExecute(e.CommandWord, out args));

            if (botCommand == null)
            {
                return;
            }

            // TODO:Remove this soon and replace with smarter code
            if (botCommand is RefreshCommandListCommand refreshCommand &&
                refreshCommand.NeedsInitializing)
            {
                refreshCommand.Initialize(_commandList);
            }

            var cooldown = _usageTracker.GetActiveCooldown(e.ChatUser, botCommand);

            switch (cooldown)
            {
            case NoCooldown none:
                ProcessTheCommand(e, chatClient, botCommand, args);
                break;

            case UserCooldown userCooldown:
                chatClient.SendDirectMessage(e.ChatUser.DisplayName, userCooldown.Message);
                break;

            case UserCommandCooldown userCommandCooldown:
                chatClient.SendDirectMessage(e.ChatUser.DisplayName, userCommandCooldown.Message);
                break;

            case CommandCooldown commandCooldown:
                chatClient.SendMessage(commandCooldown.Message);
                break;
            }
        }
예제 #4
0
        public void CommandReceivedHandler(object sender, CommandReceivedEventArgs e)
        {
            if (!(sender is IChatClient chatClient))
            {
                return;
            }

            IList <string> args       = new List <string>();
            IBotCommand    botCommand = _commandList.FindCommandByKeyword(e.CommandWord, out args);

            if (botCommand == null)
            {
                return;
            }

            var cooldown = _usageTracker.GetActiveCooldown(e.ChatUser, botCommand);

            switch (cooldown)
            {
            case NoCooldown none:
                ProcessTheCommand(e, chatClient, botCommand, args);
                break;

            case UserCooldown userCooldown:
                chatClient.SendDirectMessage(e.ChatUser.DisplayName, userCooldown.Message);
                break;

            case UserCommandCooldown userCommandCooldown:
                chatClient.SendDirectMessage(e.ChatUser.DisplayName, userCommandCooldown.Message);
                break;

            case CommandCooldown commandCooldown:
                chatClient.SendMessage(commandCooldown.Message);
                break;
            }
        }