1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-29 18:49: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,20 +9,25 @@ namespace Boyfriend.Commands;
public class UnbanCommand : Command {
public override async Task Run(SocketCommandContext context, string[] args) {
var toUnban = await Utils.ParseUser(args[0]);
if (context.Guild.GetBanAsync(toUnban.Id) == null)
throw new ApplicationException(Messages.UserNotBanned);
UnbanUser(context.Guild, context.Channel as ITextChannel, context.Guild.GetUser(context.User.Id), toUnban,
Utils.JoinString(args, 1));
await UnbanUser(context.Guild, context.Channel as ITextChannel, context.Guild.GetUser(context.User.Id),
await Utils.ParseUser(args[0]), Utils.JoinString(args, 1));
}
public static async void UnbanUser(IGuild guild, ITextChannel? channel, IGuildUser author, IUser toUnban,
public static async Task UnbanUser(IGuild guild, ITextChannel? channel, IGuildUser author, IUser toUnban,
string reason) {
await CommandHandler.CheckPermissions(author, GuildPermission.BanMembers);
var authorMention = author.Mention;
var notification = string.Format(Messages.UserUnbanned, authorMention, toUnban.Mention,
Utils.WrapInline(reason));
await guild.RemoveBanAsync(toUnban);
var requestOptions = Utils.GetRequestOptions($"({Utils.GetNameAndDiscrim(author)}) {reason}");
await CommandHandler.CheckPermissions(author, GuildPermission.BanMembers);
if (guild.GetBanAsync(toUnban.Id) == null)
throw new ApplicationException(Messages.UserNotBanned);
await guild.RemoveBanAsync(toUnban, requestOptions);
await Utils.SilentSendAsync(channel, string.Format(Messages.UnbanResponse, toUnban.Mention,
Utils.WrapInline(reason)));
await Utils.SilentSendAsync(await guild.GetSystemChannelAsync(), notification);