Skip to content

Commit

Permalink
Merge pull request #360 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
Hopeful fix
  • Loading branch information
JoshuaMicallefYBSU authored Oct 20, 2024
2 parents 45454a1 + b8cd21f commit 51b90a1
Show file tree
Hide file tree
Showing 2 changed files with 18 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 @@ -43,7 +43,7 @@ protected function schedule(Schedule $schedule)
$schedule->job(new ProcessSessionLogging())->everyMinute();

//Inactivity checks
$schedule->job(new DiscordAccountCheck())->dailyAt('6:40');
$schedule->job(new DiscordAccountCheck())->dailyAt('10:30');

//Inactivity checks
$schedule->job(new ProcessRosterInactivity())->daily();
Expand Down
29 changes: 17 additions & 12 deletions app/Jobs/DiscordAccountCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Models\Training\Instructing\Records\TrainingSession;
use App\Models\Users\User;
use App\Models\Roster\RosterMember;
use App\Models\Network\ShanwickController;
use App\Notifications\Training\Instructing\RemovedAsStudent;
use App\Models\Training\Instructing\Students\StudentStatusLabel;
use App\Models\Training\Instructing\Links\StudentStatusLabelLink;
Expand All @@ -39,6 +40,7 @@ public function handle()
// Initialise some variables
$checked_users = 0;
$accounts_not_linked = 0;
$not_in_discord = 0;
$discord_uids = [];

// Get List of Users in Discord
Expand Down Expand Up @@ -89,7 +91,7 @@ public function handle()
}

// Update DB information
$user->member_of_czqo = 1;
$user->member_of_czqo = true;
$user->discord_username = $discord_member['user']['username'];
$user->discord_avatar = $user->avatar ? 'https://cdn.discordapp.com/avatars/'.$user->discord_user_id.'/'.$discord_member['user']['avatar'].'.png' : null;
$user->save();
Expand All @@ -111,14 +113,15 @@ public function handle()
$discordRoleIds = [
'guest' => 482835389640343562,
'training' => 482824058141016075,
'certified' => 482819739996127259,
'gander_certified' => 482819739996127259,
'shanwick_certified' => 482819739996127259,
'supervisor' => 720502070683369563,
];

//Add the Member role to each user
array_push($rolesToAdd, $discordRoleIds['guest']);

//Roster Member?
//Gander Roster Member
if (RosterMember::where('user_id', $user->id)->exists()) {
//What status do they have?
$rosterProfile = RosterMember::where('user_id', $user->id)->first();
Expand All @@ -133,7 +136,7 @@ public function handle()
}

// Shankwick Roster Members
$shanwickRoster = ShanwickRoster::where('controller_cid', $user->id)->first();
$shanwickRoster = ShanwickController::where('controller_cid', $user->id)->first();
if ($shanwickRoster) {
array_push($rolesToAdd, $discordRoleIds['certified']);
}
Expand Down Expand Up @@ -172,9 +175,10 @@ public function handle()

} else {
## User is NOT in the discord

$not_in_discord++;

// Update DB Information
$user->member_of_czqo = 0;
$user->member_of_czqo = false;
$user->save();
}

Expand All @@ -186,10 +190,10 @@ public function handle()
foreach($discord_uids as $discord_uid){
$accounts_not_linked++; //records that Account Not Linked Role Assigned

sleep(3);
// sleep(3);

// add role
$discord->getClient()->put('guilds/'.env('DISCORD_GUILD_ID').'/members/'.$discord_uid.'/roles/1297422968472997908');
// // add role
// $discord->getClient()->put('guilds/'.env('DISCORD_GUILD_ID').'/members/'.$discord_uid.'/roles/1297422968472997908');
}


Expand All @@ -202,16 +206,17 @@ public function handle()
$update_content .= "\n\n **__Accounts:__**";

// Users which are linked in Discord
$update_content .= "\n- Linked to Discord: ".$checked_users." (name/roles updated)";
$update_content .= "\n- Accounts Linked: ".$checked_users." (name/roles updated)";
$update_content .= "\n- Linked but not in Discord: ".$not_in_discord;

// Accounts not linked
$update_content .= "\n- Not Linked to Discord: ".$accounts_not_linked." (role assigned)";

// Completion Time
$end_time = Carbon::now();
$seconds = $start_time->diffInSeconds($end_time);
$update_content .= "\n\n**__Script Time:__**";
$update_content .= "\n- Script Time: ".$seconds." seconds.";
$update_content .= "\n- Script Time: " . $start_time->diffForHumans($end_time, ['parts' => 2, 'short' => true, 'syntax' => Carbon::DIFF_ABSOLUTE]) . ".";


$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'WEEKLY: Discord User Update', $update_content);
}
Expand Down

0 comments on commit 51b90a1

Please sign in to comment.