Adding Admin Commands for Purging Messages

This commit is contained in:
Sean "Solao Bajiuik" Stoves 2020-06-03 00:17:38 -04:00
parent 2c88b7f1c9
commit 4e59ccb85d
2 changed files with 40 additions and 0 deletions

View File

@ -12,6 +12,7 @@
<e p="Discord" t="Include">
<e p="DiscordConnect.cs" t="Include" />
<e p="Modules" t="Include">
<e p="AdminCommands.cs" t="Include" />
<e p="InfoCommands.cs" t="Include" />
</e>
<e p="Services" t="Include">

View File

@ -0,0 +1,39 @@
using System;
using Discord;
using System.Text;
using Discord.Commands;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using NLog;
namespace ChaosBot.Discord.Modules
{
public class AdminCommands : ModuleBase
{
private static readonly Logger _logger = Program._logger;
[Command("clear")]
[Alias("purge")]
[RequireBotPermission(GuildPermission.ManageMessages)]
[RequireUserPermission(GuildPermission.ManageMessages)]
public async Task ClearCommand(int msgtoDelete = 1)
{
try
{
IEnumerable<IMessage> messages = await Context.Channel.GetMessagesAsync(msgtoDelete + 1).FlattenAsync();
await ((ITextChannel) Context.Channel).DeleteMessagesAsync(messages);
const int delay = 3000;
IUserMessage m = await ReplyAsync($"{msgtoDelete} messages deleted.");
await Task.Delay(delay);
await m.DeleteAsync();
}
catch (Exception ex)
{
_logger.Error($"InfoCommands.InfoCommand: Exception [{ex}] thrown, <[{ex.Message}]>.");
}
}
}
}