diff --git a/app/Jobs/DiscordAccountCheck.php b/app/Jobs/DiscordAccountCheck.php index 07a52e37..b0351fda 100644 --- a/app/Jobs/DiscordAccountCheck.php +++ b/app/Jobs/DiscordAccountCheck.php @@ -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'])) { diff --git a/app/Jobs/ProcessRosterInactivity.php b/app/Jobs/ProcessRosterInactivity.php index b882495e..6df753fa 100644 --- a/app/Jobs/ProcessRosterInactivity.php +++ b/app/Jobs/ProcessRosterInactivity.php @@ -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++; @@ -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++; @@ -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++; diff --git a/app/Jobs/ProcessSessionLogging.php b/app/Jobs/ProcessSessionLogging.php index c0fc1b50..9b0eafd4 100644 --- a/app/Jobs/ProcessSessionLogging.php +++ b/app/Jobs/ProcessSessionLogging.php @@ -74,10 +74,10 @@ 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; @@ -85,41 +85,30 @@ public function handle() $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 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 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.**'); } } @@ -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 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(); } + } } } }