From 6c06f2e053901d1bebb653860a6dbe23edd77279 Mon Sep 17 00:00:00 2001 From: JoshuaMicallefYBSU <91457812+JoshuaMicallefYBSU@users.noreply.github.com> Date: Mon, 21 Oct 2024 02:56:47 +1000 Subject: [PATCH] Move Updates to server-log --- app/Console/Kernel.php | 41 +------ app/Jobs/DiscordAccountCheck.php | 8 +- app/Jobs/DiscordTrainingWeeklyUpdates.php | 2 +- app/Jobs/ProcessRosterInactivity.php | 2 +- app/Jobs/ProcessShanwickController.php | 4 +- app/Jobs/UpdateDiscordUserRoles.php | 126 ---------------------- 6 files changed, 10 insertions(+), 173 deletions(-) delete mode 100644 app/Jobs/UpdateDiscordUserRoles.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 698b5465..b9f33727 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -48,12 +48,6 @@ protected function schedule(Schedule $schedule) //Inactivity checks $schedule->job(new ProcessRosterInactivity())->daily(); - // Monthly Statistics Breakdown - $schedule->job(new ProcessMonthlyBreakdown())->monthlyOn(1, '00:01'); - - //Solo cert expiry warning - // $schedule->job(new ProcessSoloCertExpiryWarnings())->daily(); - // Shanwick Controller Roster Update $schedule->job(new ProcessShanwickController())->daily(); @@ -63,39 +57,8 @@ protected function schedule(Schedule $schedule) // Check Training Threads Status (Once per week) $schedule->job(new DiscordTrainingWeeklyUpdates())->weeklyOn(6, '00:01'); - //CRONS FOR INACTIVITY EMAILS 2 weeks - // $schedule->call(function () { - // //Loop through controllers - // $count = 0; - // foreach (RosterMember::all() as $rosterMember) { - // //Do they meet the requirements? - // if (!$rosterMember->meetsActivityRequirement()) { - // $count++; - // $rosterMember->user->notify(new TwoWeekInactivityReminder($rosterMember, 'n/a')); - // } - // } - - // //Tell Discord all about it - // $discord = new DiscordClient(); - // $discord->sendMessage(753086414811562014, 'Sent '.$count.' two-week warning inactivity emails'); - // })->cron('00 00 16 MAR,JUN,SEP,DEC *'); // 2 weeks before end of quarter - - // 1 week - // $schedule->call(function () { - // //Loop through controllers - // $count = 0; - // foreach (RosterMember::all() as $rosterMember) { - // //Do they meet the requirements? - // if (!$rosterMember->meetsActivityRequirement()) { - // $count++; - // $rosterMember->user->notify(new OneWeekInactivityReminder($rosterMember, 'n/a')); - // } - // } - - // //Tell Discord all about it - // $discord = new DiscordClient(); - // $discord->sendMessage(753086414811562014, 'Sent '.$count.' one-week warning inactivity emails'); - // })->cron('00 00 23 MAR,JUN,SEP,DEC *'); // 1 week before end of quarter*/ + // Monthly Statistics Breakdown + $schedule->job(new ProcessMonthlyBreakdown())->monthlyOn(1, '00:01'); } /** diff --git a/app/Jobs/DiscordAccountCheck.php b/app/Jobs/DiscordAccountCheck.php index 776519a0..0ad7fefb 100644 --- a/app/Jobs/DiscordAccountCheck.php +++ b/app/Jobs/DiscordAccountCheck.php @@ -23,7 +23,7 @@ class DiscordAccountCheck implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public $timeout = 5000; + public $timeout = 7200; /** * Execute the job. @@ -34,7 +34,7 @@ class DiscordAccountCheck implements ShouldQueue public function handle() { // Timeout length (seconds) - ini_set('max_execution_time', 5000); + ini_set('max_execution_time', 7200); // Script Start Time $start_time = Carbon::now(); @@ -73,7 +73,7 @@ public function handle() } // Add a Sleep Timer - Allows API to not block - sleep(2); + sleep(3); // Check if user is currently in Discord if (in_array($user->discord_user_id, $discord_uids)) { @@ -237,7 +237,7 @@ public function handle() $update_content .= "\n- Script Time: " . $start_time->diffForHumans($end_time, ['parts' => 2, 'short' => true, 'syntax' => Carbon::DIFF_ABSOLUTE]) . "."; - $discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'DAILY: Discord User Update', $update_content); + $discord->sendMessageWithEmbed(env('DISCORD_SERVER_LOGS'), 'DAILY: Discord User Update', $update_content); } } diff --git a/app/Jobs/DiscordTrainingWeeklyUpdates.php b/app/Jobs/DiscordTrainingWeeklyUpdates.php index 303d43ed..33e3571a 100644 --- a/app/Jobs/DiscordTrainingWeeklyUpdates.php +++ b/app/Jobs/DiscordTrainingWeeklyUpdates.php @@ -330,7 +330,7 @@ public function handle() } // Send Message - $discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'WEEKLY: Discord Training Thread Updates', $update_content); + $discord->sendMessageWithEmbed(env('DISCORD_SERVER_LOGS'), 'WEEKLY: Discord Training Thread Updates', $update_content); } } } diff --git a/app/Jobs/ProcessRosterInactivity.php b/app/Jobs/ProcessRosterInactivity.php index 20280a1b..a5141b6d 100644 --- a/app/Jobs/ProcessRosterInactivity.php +++ b/app/Jobs/ProcessRosterInactivity.php @@ -151,7 +151,7 @@ public function handle() // Send Web Notification if any changes have been made if($first_notice != 0 || $second_notice !== 0 || $third_notice !== 0 || $termination_notice !== 0){ $discord = new DiscordClient(); - $discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'AUTO: Roster Inactivity Update', + $discord->sendMessageWithEmbed(env('DISCORD_SERVER_LOGS'), 'AUTO: Roster Inactivity Update', 'The Following changes have occured to the Controller Roster 60 Days till Removed: '.$first_notice.' 30 Days till Removed: '.$second_notice.' diff --git a/app/Jobs/ProcessShanwickController.php b/app/Jobs/ProcessShanwickController.php index 4fc8bf72..3c7b0028 100644 --- a/app/Jobs/ProcessShanwickController.php +++ b/app/Jobs/ProcessShanwickController.php @@ -19,7 +19,7 @@ class ProcessShanwickController implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public $timeout = 300; + public $timeout = 600; /** * Create a new job instance. @@ -39,7 +39,7 @@ public function __construct() public function handle() { // Data to Start Off With - ini_set('max_execution_time', 300); + ini_set('max_execution_time', 600); // VATSIM Region List $vatsim_regions = [ diff --git a/app/Jobs/UpdateDiscordUserRoles.php b/app/Jobs/UpdateDiscordUserRoles.php deleted file mode 100644 index 5d24375c..00000000 --- a/app/Jobs/UpdateDiscordUserRoles.php +++ /dev/null @@ -1,126 +0,0 @@ - config('services.discord.token')]); - - //Counter of how many people were updated - $counter = 0; - - //Get all Discord linked users - foreach (User::where('discord_user_id', '!=', null)->cursor() as $user) { - //Test if they're on the server or a staff member - if (!$user->member_of_czqo || $user->staffProfile || $user->isBot()) { - //They're not.. continue on. - continue; - } - - //Get their current user, so we can compare changes - $guildMember = $discord->guild->getGuildMember([ - 'guild.id' => intval(config('services.discord.guild_id')), - 'user.id' => $user->discord_user_id, - ]); - - //let's find all the roles they could possibly have... - $rolesToAdd = []; - - //Here are all the role ids - $discordRoleIds = [ - 'guest' => 482835389640343562, - 'training' => 482824058141016075, - 'certified' => 482819739996127259, - 'supervisor' => 720502070683369563, - ]; - - //Roster? - if (!$user->rosterProfile) { - //Not on the roster, we can give them guest. - array_push($rolesToAdd, $discordRoleIds['guest']); - } else { - //What status do they have? - $rosterProfile = $user->rosterProfile; - switch ($rosterProfile->certification) { - case 'certified': - array_push($rolesToAdd, $discordRoleIds['certified']); - break; - case 'training': - array_push($rolesToAdd, $discordRoleIds['training']); - break; - default: - //Otherwise... - array_push($rolesToAdd, $discordRoleIds['guest']); - } - } - - //Supervisor? - if ($user->rating_short == 'SUP') { - array_push($rolesToAdd, $discordRoleIds['supervisor']); - } - - //Create the full arguments - $arguments = [ - 'guild.id' => intval(config('services.discord.guild_id')), - 'user.id' => $user->discord_user_id, - 'nick' => $user->fullName('FLC'), - 'roles' => $rolesToAdd, - ]; - - //Modify - $discord->guild->modifyGuildMember($arguments); - - //Notify them if roles/nickname were change - if ($user->fullName('FLC') != $guildMember->nick) { - $discord->channel->createMessage([ - 'channel.id' => intval($user->discord_dm_channel_id), - 'content' => 'Hi there! Your nickname on the Gander Oceanic Discord has been updated from "' . $guildMember->nick . '" to "' . $user->fullName('FLC') . '" as per your website nickname settings. If this is a mistake, please contact the Web Team.' - ]); - } - - if ($rolesToAdd !== $guildMember->roles) { - $discord->channel->createMessage([ - 'channel.id' => intval($user->discord_dm_channel_id), - 'content' => 'Hi there! Your roles on the Gander Oceanic Discord have been updated in line with your roster status. If there is a mistake, please contact the Web Team.' - ]); - } - - //Counter! - $counter++; - } - - //Tell the log chat - $discord->channel->createMessage(['channel.id' => 482860026831175690, 'content' => $counter.' users were updated automatically.']); - } -}