Skip to content

Commit

Permalink
Merge pull request #390 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
ControllerApplication - Discord Announcement Update
  • Loading branch information
JoshuaMicallefYBSU authored Oct 23, 2024
2 parents 3be727b + b30edb5 commit 83d6852
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 33 deletions.
18 changes: 9 additions & 9 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
28 changes: 16 additions & 12 deletions app/Http/Controllers/Training/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.');

Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -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!');

Expand All @@ -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');
Expand Down
83 changes: 82 additions & 1 deletion app/Services/DiscordClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function sendMessageWithEmbed($channelId, $title, $description)
]
]);

return $response->getStatusCode() == 200;
return $response;
}

public function ControllerConnection($callsign, $name)
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions database/migrations/2024_10_23_update_applications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('applications', function (Blueprint $table) {
$table->string('discord_message_id')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('applications', function (Blueprint $table) {
$table->dropColumn(['discord_message_id']);
});
}
};
14 changes: 5 additions & 9 deletions resources/views/training/applications/apply.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</div>
<h4 class="blue-text mt-4 mb-3">Finish your application</h4>
<div class="list-group-item p-4 z-depth-1">
<p>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.</p>
<p>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.</p>
<p>You also agree to comply with our General and Training policies.</p>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" required name="agreeActivity" id="agreeActivity">
Expand Down Expand Up @@ -129,24 +129,20 @@
<p style="font-size: 1.2em;" class="mt-3">
If you believe there has been an error, please contact us so that we can investigate.
</p>
<p style="font-size: 1.2em;" class="mt-3">
<a class="font-weight-bold text-body" href="https://cts.vatsim.uk/home/validations.php?view=16">View VATUK Shanwick roster &nbsp;&nbsp;<i class="fas fa-arrow-right blue-text"></i></a>
</p>
</div>
@break

@case('discord')

<div class="container py-4">
<h1 class="font-weight-bold red-text">Discord Account Details Missing</h1>
<h1 class="font-weight-bold red-text">{{Auth::user()->Fullname('F')}}, You are not in the Gander Oceanic Discord</h1>
<p style="font-size: 1.2em;" class="mt-3">
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.
</p>
<p style="font-size: 1.2em;" class="mt-3">
If you are already a member of the Discord, you need to relink your discord account so we have your information.
Please head to <a href="{{route('my.index')}}">myCZQO</a> to link your Discord Account, and join our Discord Server.
</p>
<p style="font-size: 1.2em;" class="mt-3">
<a href="{{route('my.index')}}">Join Discord via myCZQO.</a>
If you encounter any further issues once you have joined the discord, please reach out to <b>Joshua Micallef - ZQO3</b> via Discord, who can investigate any issues.
</p>
</div>

Expand Down
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83d6852

Please sign in to comment.