diff --git a/app/Http/Controllers/DiscordTestController.php b/app/Http/Controllers/DiscordTestController.php index fd7815ad..586730c2 100644 --- a/app/Http/Controllers/DiscordTestController.php +++ b/app/Http/Controllers/DiscordTestController.php @@ -48,4 +48,19 @@ public function SendEmbed() If you would like to begin training again, please re-apply via the Gander Website.'); } + + public function DiscordRoles() + { + $discord = new DiscordClient(); + + //Get role ID based off status + $roles = [ + 'certified' => 482819739996127259, + 'student' => 482824058141016075, + ]; + + $discord->removeRole(200426385863344129, $roles['student']); + + dd($discord); + } } diff --git a/app/Jobs/ProcessDiscordRoles.php b/app/Jobs/ProcessDiscordRolesOld.php similarity index 96% rename from app/Jobs/ProcessDiscordRoles.php rename to app/Jobs/ProcessDiscordRolesOld.php index 3f31bff9..8758f76f 100644 --- a/app/Jobs/ProcessDiscordRoles.php +++ b/app/Jobs/ProcessDiscordRolesOld.php @@ -11,7 +11,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Contracts\Queue\ShouldBeUnique; -class ProcessDiscordRoles implements ShouldQueue +class ProcessDiscordRolesOld implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public $tries = 3; diff --git a/app/Services/DiscordClient.php b/app/Services/DiscordClient.php index f1ea5649..29904f71 100644 --- a/app/Services/DiscordClient.php +++ b/app/Services/DiscordClient.php @@ -105,16 +105,42 @@ public function ControllerDisconnect($id, $callsign, $name, $connect_time, $tota public function assignRole($discordId, $roleId) { - ProcessDiscordRoles::dispatch(true, $discordId, $roleId); - - return; + sleep(1); + + try { + $client = new Client(); + $client->request('PUT', "https://discord.com/api/v10/guilds/".env('DISCORD_GUILD_ID')."/members/" . $discordId . "/roles/" . $roleId, [ + 'headers' => [ + 'Authorization' => 'Bot ' . env('DISCORD_BOT_TOKEN'), + 'Content-Type' => 'application/json' + ], + ]); + } catch (\Exception $e) { + if ($e->getCode() !== 404) { + throw $e; + } + return; + } } public function removeRole($discordId, $roleId) { - ProcessDiscordRoles::dispatch(false, $discordId, $roleId); - - return; + sleep(2); + + try { + $client = new Client(); + $client->request('DELETE', "https://discord.com/api/v10/guilds/".env('DISCORD_GUILD_ID')."/members/" . $discordId . "/roles/" . $roleId, [ + 'headers' => [ + 'Authorization' => 'Bot ' . env('DISCORD_BOT_TOKEN'), + 'Content-Type' => 'application/json' + ], + ]); + } catch (\Exception $e) { + if ($e->getCode() !== 404) { + throw $e; + } + return; + } } public function changeName($userId, $name) diff --git a/routes/web.php b/routes/web.php index 4945251f..04792608 100644 --- a/routes/web.php +++ b/routes/web.php @@ -75,7 +75,7 @@ // Discord shortcut Route::get('/discord', [DiscordController::class, 'joinShortcut']); -Route::get('/discord/function-test', [DiscordTestController::class, 'Job']); +Route::get('/discord/function-test', [DiscordTestController::class, 'DiscordRoles']); // Public news articles Route::get('/news/{id}', [NewsController::class, 'viewArticlePublic'])->name('news.articlepublic')->where('id', '[0-9]+');