Пример #1
0
        public async Task Delete([Summary("The range of messages to delete")] int range)
        {
            if (Moderation.IsCorrectRole(Context, new[] { "Founders", "Moderators", "Regulars" }))
            {
                var messageList = await Context.Channel.GetMessagesAsync(range).Flatten();

                await Context.Channel.DeleteMessagesAsync(messageList);

                await ReplyAsync($"Deleted the last {range} messages.");
            }
            else
            {
                await ReplyAsync("Couldn't delete messages: Insufficient role");
            }
        }
Пример #2
0
        public async Task Delete([Summary("The most recent message ID to start deleting at")] ulong startMessage, [Summary("The last message ID to delete")] ulong endMessage)
        {
            if (Moderation.IsCorrectRole(Context, new[] { "Founders", "Moderators", "Regulars" })) // todo: replace this array with something better
            {
                var messageList = (await Context.Channel.GetMessagesAsync(500).Flatten()).ToList();
                int startIndex  = messageList.FindIndex(m => m.Id == startMessage);
                int endIndex    = messageList.FindIndex(m => m.Id == endMessage);
                if (startIndex == -1 || endIndex == -1)
                {
                    await ReplyAsync("Couldn't delete messages: The start or end message ID couldn't be found");

                    return;
                }
                var messageRange = (startIndex > endIndex) ? messageList.GetRange(endIndex - 1, (startIndex - endIndex) + 1) : messageList.GetRange(startIndex, (endIndex - startIndex) + 1);
                await Context.Channel.DeleteMessagesAsync(messageRange);

                await ReplyAsync($"Deleted {Math.Abs(endIndex - startIndex) + 1} messages");
            }
            else
            {
                await ReplyAsync("Couldn't delete messages: Insufficient role");
            }
        }