Skip to content

Commit

Permalink
Merge pull request #325 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
Many Small Updates
  • Loading branch information
JoshuaMicallefYBSU authored Aug 22, 2024
2 parents 060060c + bc4208c commit 0dda15c
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function schedule(Schedule $schedule)
$schedule->job(new ProcessSoloCertExpiryWarnings())->daily();

// Shanwick Controller Roster Update
$schedule->job(new ProcessShanwickController())->dailyAt('08:35');
$schedule->job(new ProcessShanwickController())->daily();

//Training/OTS session reminders
$schedule->job(new ProcessSessionReminders())->daily();
Expand Down
15 changes: 15 additions & 0 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions app/Http/Controllers/Training/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public function apply(Request $request)
return view('training.applications.apply')->with('allowed', 'rating');
}

if(auth()->user()->member_of_czqo == 0){

return view('training.applications.apply')->with('allowed', 'discord');
}

//Check hours of controller
//Download via CURL
$url = 'https://api.vatsim.net/v2/members/'.auth()->id().'/stats';
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/DiscordTrainingWeeklyUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function handle()
$avail_message++;

// // SendEmbed to ask student to send availability
$discord->sendEmbedInTrainingThread($cid, "Please Provide Availability", 'Hello,
$discord->sendEmbedInTrainingThread($cid, "Please Provide Availability", 'Hello, <@'.$student->discord_id.'>
As we head into the Weekend, we ask you please provide your availability for next week. Please ensure to tag the `@Instructor` role with all times you are available. Please provide these times in Zulu Format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 32 additions & 6 deletions app/Services/DiscordClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions resources/views/roster/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
</div>
<div class="container py-4">
<p class="text-muted">Please note that the 'full name' field on this roster is dependent on the controller's name settings on the CZQO Core system.<br></p>
<p class="text-muted">This Roster shows the combined endorsements of Shanwick and Gander controllers.<br><i class="fas fa-certificate"></i> = Certified frm Shanwick FIR</p>
<p class="text-muted">Controllers with active status are endorsed to open & control: CZQX_CTR, EGGX_CTR and/or NAT_FSS<br></p>
<p class="text-muted">This Roster shows the combined endorsements of Shanwick and Gander controllers.<br><i class="fas fa-certificate"></i> = Certified by VATSIM UK</p>
<p class="text-muted">Controllers with active status are endorsed to open & control either CZQO, EGGX and/or NAT_FSS positions.<br></p>
<table id="rosterTable" class="table table-hover">
<thead>
<tr>
Expand Down
17 changes: 17 additions & 0 deletions resources/views/training/applications/apply.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@
</div>
@break

@case('discord')

<div class="container py-4">
<h1 class="font-weight-bold red-text">You are not a member of 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.
</p>
<p style="font-size: 1.2em;" class="mt-3">
<a href="{{route('my.index')}}">Join Discord via myCZQO.</a>
</p>
<p style="font-size: 1.2em;" class="mt-3">
If you beleive this is a mistake, please make contact with the Senior Leadership Team.
</p>
</div>

@break

@endswitch

@endsection
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]+');
Expand Down

0 comments on commit 0dda15c

Please sign in to comment.