From 5512d0045edaadc9fc57f9bde309f24f05e4da62 Mon Sep 17 00:00:00 2001 From: miguel456 Date: Tue, 23 Aug 2022 04:42:47 +0100 Subject: [PATCH] feat: add removeGuildBan --- app/Helpers/Discord.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Helpers/Discord.php b/app/Helpers/Discord.php index e8b4741..679164c 100644 --- a/app/Helpers/Discord.php +++ b/app/Helpers/Discord.php @@ -134,6 +134,25 @@ class Discord throw new AccountNotLinkedException('Specified website user has not linked their Discord account yet.'); } + /** + * @param string $reason The removal reason to provide Discord with (e.g. ban expired) + * @return null|bool Null on unnan, false if user is not banned + * @throws RequestException + */ + public function removeGuildBan(string $reason): null|bool { + + if ($this->getGuildBan($this->user)) { + Http::withHeaders([ + 'Authorization' => 'Bot ' . config('services.discord.token'), + 'X-Audit-Log-Reason' => $reason + ])->delete(config('services.discord.base_url') . "/guilds/{$this->workingGuild}/bans/{$this->user->discord_user_id}") + ->throw(); + + return null; + } + return false; + } + /** * Gets (possible) ban for current user. * @@ -153,5 +172,4 @@ class Discord return ($ban->successful()) ? (object) $ban->json() : $ban->throwIf($ban->status() !== 404); } - }