From b30edb556145ed72a1f9a1d0732c562229fbd0ab Mon Sep 17 00:00:00 2001 From: JoshuaMicallefYBSU <91457812+JoshuaMicallefYBSU@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:51:35 +1000 Subject: [PATCH] ControllerApplication - Discord Announcement Update --- .../Controllers/DiscordTestController.php | 18 ++-- .../Training/ApplicationsController.php | 28 ++++--- app/Services/DiscordClient.php | 83 ++++++++++++++++++- .../2024_10_23_update_applications.php | 32 +++++++ .../training/applications/apply.blade.php | 14 ++-- routes/web.php | 4 +- 6 files changed, 146 insertions(+), 33 deletions(-) create mode 100644 database/migrations/2024_10_23_update_applications.php diff --git a/app/Http/Controllers/DiscordTestController.php b/app/Http/Controllers/DiscordTestController.php index 22413047..26e03f23 100644 --- a/app/Http/Controllers/DiscordTestController.php +++ b/app/Http/Controllers/DiscordTestController.php @@ -58,20 +58,20 @@ public function SendEmbed() //New Applicant in Instructor Channel $discord = new DiscordClient(); - $discord->sendMessageWithEmbed('488265136696459292', 'Discord Account Not Linked on CZQO', + $discord->sendMessageWithEmbed('1298229107334844518', '', -'Dear Gander Members, +'## :mega: Staff Role Updates -If you have been pinged in this message, it means your discord account is not linked on the Gander Oceanic Website. +Dear Valued Staff, -We ask that you head to the [Gander Oceanic Website](https://ganderoceanic.ca/my) to link your Discord Account. This will automatically update your roles and name with Gander Oceanic daily. +Roles have been updated & synced with the Gander Core. As such, some of you may be missing staff roles. -Access for users not linked will be limited from the 11/31/2024. +If so, please DM <@200426385863344129> so he can fix this for you. -Thank You, -Gander Oceanic Team +Thanks all, +Gander Oceanic Web Team +'); -<@&1297422968472997908>'); } public function DiscordRoles() @@ -92,7 +92,7 @@ public function DiscordRoles() public function sendMessage() { $discord = new DiscordClient(); - $discord->sendDM('200426385863344129', 'Test message'); + $discord->sendMessage('1298229107334844518', '<@&752767906768748586>'); } public function SlashCommand() diff --git a/app/Http/Controllers/Training/ApplicationsController.php b/app/Http/Controllers/Training/ApplicationsController.php index e7553e67..bff3c710 100644 --- a/app/Http/Controllers/Training/ApplicationsController.php +++ b/app/Http/Controllers/Training/ApplicationsController.php @@ -142,14 +142,15 @@ public function applyPost(Request $request) //Dispatch event // Notification::route('mail', CoreSettings::find(1)->emailfirchief)->notify(new NewApplicationStaff($application)); // Notification::route('mail', CoreSettings::find(1)->emaildepfirchief)->notify(new NewApplicationStaff($application)); - Notification::route('mail', CoreSettings::find(1)->emailcinstructor)->notify(new NewApplicationStaff($application)); + // Notification::route('mail', CoreSettings::find(1)->emailcinstructor)->notify(new NewApplicationStaff($application)); //New Applicant in Instructor Channel $discord = new DiscordClient(); - $discord->sendMessageWithEmbed(config('app.env') == 'local' ? intval(config('services.discord.web_logs')) : intval(config('services.discord.applications')), 'New Training Applicant!', $application->user->fullName('FLC').' has just applied to control at Gander Oceanic! - -[View their application now](https://ganderoceanic.ca/admin/training/applications/'.$application->reference_id.')'); + $discord_message_id = $discord->ControllerEndorsementApplication($application->user->fullName('FLC'), $application->applicant_statement, $application->reference_id); + + $application->discord_message_id = $discord_message_id; + $application->save(); //Redirect to application page return redirect()->route('training.applications.show', $application->reference_id); @@ -232,6 +233,10 @@ public function withdraw(Request $request) Notification::route('mail', CoreSettings::find(1)->emailfirchief)->notify(new ApplicationWithdrawnStaff($application)); Notification::route('mail', CoreSettings::find(1)->emaildepfirchief)->notify(new ApplicationWithdrawnStaff($application)); + //Discord - User withdrew application + $discord = new DiscordClient(); + $discord->ControllerEndorsementResponse($application->user->fullName('FLC'), auth()->user()->fullName('FLC'), $application->discord_message_id, $application->reference_id, 'withdrawn'); + //Return $request->session()->flash('alreadyApplied', 'Application withdrawn.'); @@ -443,9 +448,6 @@ public function adminAcceptApplication($reference_id, Request $request) //Create Instructor Thread $discord->createTrainingThread($student->user->fullName('FLC'), '<@'.$student->user->discord_user_id.'>'); - - // Notify Senior Team that the application was accepted. - $discord->sendMessageWithEmbed(config('app.env') == 'local' ? intval(config('services.discord.web_logs')) : intval(config('services.discord.applications')), 'Accepted Applicant', $student->user->fullName('FLC').' has just been accepted.', 'error'); } else { Session::flash('info', 'Unable to add Discord permissions automatically, as the member is not in the Discord.'); @@ -474,6 +476,10 @@ public function adminAcceptApplication($reference_id, Request $request) //Notify staff //Notification::route('mail', CoreSettings::find(1)->emailcinstructor)->notify(new ApplicationAcceptedStaff($application)); + //Discord - User withdrew application + $discord = new DiscordClient(); + $discord->ControllerEndorsementResponse($application->user->fullName('FLC'), auth()->user()->fullName('FLC'), $application->discord_message_id, $application->reference_id, 'accepted'); + //Return $request->session()->flash('alreadyApplied', 'Accepted!'); @@ -498,11 +504,9 @@ public function adminRejectApplication($reference_id, Request $request) ]); $update->save(); - // Notify Senior Team that new Applicant has been rejected. - $discord->sendMessageWithEmbed(config('app.env') == 'local' ? intval(config('services.discord.web_logs')) : intval(config('services.discord.applications')), 'Application Denied', $student->user->fullName('FLC')."'s application has been denied.", 'error'); - - //Notify user - $application->user->notify(new ApplicationRejectedApplicant($application)); + //Discord - User withdrew application + $discord = new DiscordClient(); + $discord->ControllerEndorsementResponse($application->user->fullName('FLC'), auth()->user()->fullName('FLC'), $application->discord_message_id, $application->reference_id, 'rejected'); //Return $request->session()->flash('alreadyApplied', 'Rejected'); diff --git a/app/Services/DiscordClient.php b/app/Services/DiscordClient.php index 513f4450..5b15e20f 100644 --- a/app/Services/DiscordClient.php +++ b/app/Services/DiscordClient.php @@ -74,7 +74,7 @@ public function sendMessageWithEmbed($channelId, $title, $description) ] ]); - return $response->getStatusCode() == 200; + return $response; } public function ControllerConnection($callsign, $name) @@ -124,6 +124,87 @@ public function ControllerDisconnect($id, $callsign, $name, $connect_time, $tota return $responseData; } + // New Controller Application - Message to Senior Leadership + public function ControllerEndorsementApplication($name, $statement, $refId) + { + $response = $this->client->post("channels/".env('DISCORD_APPLICATIONS')."/messages", [ + 'json' => [ + "tts" => false, + "embeds" => [ + [ + 'title' => 'New Controller Application', + 'description' => +$name. ' has just applied to join Gander Oceanic! + +**__Applicant Statement:__** +```'.$statement.'``` + +[View their application](https://ganderoceanic.ca/admin/training/applications/'.$refId.')', + 'color' => hexdec('0080C9'), + ] + ] + ] + ]); + + $response = json_decode($response->getBody(), true); + + return $response['id']; + + } + + public function ControllerEndorsementResponse($app_name, $auth_name, $messageId, $refId, $status) + { + // Student Withdraws Application + if($status == "withdrawn"){ + $response = $this->client->patch("channels/".env('DISCORD_APPLICATIONS')."/messages/".$messageId, [ + 'json' => [ + "tts" => false, + "embeds" => [ + [ + 'title' => 'Controller Application has been Withdrawn', + 'description' => $app_name. ' has withdrawn their application.', + 'color' => hexdec('7d7d7d'), + ] + ] + ] + ]); + } + + if($status == "accepted"){ + $response = $this->client->patch("channels/".env('DISCORD_APPLICATIONS')."/messages/".$messageId, [ + 'json' => [ + "tts" => false, + "embeds" => [ + [ + 'title' => 'Controller Application Accepted', + 'description' => $app_name. ' Application has been accepted by '.$auth_name.' + +[View the application](https://ganderoceanic.ca/admin/training/applications/'.$refId.')', + 'color' => hexdec('1ce335'), + ] + ] + ] + ]); + } + + if($status == "rejected"){ + $response = $this->client->patch("channels/".env('DISCORD_APPLICATIONS')."/messages/".$messageId, [ + 'json' => [ + "tts" => false, + "embeds" => [ + [ + 'title' => 'Controller Application Rejected', + 'description' => $app_name. ' Application has been rejected by '.$auth_name.' + +[View the application](https://ganderoceanic.ca/admin/training/applications/'.$refId.')', + 'color' => hexdec('dc3b23'), + ] + ] + ] + ]); + } + } + public function assignRole($discordId, $roleId) { sleep(1); diff --git a/database/migrations/2024_10_23_update_applications.php b/database/migrations/2024_10_23_update_applications.php new file mode 100644 index 00000000..b3e704d6 --- /dev/null +++ b/database/migrations/2024_10_23_update_applications.php @@ -0,0 +1,32 @@ +string('discord_message_id')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('applications', function (Blueprint $table) { + $table->dropColumn(['discord_message_id']); + }); + } +}; diff --git a/resources/views/training/applications/apply.blade.php b/resources/views/training/applications/apply.blade.php index 4ee5aeb4..bf154a69 100644 --- a/resources/views/training/applications/apply.blade.php +++ b/resources/views/training/applications/apply.blade.php @@ -67,7 +67,7 @@

Finish your application

-

By applying to Gander Oceanic you acknowledge the activity requirements for after you receive your endorsement. You will be required to control 6 hours each quarter. Failure to meet the requirement without justification may lead to the revokation of your endorsement.

+

By applying to Gander Oceanic you acknowledge the activity requirements for after you receive your endorsement. You will be required to control a minimum of 60 minutes per year. Failure to do so will result in the removal of your controller endorsement.

You also agree to comply with our General and Training policies.

@@ -129,24 +129,20 @@

If you believe there has been an error, please contact us so that we can investigate.

-

- View VATUK Shanwick roster    -

@break @case('discord') -
-

Discord Account Details Missing

+

{{Auth::user()->Fullname('F')}}, You are not in the Gander Oceanic Discord

- You must be a member of the Gander Oceanic Discord to begin your training. Once you do so, you will be able to apply. + Gander Oceanic Training is completed on the Gander Oceanic Discord. Our records indicate that you are not currently connected to our server.

- If you are already a member of the Discord, you need to relink your discord account so we have your information. + Please head to myCZQO to link your Discord Account, and join our Discord Server.

- Join Discord via myCZQO. + If you encounter any further issues once you have joined the discord, please reach out to Joshua Micallef - ZQO3 via Discord, who can investigate any issues.

diff --git a/routes/web.php b/routes/web.php index 98efbfc1..25e2b05c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -75,8 +75,8 @@ // Discord shortcut Route::get('/discord', [DiscordController::class, 'joinShortcut']); -Route::get('/discord/function-test', [DiscordTestController::class, 'Job']); -// Route::get('/discord/function-test2', [DiscordTestController::class, 'Job2']); +Route::get('/discord/function-test', [DiscordTestController::class, 'SendEmbed']); +Route::get('/discord/function-test2', [DiscordTestController::class, 'SendMessage']); Route::post('/discord/bot-webhook', [DiscordController::class, 'handelDiscordCommand']); // Public news articles