1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-29 10:39:53 +03:00

general code refactor and bug fixes

This commit is contained in:
l1ttleO 2022-02-02 18:14:26 +05:00
parent 4d838e5af3
commit 04facc3de2
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
15 changed files with 197 additions and 132 deletions

View file

@ -9,16 +9,19 @@ namespace Boyfriend.Commands;
public class ClearCommand : Command {
public override async Task Run(SocketCommandContext context, string[] args) {
var user = context.User;
int toDelete;
try {
toDelete = Convert.ToInt32(args[0]);
}
catch (Exception e) when (e is FormatException or OverflowException) {
} 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);
await CommandHandler.CheckPermissions(context.Guild.GetUser(user.Id), GuildPermission.ManageMessages);
switch (toDelete) {
case < 1:
throw new ApplicationException(Messages.ClearNegativeAmount);
@ -26,9 +29,11 @@ public class ClearCommand : Command {
throw new ApplicationException(Messages.ClearAmountTooLarge);
default: {
var messages = await channel.GetMessagesAsync(toDelete + 1).FlattenAsync();
await channel.DeleteMessagesAsync(messages);
await channel.DeleteMessagesAsync(messages, Utils.GetRequestOptions(Utils.GetNameAndDiscrim(user)));
await Utils.SilentSendAsync(await Utils.GetAdminLogChannel(context.Guild),
string.Format(Messages.MessagesDeleted, context.User.Mention, toDelete + 1,
string.Format(Messages.MessagesDeleted, user.Mention, toDelete + 1,
Utils.MentionChannel(context.Channel.Id)));
break;
}
@ -46,4 +51,4 @@ public class ClearCommand : Command {
public override string GetSummary() {
return "Очищает сообщения";
}
}
}