Make the rank check endpoint dynamic
This commit is contained in:
parent
f5382aa16d
commit
c584f94c4a
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\FreeCompanyRankedUser;
|
||||
use App\Services\LodestoneApiService;
|
||||
use App\Services\LodestoneCacheService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class HelixRankCheckCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'chaosbot:cron';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Runs Helix crons';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(LodestoneCacheService $cacheService, LodestoneApiService $apiService)
|
||||
{
|
||||
$fcInfo = $cacheService->getFreeCompanyById('9231394073691143535', $apiService);
|
||||
$members = $fcInfo->content['FreeCompanyMembers'];
|
||||
foreach ($members as $member) {
|
||||
$rankedUser = FreeCompanyRankedUser::where('lodestoneId', $member['ID'])->first();
|
||||
|
||||
if ($rankedUser === null)
|
||||
{
|
||||
$rankedUser = new FreeCompanyRankedUser;
|
||||
$rankedUser->lodestoneId = $member['ID'];
|
||||
}
|
||||
|
||||
$rankedUser->displayName = $member['Name'];
|
||||
$rankedUser->ingameRole = $member['Rank'];
|
||||
$rankedUser->lastSeen = Carbon::now();
|
||||
if ($rankedUser->firstSeen === null)
|
||||
$rankedUser->firstSeen = Carbon::now();
|
||||
|
||||
$rankedUser->save();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
70
app/Console/Commands/RankCheckCommand.php
Normal file
70
app/Console/Commands/RankCheckCommand.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\FreeCompanyRankedUser;
|
||||
use App\Services\LodestoneApiService;
|
||||
use App\Services\LodestoneCacheService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class RankCheckCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'chaosbot:cron';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Runs Helix crons';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(LodestoneCacheService $cacheService, LodestoneApiService $apiService)
|
||||
{
|
||||
foreach (array_keys(config('chaosapi.free_company_ranked_user')) as $lodestoneFreeCompanyId) {
|
||||
$fcInfo = $cacheService->getFreeCompanyById($lodestoneFreeCompanyId, $apiService);
|
||||
$members = $fcInfo->content['FreeCompanyMembers'];
|
||||
foreach ($members as $member) {
|
||||
$rankedUser = FreeCompanyRankedUser::where('lodestoneId', $member['ID'])->first();
|
||||
|
||||
if ($rankedUser === null)
|
||||
{
|
||||
$rankedUser = new FreeCompanyRankedUser;
|
||||
$rankedUser->lodestoneId = $member['ID'];
|
||||
}
|
||||
|
||||
$rankedUser->freeCompanyId = $lodestoneFreeCompanyId;
|
||||
$rankedUser->displayName = $member['Name'];
|
||||
$rankedUser->ingameRole = $member['Rank'];
|
||||
$rankedUser->lastSeen = Carbon::now();
|
||||
if ($rankedUser->firstSeen === null)
|
||||
$rankedUser->firstSeen = Carbon::now();
|
||||
|
||||
$rankedUser->save();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -7,16 +7,22 @@ use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class HelixRankCheckController extends Controller
|
||||
class RankCheckController extends Controller
|
||||
{
|
||||
public function getRankChanges()
|
||||
public function getRankChanges(string $discordGuildId)
|
||||
{
|
||||
$members = FreeCompanyRankedUser::all()->toArray();
|
||||
$members = array_map(function ($e) {
|
||||
if (!in_array($discordGuildId, array_keys(config('chaosapi.free_company_ranked_user_discord_mapping')))) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$lodestoneFreeCompanyId = config('chaosapi.free_company_ranked_user_discord_mapping.' . $discordGuildId);
|
||||
|
||||
$members = FreeCompanyRankedUser::where('freeCompanyId', $lodestoneFreeCompanyId)->get()->toArray();
|
||||
$members = array_map(function ($e) use ($lodestoneFreeCompanyId) {
|
||||
$e['lodestoneId'] = (string)$e['lodestoneId'];
|
||||
$e['shouldBeRole'] = null;
|
||||
|
||||
$editable_roles = config('chaosapi.helix.rank_time');
|
||||
$editable_roles = config('chaosapi.free_company_ranked_user.' . $lodestoneFreeCompanyId . '.rank_time');
|
||||
// We don't want to edit council or mentor
|
||||
if (!in_array($e['ingameRole'], array_keys($editable_roles))) return $e;
|
||||
|
||||
@ -5,12 +5,33 @@ return [
|
||||
|
||||
'cachetime' => 60,
|
||||
|
||||
'helix' => [
|
||||
'rank_time' => [
|
||||
"Recruit" => 0,
|
||||
"Initiate" => 14,
|
||||
"Member" => 44,
|
||||
'free_company_ranked_user' => [
|
||||
'9231394073691143535' => [
|
||||
'rank_time' => [
|
||||
"Recruit" => 0,
|
||||
"Initiate" => 14,
|
||||
"Member" => 44,
|
||||
],
|
||||
'demotion_time_hours' => 5
|
||||
],
|
||||
'demotion_time_hours' => 5
|
||||
'9231394073691151733' => [
|
||||
'rank_time' => [
|
||||
"Early Birb" => 0,
|
||||
"Tiny Birb" => 14,
|
||||
],
|
||||
'demotion_time_hours' => 5
|
||||
]
|
||||
],
|
||||
|
||||
'free_company_ranked_user_discord_mapping' => [
|
||||
// Helix/Daybreak
|
||||
'618857558740041738' => '9231394073691143535',
|
||||
// Birbs
|
||||
'762877727215714324' => '9231394073691151733',
|
||||
|
||||
// Dan's testing server
|
||||
'386574965626896384' => '9231394073691151733',
|
||||
// ChaoticLogic
|
||||
'178563508034600960' => '9231394073691143535',
|
||||
]
|
||||
];
|
||||
|
||||
@ -42,7 +42,7 @@ Route::prefix('api')->middleware(ApiAuthorization::class)->group(function() {
|
||||
});
|
||||
|
||||
Route::prefix('rank')->group(function() {
|
||||
Route::get('/check/helix', 'HelixRankCheckController@getRankChanges');
|
||||
Route::get('/check/{discordGuildId}', 'RankCheckController@getRankChanges');
|
||||
|
||||
Route::get('/check/{freeCompanyId}/discord/{discordGuildId}/{discordUserId}/{currentRank}');
|
||||
Route::get('/check/{freeCompanyId}/website/{hostname}/{websiteId}/{currentRank}');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user