Skip to content

Commit

Permalink
JobsUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMicallefYBSU committed Dec 1, 2024
1 parent 35dde33 commit a5e282e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 65 deletions.
3 changes: 2 additions & 1 deletion app/Jobs/DiscordAccountCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public function handle()
634656628335050762, //Shanwick Team
497351197280174080, //VATCAN Divisional Staff
497359834010615809, //VATSIM Senior Staff
1300054143532138516]; //VATSYS Beta Tester
1300054143532138516, //VATSYS Beta Tester
1278868454606377040]; //Currently Online

foreach ($roleIdsToCheck as $roleId) {
if (in_array($roleId, $discord_member['roles'])) {
Expand Down
6 changes: 3 additions & 3 deletions app/Jobs/ProcessRosterInactivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function handle()
if($roster->certification == "certified" && $roster->active && Carbon::now()->format('d/m') == "01/11" && $roster->currency < 1) {
$active_status = 0;

$first_names[] = $name ."(". $roster->currency ." hrs)";
$first_names[] = $name ." (". $roster->currency ." hrs)";

$first_notice++;

Expand All @@ -109,7 +109,7 @@ public function handle()
if($roster->certification == "certified" && Carbon::now()->format('d/m') == "01/12" && $roster->currency < 1){
$active_status = 0;

$second_names[] = $name ."(". $roster->currency ." hrs)";
$second_names[] = $name ." (". $roster->currency ." hrs)";

$second_notice++;

Expand All @@ -120,7 +120,7 @@ public function handle()
if($roster->certification == "certified" && Carbon::now()->format('d/m') == "24/12" && $roster->currency < 1){
$active_status = 0;

$third_names[] = $name ."(". $roster->currency ." hrs)";
$third_names[] = $name ." (". $roster->currency ." hrs)";

$third_notice++;

Expand Down
94 changes: 33 additions & 61 deletions app/Jobs/ProcessSessionLogging.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,52 +74,41 @@ public function handle()
$name = $controller->cid;
}

//Check if Controller is Authorised to open a position (training/certified)
// Check if Controller is Authorised to open a position (training/certified)
if (in_array($session->cid, $allRoster)) {
// Controller is authorised, send message if discord_id is not set
if($session->discord_id == null ){
if($session->discord_id == null){
// Discord Message
try{
$session->discord_id = $discord_id;
$session->save();

$discord = new DiscordClient();
$discord_id = $discord->ControllerConnection($controller->callsign, $name);

} catch (\Exception $e) {
$session->discord_id = 0;
$session->save();

$discord = new DiscordClient();
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'Discord Controller Connect Error', $e->getMessage());
}

// Add Discord Role
if($session->user && $session->user->hasDiscord() && $session->user->member_of_czqo){
if($log->user && $log->user->hasDiscord() && $log->user->member_of_czqo){
$discord = new DiscordClient();

$discord->assignRole($session->user->discord_user_id, '1278868454606377040');
$discord->assignRole($log->user->discord_user_id, '1278868454606377040');
}
}
} else {
// Controller is not authorised. Let Senior Team know.
if($session->discord_id == null || $session->discord_id !== 0){
try{
// Save ID so it doesnt keep spamming
$session->discord_id = $discord_id;
$session->save();
if($session->discord_id == null){
// Save ID so it doesnt keep spamming
$session->discord_id = $discord_id;
$session->save();

// Send Discord Message
$discord = new DiscordClient();
$discord_id = $discord->sendMessageWithEmbed('482817715489341441', 'Unauthorised Controller Connection', $session->cid.' has just connected onto VATSIM as '.$session->callsign.' on <t:'.Carbon::now()->timestamp.':F> (local time).
// Send Discord Message
$discord = new DiscordClient();
$discord_id = $discord->sendMessageWithEmbed('482817715489341441', 'Controller Unauthorised to Control', '<@&482816721280040964>, '.$session->cid.' has just connected onto VATSIM as '.$session->callsign.' on <t:'.Carbon::now()->timestamp.':F>.
**This controller does not appear on our Roster. This means that:**
- They are not authorised to control; or,
- The student is currently undergoing training with another division.');
} catch (\Exception $e) {
$discord = new DiscordClient();
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'Unauthorised Controller Notification Error', $e->getMessage());
}
**They are not authorised to open this position.**');
}
}

Expand All @@ -144,48 +133,31 @@ public function handle()
$name = $log->cid;
}

// Check if Controller is Authorised to open a position (training/certified)
if (in_array($session->cid, $allRoster)) {
// Controller is authorised, send message if discord_id is not set
if($session->discord_id == null){
// Discord Message
try{
$discord = new DiscordClient();
$discord_id = $discord->ControllerConnection($controller->callsign, $name);

$session->discord_id = $discord_id;
$session->save();
} catch (\Exception $e) {
$discord = new DiscordClient();
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'Discord Controller Connect Error', $e->getMessage());
}
// Discord ID is not null (message has not yet been sent)
if($log->discord_id !== null){
// Update Disconnect Message
$discord = new DiscordClient();
$data = $discord->ControllerDisconnect($log->discord_id, $log->callsign, $name, $log->session_start, $log->duration);

// Add Discord Role
if($session->user && $session->user->hasDiscord() && $session->user->member_of_czqo){
$discord = new DiscordClient();
// Remove Discord Role
if($log->user && $log->user->hasDiscord() && $log->user->member_of_czqo){
$discord = new DiscordClient();

$discord->assignRole($session->user->discord_user_id, '1278868454606377040');
}
}
} else {
// Controller is not authorised. Let Senior Team know.
if($session->discord_id == null){
try{
// Send Discord Message
$discord = new DiscordClient();
$discord_id = $discord->sendMessageWithEmbed('482817715489341441', 'Controller Unauthorised to Control', '<@&482816721280040964>, '.$session->cid.' has just connected onto VATSIM as '.$session->callsign.' on <t:'.Carbon::now()->timestamp.':F>.
**They are not authorised to open this position.**');
$discord->removeRole($log->user->discord_user_id, '1278868454606377040');
}
}

// Save ID so it doesnt keep spamming
$session->discord_id = $discord_id;
$session->save();
} catch (\Exception $e) {
$discord = new DiscordClient();
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'Unauthorised Controller Notification Error', $e->getMessage());
}
}
$log->discord_id = null;
$log->save;

//If there is an associated roster member, give them the hours and set as active
if ($rosterMember = $log->rosterMember) {
if (($rosterMember->certification == 'certified' || $rosterMember->certification == 'training')) {
$rosterMember->currency += $log->session_start->floatDiffInMinutes(Carbon::now()) / 60;
$rosterMember->monthly_hours += $log->session_start->floatDiffInMinutes(Carbon::now()) / 60;
$rosterMember->save();
}
}
}
}
}
Expand Down

0 comments on commit a5e282e

Please sign in to comment.