From 2ddf6e860c4d4229b436997a7773b4073438f7eb Mon Sep 17 00:00:00 2001 From: JoshuaMicallefYBSU Date: Fri, 22 Nov 2024 00:52:55 +1000 Subject: [PATCH] Some Fixes --- app/Console/Kernel.php | 2 +- app/Jobs/ProcessSessionLogging.php | 76 ++++++++++++------------- app/Jobs/ProcessShanwickControllers.php | 2 +- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index e016df96..093932d5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -46,7 +46,7 @@ protected function schedule(Schedule $schedule) $schedule->job(new ProcessShanwickControllers())->cron('0 * * * *'); //Updated Hourly //Discord Update - $schedule->job(new DiscordAccountCheck())->dailyAt('02:00'); + $schedule->job(new DiscordAccountCheck())->everyHour(); //Roster Inactivity checks $schedule->job(new ProcessRosterInactivity())->dailyAt('23:55'); diff --git a/app/Jobs/ProcessSessionLogging.php b/app/Jobs/ProcessSessionLogging.php index 61c97737..c0fc1b50 100644 --- a/app/Jobs/ProcessSessionLogging.php +++ b/app/Jobs/ProcessSessionLogging.php @@ -144,52 +144,48 @@ public function handle() $name = $log->cid; } - // Discord ID is not null (message has not yet been sent) - if($log->discord_id !== null){ - // Update Disconnect Message - try{ - $discord = new DiscordClient(); - $data = $discord->ControllerDisconnect($log->discord_id, $log->callsign, $name, $log->session_start, $log->duration); - } catch (\Exception $e) { - $discord = new DiscordClient(); - $discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'Discord Controller Disconnect Error', $e->getMessage()); - } - - // Remove Discord Role - if($log->user && $log->user->hasDiscord() && $log->user->member_of_czqo){ - $discord = new DiscordClient(); - - $discord->removeRole($log->user->discord_user_id, '1278868454606377040'); - } - } - - $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) { - - // Set variables - $currency = $log->session_start->floatDiffInMinutes(Carbon::now()) / 60; - $monthly_hours = $log->session_start->floatDiffInMinutes(Carbon::now()) / 60; + // 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()); + } - // Controller is either Certified or In Training - if (($rosterMember->certification == 'certified' || $rosterMember->certification == 'training')) { + // Add Discord Role + if($session->user && $session->user->hasDiscord() && $session->user->member_of_czqo){ + $discord = new DiscordClient(); - // Only add hours if more than 30mins (Disabled to 01mins until policy update) - if($currency > 0.00){ - $rosterMember->currency += $currency; - $rosterMember->monthly_hours += $monthly_hours; - $rosterMember->save(); + $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.**'); - // Set user as active if more than 1 hour - if($rosterMember->currency > 0.99){ - $rosterMember->active = 1; - $rosterMember->save(); + // 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()); + } } } - } } } } diff --git a/app/Jobs/ProcessShanwickControllers.php b/app/Jobs/ProcessShanwickControllers.php index 726cf24c..924f9bc5 100644 --- a/app/Jobs/ProcessShanwickControllers.php +++ b/app/Jobs/ProcessShanwickControllers.php @@ -302,7 +302,7 @@ public function handle() } } - dd($get_vatsim_data); + // dd($get_vatsim_data); // dd($use_gander_data); // Get Current Shanwick Details