*/ class OsuLeaderboardUpdateCommand extends Command { /** * A quick description of this command. * @return string. */ public function brief(): string { return 'Connects to the osu!api and stores new data.'; } /** * Command. */ public function execute(): void { $this->getLogger()->writeln('Updating osu! leaderboard...'); $api_key = config('osu.api_key'); if ($api_key === null) { $this->getLogger()->writeln("Your api key isn't set in the config, get one at https://osu.ppy.sh/p/api."); return; } $game_modes = [ 'osu!', 'osu!taiko', 'osu!catch', 'osu!mania', ]; $osulb = new OsuLeaderboard($api_key); $start = Carbon::now(); $users = DB::table('users') ->whereNotNull('user_osu') ->get(['user_id']); foreach ($game_modes as $mode => $name) { $this->getLogger()->writeln(PHP_EOL . "=> {$name}"); foreach ($users as $user) { $user = User::construct($user->user_id); $user_display = $user->osu . ($user->username !== $user->osu ? " ({$user->username})" : ''); $this->getLogger()->writeln("==> Updating {$name} scores for {$user_display}..."); $osulb->update($user->osu, $user, $mode); } } $this->getLogger()->writeln(PHP_EOL . "Purging inactive data..."); $osulb->purge($start); } }