Merge pull request #1 from jdmcmahan/exclude-paid-apps

Allow exclusion of paid apps
This commit is contained in:
jdmcmahan 2021-08-27 16:32:16 -05:00 committed by GitHub
commit 884a565ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 6 deletions

View file

@ -51,8 +51,8 @@ Automatically fill a [lancache](https://github.com/zeropingheroes/lancache) with
lancache-autofill steam:queue-popular-apps [<top X apps>] [--free] [--windows=true] [--osx] [--linux]
lancache-autofill steam:queue-users-recent-apps <steam id 64> [<steam id 64>...] [--windows=true] [--osx] [--linux]
lancache-autofill steam:queue-users-recent-apps <steam-ids.txt> [--windows=true] [--osx] [--linux]
lancache-autofill steam:queue-users-owned-apps <steam id 64> [<steam id 64>...] [--include_free=true] [--windows=true] [--osx] [--linux]
lancache-autofill steam:queue-users-owned-apps <steam-ids.txt> [--include_free=true] [--windows=true] [--osx] [--linux]
lancache-autofill steam:queue-users-owned-apps <steam id 64> [<steam id 64>...] [--include_free=true] [--include_paid=true] [--windows=true] [--osx] [--linux]
lancache-autofill steam:queue-users-owned-apps <steam-ids.txt> [--include_free=true] [--include_paid=true] [--windows=true] [--osx] [--linux]
lancache-autofill steam:show-queue [<status>]
lancache-autofill steam:start-downloading

View file

@ -20,6 +20,7 @@ class QueueUsersOwnedApps extends Command
protected $signature = 'steam:queue-users-owned-apps
{steamIds* : One or more SteamId64(s) for the user(s) whose apps to queue, or a file containing a list}
{--include_free=true : Queue played free games}
{--include_paid=true : Queue purchased games}
{--windows=true : Queue the Windows version of the apps}
{--osx : Queue the OS X version of the apps}
{--linux : Queue the Linux version of the apps}';
@ -51,9 +52,8 @@ class QueueUsersOwnedApps extends Command
$platforms[] = 'linux';
}
if ($this->option('include_free')) {
$includeFree = true;
}
$includeFree = is_null($this->option('include_free')) || filter_var($this->option('include_free'), FILTER_VALIDATE_BOOLEAN);
$includePaid = is_null($this->option('include_paid')) || filter_var($this->option('include_paid'), FILTER_VALIDATE_BOOLEAN);
$steamIds = $this->argument('steamIds');
if (file_exists($steamIds[0])) {
@ -91,8 +91,26 @@ class QueueUsersOwnedApps extends Command
$consumer->consume(1);
$apps = Steam::player($user->steamId)->GetOwnedGames(true, $includeFree);
if (!$includePaid) {
// Technically the appDetails() method supports an array of app IDs
// However, the Steam API fails when more than 1 app ID is passed at a time
// See https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI#appdetails
$apps = $apps->filter(function ($app, $key) use ($consumer) {
$consumer->consume(1);
$appDetails = Steam::app()->appDetails($app->appId);
$isFree = $appDetails->isFree->get(0);
if (!isset($isFree)) {
$this->warn('Unable to determine whether app ' . $app->name . ' (' . $app->appId . ') is free to play, skipping');
return false;
}
return $isFree;
});
}
if (empty($apps)) {
$this->warn('Skipping user who does not own any apps: ' . $user->personaName);
$this->warn('Skipping user who does not own any matching apps: ' . $user->personaName);
continue;
}