Skip to content

Commit

Permalink
[Feature] Add excludeDeleted argument to GetEntitlementsAsync (#3074
Browse files Browse the repository at this point in the history
)

* add `excludeDeleted` argument

* i love when it still builds locally somehow
  • Loading branch information
Misha-133 authored Mar 1, 2025
1 parent aa66928 commit 9c9407b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Discord.Net.Core/IDiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public interface IDiscordClient : IDisposable, IAsyncDisposable
/// </summary>
IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> GetEntitlementsAsync(int limit = 100,
ulong? afterId = null, ulong? beforeId = null, bool excludeEnded = false, ulong? guildId = null, ulong? userId = null,
ulong[] skuIds = null, RequestOptions options = null);
ulong[] skuIds = null, RequestOptions options = null, bool? excludeDeleted = null);

/// <summary>
/// Returns all SKUs for a given application.
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/API/Rest/ListEntitlementsParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ internal class ListEntitlementsParams
public Optional<ulong> GuildId { get; set; }

public Optional<bool> ExcludeEnded { get; set; }

public Optional<bool> ExcludeDeleted { get; set; }
}
2 changes: 1 addition & 1 deletion src/Discord.Net.Rest/BaseDiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Task IDiscordClient.DeleteTestEntitlementAsync(ulong entitlementId, RequestOptio
/// Returns all entitlements for a given app.
/// </summary>
IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> IDiscordClient.GetEntitlementsAsync(int limit, ulong? afterId, ulong? beforeId,
bool excludeEnded, ulong? guildId, ulong? userId, ulong[] skuIds, RequestOptions options) => AsyncEnumerable.Empty<IReadOnlyCollection<IEntitlement>>();
bool excludeEnded, ulong? guildId, ulong? userId, ulong[] skuIds, RequestOptions options, bool? excludeDeleted) => AsyncEnumerable.Empty<IReadOnlyCollection<IEntitlement>>();

/// <summary>
/// Gets all SKUs for a given application.
Expand Down
3 changes: 2 additions & 1 deletion src/Discord.Net.Rest/ClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public static async Task<RestEntitlement> CreateTestEntitlementAsync(BaseDiscord

public static IAsyncEnumerable<IReadOnlyCollection<RestEntitlement>> ListEntitlementsAsync(BaseDiscordClient client, int? limit = 100,
ulong? afterId = null, ulong? beforeId = null, bool excludeEnded = false, ulong? guildId = null, ulong? userId = null,
ulong[] skuIds = null, RequestOptions options = null)
ulong[] skuIds = null, bool? excludeDeleted = null, RequestOptions options = null)
{
return new PagedAsyncEnumerable<RestEntitlement>(
DiscordConfig.MaxEntitlementsPerBatch,
Expand All @@ -419,6 +419,7 @@ public static IAsyncEnumerable<IReadOnlyCollection<RestEntitlement>> ListEntitle
GuildId = guildId ?? Optional<ulong>.Unspecified,
UserId = userId ?? Optional<ulong>.Unspecified,
SkuIds = skuIds ?? Optional<ulong[]>.Unspecified,
ExcludeDeleted = excludeDeleted ?? Optional<bool>.Unspecified
};
if (info.Position != null)
args.AfterId = info.Position.Value;
Expand Down
5 changes: 5 additions & 0 deletions src/Discord.Net.Rest/DiscordRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,11 @@ public Task<Entitlement[]> ListEntitlementAsync(ListEntitlementsParams args, Req
query += $"&exclude_ended={args.ExcludeEnded.Value}";
}

if (args.ExcludeDeleted.IsSpecified)
{
query += $"&exclude_deleted={args.ExcludeDeleted.Value}";
}

return SendAsync<Entitlement[]>("GET", () => $"applications/{CurrentApplicationId}/entitlements{query}", new BucketIds(), options: options);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/DiscordRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ public Task DeleteTestEntitlementAsync(ulong entitlementId, RequestOptions optio
/// <inheritdoc cref="IDiscordClient.GetEntitlementsAsync" />
public IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> GetEntitlementsAsync(int? limit = 100,
ulong? afterId = null, ulong? beforeId = null, bool excludeEnded = false, ulong? guildId = null, ulong? userId = null,
ulong[] skuIds = null, RequestOptions options = null)
=> ClientHelper.ListEntitlementsAsync(this, limit, afterId, beforeId, excludeEnded, guildId, userId, skuIds, options);
ulong[] skuIds = null, RequestOptions options = null, bool? excludeDeleted = null)
=> ClientHelper.ListEntitlementsAsync(this, limit, afterId, beforeId, excludeEnded, guildId, userId, skuIds, excludeDeleted, options);

/// <inheritdoc />
public Task<IReadOnlyCollection<SKU>> GetSKUsAsync(RequestOptions options = null)
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ public Task DeleteTestEntitlementAsync(ulong entitlementId, RequestOptions optio
/// <inheritdoc cref="IDiscordClient.GetEntitlementsAsync"/>
public IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> GetEntitlementsAsync(int? limit = 100,
ulong? afterId = null, ulong? beforeId = null, bool excludeEnded = false, ulong? guildId = null, ulong? userId = null,
ulong[] skuIds = null, RequestOptions options = null)
=> ClientHelper.ListEntitlementsAsync(this, limit, afterId, beforeId, excludeEnded, guildId, userId, skuIds, options);
ulong[] skuIds = null, RequestOptions options = null, bool? excludeDeleted = null)
=> ClientHelper.ListEntitlementsAsync(this, limit, afterId, beforeId, excludeEnded, guildId, userId, skuIds, excludeDeleted, options);

/// <inheritdoc />
public Task<IReadOnlyCollection<SKU>> GetSKUsAsync(RequestOptions options = null)
Expand Down

0 comments on commit 9c9407b

Please sign in to comment.