From d013d37f45f57dd2a0ecbfcb4b5cc0d43ccb9df7 Mon Sep 17 00:00:00 2001 From: JoshuaMicallefYBSU <91457812+JoshuaMicallefYBSU@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:16:20 +1000 Subject: [PATCH] Further Updates --- app/Console/Kernel.php | 2 +- app/Jobs/ProcessRosterInactivity.php | 18 +++++++++--------- app/Services/DiscordClient.php | 28 +++++++++++++++++----------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7f4ff3e8..c0fc381d 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -42,7 +42,7 @@ protected function schedule(Schedule $schedule) $schedule->job(new ProcessSessionLogging())->everyMinute(); //Inactivity checks - $schedule->job(new ProcessRosterInactivity())->dailyAt('8:05'); + $schedule->job(new ProcessRosterInactivity())->dailyAt('8:20'); //CRONS FOR INACTIVITY EMAILS 2 weeks // $schedule->call(function () { diff --git a/app/Jobs/ProcessRosterInactivity.php b/app/Jobs/ProcessRosterInactivity.php index 1288f324..2c45ce96 100644 --- a/app/Jobs/ProcessRosterInactivity.php +++ b/app/Jobs/ProcessRosterInactivity.php @@ -139,14 +139,14 @@ public function handle() $termination_notice++; } } - - // Send Web Notification if any changes have been made - $discord = new DiscordClient(); - $discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'AUTO: Roster Inactivity Update', -'60 Days till Removed: '.$first_notice.' -30 Days till Removed: '.$second_notice.' -7 Days till Removed: '.$third_notice.' -Removed from Roster: '.$termination_notice -); } + + // Send Web Notification if any changes have been made + $discord = new DiscordClient(); + $discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'AUTO: Roster Inactivity Update', + '60 Days till Removed: '.$first_notice.' + 30 Days till Removed: '.$second_notice.' + 7 Days till Removed: '.$third_notice.' + Removed from Roster: '.$termination_notice + ); }} diff --git a/app/Services/DiscordClient.php b/app/Services/DiscordClient.php index 3d3cff6e..513f4450 100644 --- a/app/Services/DiscordClient.php +++ b/app/Services/DiscordClient.php @@ -40,17 +40,23 @@ public function sendMessage($channelId, $message) public function sendDM($userId, $title, $message) { - $response = $this->client->post("https://discord.com/api/v10/users/@me/channels", [ - 'json' => [ - 'recipient_id' => $userId, // Replace $userId with the Discord user ID - ], - ]); - - $channel = json_decode($response->getBody(), true); - $channelId = $channel['id']; - - // Step 2: Send the Message to the DM Channel - $this->sendMessageWithEmbed($channelId, $title, $message); + try{ + + $response = $this->client->post("https://discord.com/api/v10/users/@me/channels", [ + 'json' => [ + 'recipient_id' => $userId, // Replace $userId with the Discord user ID + ], + ]); + + $channel = json_decode($response->getBody(), true); + $channelId = $channel['id']; + + // Step 2: Send the Message to the DM Channel + $this->sendMessageWithEmbed($channelId, $title, $message); + + } catch (GuzzleHttp\Exception\ClientException $e) { + + } } public function sendMessageWithEmbed($channelId, $title, $description)