Implements purge messages command

This commit is contained in:
Deukhoofd 2019-01-29 11:03:01 +01:00
parent 585dabce39
commit 67e793de47
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 27 additions and 0 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DeukBot4.Database.ServerSettings; using DeukBot4.Database.ServerSettings;
using DeukBot4.MessageHandlers.CommandHandler.RequestStructure; using DeukBot4.MessageHandlers.CommandHandler.RequestStructure;
@ -13,6 +14,32 @@ namespace DeukBot4.MessageHandlers.CommandHandler
{ {
public override string Name => "Moderator"; public override string Name => "Moderator";
[Command("purge", PermissionLevel.Moderator)]
[CommandHelp("Purges a set number of messages",
"Purges a set number of messages. \n" +
"Usage: \n" +
"``!purge {number}`")]
[CommandParameters(ParameterMatcher.ParameterType.Number)]
[BlockUsageInPm, RequireParameterMatch]
public async Task PurgeMessages(CommandRequest request)
{
// get the server channel object out of message. Return if it's somehow not a server channel
if (!(request.OriginalMessage.Channel is ITextChannel channel))
return;
var messageCountParameter = request.Parameters[0].AsInt();
if (!messageCountParameter.HasValue)
return;
var messageCount = messageCountParameter.Value;
var messages = channel.GetMessagesAsync(request.OriginalMessage, Direction.Before, messageCount);
messages.ForEachAsync(x =>
{
foreach (var message in x)
{
message.DeleteAsync();
}
});
}
[Command("kick", PermissionLevel.Moderator)] [Command("kick", PermissionLevel.Moderator)]
[CommandParameters(ParameterMatcher.ParameterType.User, ParameterMatcher.ParameterType.Remainder)] [CommandParameters(ParameterMatcher.ParameterType.User, ParameterMatcher.ParameterType.Remainder)]
[CommandHelp("Kicks a user from the server", [CommandHelp("Kicks a user from the server",