mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-29 10:39:53 +03:00
ton of stuff
- new command handler - multilanguage support - time out support - responses - a ton of stuff
This commit is contained in:
parent
1c9caf6d75
commit
f30485dd71
29 changed files with 1686 additions and 520 deletions
49
Boyfriend/Commands/ClearCommand.cs
Normal file
49
Boyfriend/Commands/ClearCommand.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using Discord;
|
||||
using Discord.Commands;
|
||||
|
||||
// ReSharper disable UnusedType.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable ClassNeverInstantiated.Global
|
||||
|
||||
namespace Boyfriend.Commands;
|
||||
|
||||
public class ClearCommand : Command {
|
||||
public override async Task Run(SocketCommandContext context, string[] args) {
|
||||
int toDelete;
|
||||
try {
|
||||
toDelete = Convert.ToInt32(args[0]);
|
||||
}
|
||||
catch (Exception e) when (e is FormatException or OverflowException) {
|
||||
throw new ApplicationException(Messages.ClearInvalidAmountSpecified);
|
||||
}
|
||||
|
||||
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 ApplicationException(Messages.ClearNegativeAmount);
|
||||
case > 200:
|
||||
throw new ApplicationException(Messages.ClearAmountTooLarge);
|
||||
default: {
|
||||
var messages = await channel.GetMessagesAsync(toDelete + 1).FlattenAsync();
|
||||
await channel.DeleteMessagesAsync(messages);
|
||||
await Utils.SilentSendAsync(await Utils.GetAdminLogChannel(context.Guild),
|
||||
string.Format(Messages.MessagesDeleted, context.User.Mention, toDelete + 1,
|
||||
Utils.MentionChannel(context.Channel.Id)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override List<string> GetAliases() {
|
||||
return new List<string> {"clear", "purge", "очистить", "стереть"};
|
||||
}
|
||||
|
||||
public override int GetArgumentsAmountRequired() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override string GetSummary() {
|
||||
return "Очищает сообщения";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue