This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
OctobotStealth/Boyfriend/Commands/ClearModule.cs
2021-12-15 11:19:14 +05:00

33 lines
No EOL
1.4 KiB
C#

using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace Boyfriend.Commands;
public class ClearModule : ModuleBase<SocketCommandContext> {
[Command("clear")]
[Summary("Удаляет указанное количество сообщений")]
[Alias("очистить")]
public async Task Run(int toDelete) {
if (Context.Channel is not ITextChannel channel) return;
await CommandHandler.CheckPermissions(Context.Guild.GetUser(Context.User.Id), GuildPermission.ManageMessages);
switch (toDelete) {
case < 1:
throw new Exception( "Указано отрицательное количество сообщений!");
case > 200:
throw new Exception("Указано слишком много сообщений!");
default: {
var messages = await channel.GetMessagesAsync(toDelete + 1).FlattenAsync();
await channel.DeleteMessagesAsync(messages);
await Utils.GetAdminLogChannel().SendMessageAsync(
$"{Context.User.Mention} удаляет {toDelete + 1} сообщений в канале " +
$"{Utils.MentionChannel(Context.Channel.Id)}");
break;
}
}
}
}