Skip to content

Commit

Permalink
Merge pull request #271 from czqoocavatsim/JoshuaMicallefYBSU-patch-2
Browse files Browse the repository at this point in the history
Discord Thread Creation & Application Notification
  • Loading branch information
JoshuaMicallefYBSU authored Aug 14, 2024
2 parents 62b0d6b + 3fb822d commit 1d6c236
Show file tree
Hide file tree
Showing 8 changed files with 908 additions and 856 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ app/Http/Controllers/vendor/skymeyer/vatsimphp/app/logs/pilots.log
.idea/
.DS_Store
training.yaml
composer.lock
16 changes: 16 additions & 0 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Services\DiscordClient;

class DiscordTestController extends Controller
{
public function ThreadTest()
{
//New Applicant in Instructor Channel
$discord = new DiscordClient();
$discord->createTrainingThread('1273181022699130902', 'Joshua Micallef 1342084', '<@200426385863344129>');
}
}
24 changes: 20 additions & 4 deletions app/Http/Controllers/Training/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ public function applyPost(Request $request)
// Notification::route('mail', CoreSettings::find(1)->emaildepfirchief)->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.')');

//Redirect to application page
return redirect()->route('training.applications.show', $application->reference_id);
}
Expand Down Expand Up @@ -390,7 +397,7 @@ public function adminAcceptApplication($reference_id, Request $request)
$application->status = 1;
$application->save();

//Create update
// Create update
$update = new ApplicationUpdate([
'application_id' => $application->id,
'update_title' => 'Your application has been accepted!',
Expand Down Expand Up @@ -427,15 +434,24 @@ public function adminAcceptApplication($reference_id, Request $request)
//Give role
$student->user->assignRole('Student');

//Give Discord role
//Discord Updates
if ($student->user->hasDiscord() && $student->user->member_of_czqo) {
//Get Discord client
$discord = new DiscordClient();

//Add student role
//Add student discord role
$discord->assignRole($student->user->discord_user_id, 482824058141016075);

//Create Instructor Thread
$discord->createTrainingThread('1273181022699130902', $student->user->fullName('FLC'), '<@'.$student->user->discord_user_id.'>');
} else {
Session::flash('info', 'Unable to add Discord permissions automatically.');
Session::flash('info', 'Unable to add Discord permissions automatically, as the member is not in the Discord.');

//Get Discord client
$discord = new DiscordClient();

// Notify Senior Team that new Applicant is not a member of the Discord Server
$discord->sendMessageWithEmbed(config('app.env') == 'local' ? intval(config('services.discord.web_logs')) : intval(config('services.discord.applications')), 'Accepted applicant not in the discord', $student->user->fullName('FLC').' is not a member of Gander Oceanic. They will need to be contacted via email.', 'error');
}

//Status label
Expand Down
34 changes: 34 additions & 0 deletions app/Services/DiscordClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,39 @@ public function changeName($userId, $name)
}

}

// Function to create a user training thread
public function createTrainingThread($channelId, $name, $user)
{
try {
$response = $this->client->post("channels/{$channelId}/threads", [
'json' => [
'name' => $name,
'applied_tags' => [1271845980865695774], //Tag ID for 'New Request'
'message' => [
'content' => $user.', your application has now been approved. Welcome to Gander Oceanic!
Please review <#1214345937871179777> in order to get yourself up to speed with our training process. It is pretty easy, but there are a few steps you *must* do in order to begin your training.
Once you have done so, and you are ready to attempt the exam, please ping `@exam-request` to have the Oceanic Exam assigned. You will only have 48 Hours to complete this exam, so please make sure you are ready.
After you pass the exam, please provide 7-days of availability for our Instructors.
Good luck with your study!',
],
],

]);


$responseData = json_decode($response->getBody(), true);
// Process $responseData as needed
} catch (\Exception $e) {
// Handle exception
echo 'Error: ' . $e->getMessage();
}

}

}

Loading

0 comments on commit 1d6c236

Please sign in to comment.