1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 17:19:00 +03:00
Octobot/Boyfriend/Commands/ClearModule.cs

33 lines
1.4 KiB
C#
Raw Normal View History

2021-12-10 14:25:29 +03:00
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;
2021-12-15 09:19:14 +03:00
await CommandHandler.CheckPermissions(Context.Guild.GetUser(Context.User.Id), GuildPermission.ManageMessages);
2021-12-10 14:25:29 +03:00
switch (toDelete) {
case < 1:
2021-12-15 09:19:14 +03:00
throw new Exception( "Указано отрицательное количество сообщений!");
2021-12-10 14:25:29 +03:00
case > 200:
2021-12-15 09:19:14 +03:00
throw new Exception("Указано слишком много сообщений!");
2021-12-10 14:25:29 +03:00
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;
}
}
}
}