예제 #1
0
        public async Task ClearAsync(
            [Summary("SteveJr#3333")][NoSelf][HigherReputation][UserOverride] IUser user,
            [Summary("3a")] Rule rule,
            [Summary("20")][Between(Config.MIN_CLEAR, Config.MAX_CLEAR)] int quantity = Config.CLEAR_DEFAULT,
            [Summary("stop spamming")][Remainder][MaxLength(Config.MAX_REASON_LENGTH)] string reason = null)
        {
            var messages = await Context.Channel.GetMessagesAsync().FlattenAsync();

            var filtered = messages.Where(x => x.Author.Id == user.Id).Take(quantity);

            if (filtered.Count() < 0)
            {
                await Context.ReplyAsync("There are no messages to delete.");
            }
            else
            {
                await Context.TextChannel.DeleteMessagesAsync(filtered);

                var msg = await Context.ReplyAsync(
                    $"You have successfully deleted {quantity} messages sent by {user.Bold()}.");

                await Task.Delay(Config.CLEAR_DELETE_DELAY);

                await msg.DeleteAsync();

                await _modService.LogClearAsync(Context, user, rule, quantity, reason);
            }
        }