Skip to content

Commit

Permalink
Merge pull request #323 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
SessionNotification Updates & Shanwick Controller Fixups
  • Loading branch information
JoshuaMicallefYBSU authored Aug 21, 2024
2 parents 4d035ba + 0c92f8c commit 41120b0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 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())->daily();
$schedule->job(new ProcessShanwickController())->dailyAt('07:05');

//Training/OTS session reminders
$schedule->job(new ProcessSessionReminders())->daily();
Expand Down
49 changes: 38 additions & 11 deletions app/Jobs/ProcessSessionLogging.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Network\MonitoredPosition;
use App\Models\Network\SessionLog;
use App\Models\Network\ShanwickController;
use App\Models\Roster\RosterMember;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
Expand Down Expand Up @@ -44,6 +45,10 @@ public function handle()

$vatsimData = new VATSIMClient();

$czqoRoster = RosterMember::all()->pluck('user_id')->toArray();
$eggxRoster = ShanwickController::all()->pluck('controller_cid')->toArray();
$allRoster = array_unique(array_merge($czqoRoster, $eggxRoster));

$positionsFound = [];

//Go through each position and process sessions for each of them
Expand All @@ -64,23 +69,45 @@ public function handle()
]);

if($session->user){
$name = $session->user->fullName('FL');
$name = $session->user->fullName('FLC');
} else {
$name = $controller->cid;
}

if($session->discord_id == null){
try{
$discord = new DiscordClient();
$discord_id = $discord->ControllerConnection($controller->callsign, $name);
// 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){
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());
$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());
}
}
} 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.**');

// 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());
}
}
}
}

array_push($positionsFound, $controller->callsign);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ProcessShanwickController.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function handle()

// Create a Request for the Shanwick Controllers
$client = new Client(['timeout' => 1000]);
$response = $client->request('GET', 'https://www.vatsim.uk/api/validations?position=EGGX_FSS');
$response = $client->request('GET', "https://www.vatsim.uk/api/validations?position=EGGX_FSS");
$data = json_decode($response->getBody(), true);
$data_json = $data['validated_members'];

Expand Down

0 comments on commit 41120b0

Please sign in to comment.