Skip to content

Commit

Permalink
Add MinDaysOld Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Apr 13, 2024
1 parent 5e257d8 commit db5c6d3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions FreePackages.Tests/Filters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,21 @@ public void CanFilterByWishlist() {

Assert.IsTrue(PackageFilter.IsAppWantedByFilter(app, Filter));
}

[TestMethod]
public void CanFilterByReleaseDate() {
var app = new FilterableApp(KeyValue.LoadAsText("app_which_is_free.txt"));

Filter.MinDaysOld = 0;

Assert.IsTrue(PackageFilter.IsAppWantedByFilter(app, Filter));

Filter.MinDaysOld = 1;

Assert.IsFalse(PackageFilter.IsAppWantedByFilter(app, Filter));

Filter.MinDaysOld = 20000;

Assert.IsTrue(PackageFilter.IsAppWantedByFilter(app, Filter));
}
}
3 changes: 3 additions & 0 deletions FreePackages/Data/FilterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ internal sealed class FilterConfig {
[JsonInclude]
internal bool WishlistOnly { get; set; } = false;

[JsonInclude]
internal uint MinDaysOld { get; set; } = 0;

[JsonConstructor]
internal FilterConfig() { }
}
Expand Down
2 changes: 2 additions & 0 deletions FreePackages/Data/FilterableApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal sealed class FilterableApp {
internal uint PlayTestType;
internal List<string>? OSList;
internal uint DeckCompatibility;
internal DateTime SteamReleaseDate;
internal bool Hidden;

internal FilterableApp(SteamApps.PICSProductInfoCallback.PICSProductInfo productInfo) : this(productInfo.ID, productInfo.KeyValues) {}
Expand Down Expand Up @@ -55,6 +56,7 @@ internal FilterableApp(uint id, KeyValue kv) {
PlayTestType = kv["extended"]["playtest_type"].AsUnsignedInteger();
OSList = kv["common"]["oslist"].AsString()?.ToUpper().Split(",").ToList();
DeckCompatibility = kv["common"]["steam_deck_compatibility"]["category"].AsUnsignedInteger();
SteamReleaseDate = DateTimeOffset.FromUnixTimeSeconds(kv["common"]["steam_release_date"].AsUnsignedInteger()).UtcDateTime;
Hidden = kv["common"] == KeyValue.Invalid;

// Fix the category for games which do have trading cards, but which don't have the trading card category, Ex: https://steamdb.info/app/316260/
Expand Down
5 changes: 5 additions & 0 deletions FreePackages/Handlers/PackageFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ internal bool IsAppWantedByFilter(FilterableApp app, FilterConfig filter) {
// Unwated to due not being wishlisted or followed on the Steam storefront
return false;
}

if (filter.MinDaysOld > 0 && DateTime.UtcNow.AddDays(-filter.MinDaysOld) > app.SteamReleaseDate) {
// Unwanted because the app isn't new enough
return false;
}

return true;
}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ By default, the plugin will attempt to activate all free non-playtest packages.
"Languages": [],
"Systems": [],
"MinReviewScore": 0,
"MinDaysOld": 0,
"IgnoredContentDescriptors": [],
"IgnoredTypes": [],
"IgnoredTags": [],
Expand Down Expand Up @@ -306,6 +307,12 @@ All filter options are explained below:

---

#### MinDaysOld

`uint` type with default value of `0`. Packages must contain an app with a Steam release date newer than this many days or they will not be added to your account. You can leave this at `0` to allow for all values.

---

#### IgnoredContentDescriptors

`HashSet<uint>` type with default value of `[]`. Packages containing apps with any of the `ContentDescriptorIDs` specified here will not be added to your account. Detailed information about content descriptors can be found [here](https://store.steampowered.com/account/preferences/) under "Mature Content Filtering".
Expand Down

0 comments on commit db5c6d3

Please sign in to comment.