Skip to content

Commit

Permalink
Merge pull request #274 from czqoocavatsim/JoshuaMicallefYBSU-patch-2
Browse files Browse the repository at this point in the history
EditThreadTag Addition
  • Loading branch information
JoshuaMicallefYBSU authored Aug 14, 2024
2 parents c330c3c + 889f1bd commit 5208b59
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ public function ThreadTest()
$discord = new DiscordClient();
$discord->createTrainingThread('1273181022699130902', 'Joshua Micallef 1342084', '<@200426385863344129>');
}

public function EditTagTest()
{
$discord = new DiscordClient();
$results = $discord->AddThreadTag('Test', 'Roster Placeholder 2');

return $results;
}
}
9 changes: 8 additions & 1 deletion app/Http/Controllers/Training/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,11 @@ public function adminAcceptApplication($reference_id, Request $request)
$discord->assignRole($student->user->discord_user_id, 482824058141016075);

//Create Instructor Thread
$discord->createTrainingThread('1273181022699130902', $student->user->fullName('FLC'), '<@'.$student->user->discord_user_id.'>');
$discord->createTrainingThread(intval(config('services.discord.training_forum')), $student->user->fullName('FLC'), '<@'.$student->user->discord_user_id.'>');

// Notify Senior Team that the application was accepted.
$discord->sendMessageWithEmbed(config('app.env') == 'local' ? intval(config('services.discord.web_logs')) : intval(config('services.discord.applications')), 'Accepted Applicant', $student->user->fullName('FLC').' has just been accepted.', 'error');

} else {
Session::flash('info', 'Unable to add Discord permissions automatically, as the member is not in the Discord.');

Expand Down Expand Up @@ -495,6 +499,9 @@ public function adminRejectApplication($reference_id, Request $request)
]);
$update->save();

// Notify Senior Team that new Applicant has been rejected.
$discord->sendMessageWithEmbed(config('app.env') == 'local' ? intval(config('services.discord.web_logs')) : intval(config('services.discord.applications')), 'Application Denied', $student->user->fullName('FLC')."'s application has been denied.", 'error');

//Notify user
$application->user->notify(new ApplicationRejectedApplicant($application));

Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Training/InstructingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,9 @@ public function assignStatusLabelToStudent(Request $request, $student_id)
$discord->sendMessageWithEmbed(intval(config('services.discord.instructors')), 'A new student is available for pick-up by an Instructor', $student->user->fullName('FLC') . ' is available to be picked up by an instructor!');
}


//
$discord = new DiscordClient();
$discord->EditThreadTag($lable->name, $student->user->fullName('FLC'));

//Create the link
$link = new StudentStatusLabelLink([
Expand Down
34 changes: 34 additions & 0 deletions app/Services/DiscordClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,39 @@ public function createTrainingThread($channelId, $name, $user)

}

public function EditThreadTag($lable, $name)
{
// Get Training Tags and Threads from Discord
$tag_responses = $this->client->get('channels/'.intval(config('services.discord.training_forum')));
$active_threads = $this->client->get('guilds/'.env('DISCORD_GUILD_ID').'/threads/active');

// Decode Data in JSON
$tag_data = json_decode($tag_responses->getBody(), true);
$threads_data = json_decode($active_threads->getBody(), true);

// Filter Tag/Thread data into easier format
$tag_details = [];
$tags = $tag_data['available_tags'];

$thread_details = [];
$threads = $threads_data['threads'];

// Loop through each Thread, and then through each tag to see if a match is found.
foreach($threads as $thread){
foreach($tags as $tag){
if($tag['name'] == $lable && $thread['name'] == $name){
// Update Tag with new details
$data = $this->client->patch('channels/'.$thread['id'], [
'json' => [
'applied_tags' => [$tag['id']],
]
]);

break;
}
}
}
}

}

6 changes: 3 additions & 3 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
'endorsements' => env('DISCORD_ENDORSEMENTS'),
'marketing' => env('DISCORD_MARKETING'),
'staff' => env('DISCORD_STAFF'),
'instructors' => '782927909974442015',
'applications' => '1273228164255977492',
'training_forum' => '1226234767138226338',
'instructors' => env('DISCORD_INSTRUCTORS'),
'applications' => env('DISCORD_APPLICATIONS'),
'training_forum' => env('DISCORD_TRAINING_FORUM'),
],
];
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

// Discord shortcut
Route::get('/discord', [DiscordController::class, 'joinShortcut']);
Route::get('/discord/function-test', [DiscordTestController::class, 'ThreadTest']);
Route::get('/discord/function-test', [DiscordTestController::class, 'EditTagTest']);

// Public news articles
Route::get('/news/{id}', [NewsController::class, 'viewArticlePublic'])->name('news.articlepublic')->where('id', '[0-9]+');
Expand Down

0 comments on commit 5208b59

Please sign in to comment.