Implements purge messages command
This commit is contained in:
parent
585dabce39
commit
67e793de47
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DeukBot4.Database.ServerSettings;
|
||||
using DeukBot4.MessageHandlers.CommandHandler.RequestStructure;
|
||||
|
@ -13,6 +14,32 @@ namespace DeukBot4.MessageHandlers.CommandHandler
|
|||
{
|
||||
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)]
|
||||
[CommandParameters(ParameterMatcher.ParameterType.User, ParameterMatcher.ParameterType.Remainder)]
|
||||
[CommandHelp("Kicks a user from the server",
|
||||
|
|
Loading…
Reference in New Issue