Skip to content

Commit 6d79260

Browse files
Merge pull request #413 from czqoocavatsim/JoshuaBranch
Some Fixes
2 parents baf882c + 2ddf6e8 commit 6d79260

File tree

3 files changed

+38
-42
lines changed

3 files changed

+38
-42
lines changed

app/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function schedule(Schedule $schedule)
4646
$schedule->job(new ProcessShanwickControllers())->cron('0 * * * *'); //Updated Hourly
4747

4848
//Discord Update
49-
$schedule->job(new DiscordAccountCheck())->dailyAt('02:00');
49+
$schedule->job(new DiscordAccountCheck())->everyHour();
5050

5151
//Roster Inactivity checks
5252
$schedule->job(new ProcessRosterInactivity())->dailyAt('23:55');

app/Jobs/ProcessSessionLogging.php

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -144,52 +144,48 @@ public function handle()
144144
$name = $log->cid;
145145
}
146146

147-
// Discord ID is not null (message has not yet been sent)
148-
if($log->discord_id !== null){
149-
// Update Disconnect Message
150-
try{
151-
$discord = new DiscordClient();
152-
$data = $discord->ControllerDisconnect($log->discord_id, $log->callsign, $name, $log->session_start, $log->duration);
153-
} catch (\Exception $e) {
154-
$discord = new DiscordClient();
155-
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'Discord Controller Disconnect Error', $e->getMessage());
156-
}
157-
158-
// Remove Discord Role
159-
if($log->user && $log->user->hasDiscord() && $log->user->member_of_czqo){
160-
$discord = new DiscordClient();
161-
162-
$discord->removeRole($log->user->discord_user_id, '1278868454606377040');
163-
}
164-
}
165-
166-
$log->discord_id = null;
167-
$log->save;
168-
169-
//If there is an associated roster member, give them the hours and set as active
170-
if ($rosterMember = $log->rosterMember) {
171-
172-
// Set variables
173-
$currency = $log->session_start->floatDiffInMinutes(Carbon::now()) / 60;
174-
$monthly_hours = $log->session_start->floatDiffInMinutes(Carbon::now()) / 60;
147+
// Check if Controller is Authorised to open a position (training/certified)
148+
if (in_array($session->cid, $allRoster)) {
149+
// Controller is authorised, send message if discord_id is not set
150+
if($session->discord_id == null){
151+
// Discord Message
152+
try{
153+
$discord = new DiscordClient();
154+
$discord_id = $discord->ControllerConnection($controller->callsign, $name);
155+
156+
$session->discord_id = $discord_id;
157+
$session->save();
158+
} catch (\Exception $e) {
159+
$discord = new DiscordClient();
160+
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'Discord Controller Connect Error', $e->getMessage());
161+
}
175162

176-
// Controller is either Certified or In Training
177-
if (($rosterMember->certification == 'certified' || $rosterMember->certification == 'training')) {
163+
// Add Discord Role
164+
if($session->user && $session->user->hasDiscord() && $session->user->member_of_czqo){
165+
$discord = new DiscordClient();
178166

179-
// Only add hours if more than 30mins (Disabled to 01mins until policy update)
180-
if($currency > 0.00){
181-
$rosterMember->currency += $currency;
182-
$rosterMember->monthly_hours += $monthly_hours;
183-
$rosterMember->save();
167+
$discord->assignRole($session->user->discord_user_id, '1278868454606377040');
168+
}
184169
}
170+
} else {
171+
// Controller is not authorised. Let Senior Team know.
172+
if($session->discord_id == null){
173+
try{
174+
// Send Discord Message
175+
$discord = new DiscordClient();
176+
$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>.
177+
178+
**They are not authorised to open this position.**');
185179

186-
// Set user as active if more than 1 hour
187-
if($rosterMember->currency > 0.99){
188-
$rosterMember->active = 1;
189-
$rosterMember->save();
180+
// Save ID so it doesnt keep spamming
181+
$session->discord_id = $discord_id;
182+
$session->save();
183+
} catch (\Exception $e) {
184+
$discord = new DiscordClient();
185+
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'Unauthorised Controller Notification Error', $e->getMessage());
186+
}
190187
}
191188
}
192-
}
193189
}
194190
}
195191
}

app/Jobs/ProcessShanwickControllers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public function handle()
302302
}
303303
}
304304

305-
dd($get_vatsim_data);
305+
// dd($get_vatsim_data);
306306
// dd($use_gander_data);
307307

308308
// Get Current Shanwick Details

0 commit comments

Comments
 (0)