Add HelixRankCheck endpoint and console cron
This commit is contained in:
parent
67f4a9ac84
commit
2b8995cee4
67
app/Console/Commands/HelixRankCheckCommand.php
Normal file
67
app/Console/Commands/HelixRankCheckCommand.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?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->getFreeCompanyByName('Siren', 'Helix', $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;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/FreeCompanyRankedUser.php
Normal file
22
app/FreeCompanyRankedUser.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class FreeCompanyRankedUser extends Model
|
||||||
|
{
|
||||||
|
protected $primaryKey = 'lodestoneId';
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'lodestoneId',
|
||||||
|
'ingameRole',
|
||||||
|
'firstSeen',
|
||||||
|
'displayName',
|
||||||
|
'shouldBeRole',
|
||||||
|
'lastSeen',
|
||||||
|
'discordId',
|
||||||
|
];
|
||||||
|
}
|
||||||
45
app/Http/Controllers/HelixRankCheckController.php
Normal file
45
app/Http/Controllers/HelixRankCheckController.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\FreeCompanyRankedUser;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class HelixRankCheckController extends Controller
|
||||||
|
{
|
||||||
|
public function getRankChanges()
|
||||||
|
{
|
||||||
|
$members = FreeCompanyRankedUser::all()->toArray();
|
||||||
|
$members = array_map(function ($e) {
|
||||||
|
$e['lodestoneId'] = (string)$e['lodestoneId'];
|
||||||
|
$e['shouldBeRole'] = null;
|
||||||
|
|
||||||
|
$editable_roles = config('chaosapi.helix.rank_time');
|
||||||
|
// We don't want to edit council or mentor
|
||||||
|
if (!in_array($e['ingameRole'], array_keys($editable_roles))) return $e;
|
||||||
|
|
||||||
|
// Keep track of the highest role
|
||||||
|
$highest_role = $e['ingameRole'];
|
||||||
|
foreach ($editable_roles as $role => $min_days) {
|
||||||
|
if ($min_days === null) continue;
|
||||||
|
|
||||||
|
$min_date = Carbon::parse($e['firstSeen'])->addDays($min_days);
|
||||||
|
if ($min_date <= Carbon::now())
|
||||||
|
$highest_role = $role;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_search($e['ingameRole'], array_keys($editable_roles)) < array_search($highest_role, array_keys($editable_roles)))
|
||||||
|
$e['shouldBeRole'] = $highest_role;
|
||||||
|
|
||||||
|
return $e;
|
||||||
|
}, $members);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'success' => true,
|
||||||
|
'error' => null,
|
||||||
|
'data' => $members
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,5 +3,13 @@
|
|||||||
return [
|
return [
|
||||||
'middleware-enabled' => !env('APP_DEBUG', false),
|
'middleware-enabled' => !env('APP_DEBUG', false),
|
||||||
|
|
||||||
'cachetime' => 60
|
'cachetime' => 60,
|
||||||
|
|
||||||
|
'helix' => [
|
||||||
|
'rank_time' => [
|
||||||
|
"Recruit" => 0,
|
||||||
|
"Initiate" => 14,
|
||||||
|
"Member" => 44,
|
||||||
|
]
|
||||||
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateFreeCompanyRankedUsersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('free_company_ranked_users', function (Blueprint $table) {
|
||||||
|
$table->bigInteger('lodestoneId')->unsigned()->primary();
|
||||||
|
$table->string('ingameRole', 127);
|
||||||
|
$table->dateTime('firstSeen');
|
||||||
|
$table->string('displayName', 127);
|
||||||
|
$table->dateTime('lastSeen');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('free_company_ranked_users');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -42,6 +42,8 @@ Route::prefix('api')->middleware(ApiAuthorization::class)->group(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('rank')->group(function() {
|
Route::prefix('rank')->group(function() {
|
||||||
|
Route::get('/check/helix', 'HelixRankCheckController@getRankChanges');
|
||||||
|
|
||||||
Route::get('/check/{freeCompanyId}/discord/{discordGuildId}/{discordUserId}/{currentRank}');
|
Route::get('/check/{freeCompanyId}/discord/{discordGuildId}/{discordUserId}/{currentRank}');
|
||||||
Route::get('/check/{freeCompanyId}/website/{hostname}/{websiteId}/{currentRank}');
|
Route::get('/check/{freeCompanyId}/website/{hostname}/{websiteId}/{currentRank}');
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user