more monetizatios stuffz (#3002)
* uhhhhhhhhhhhhhhhhhhh yes * uhhhhhhhhhhhhhhhhhhh yes * ~~i love git~~
This commit is contained in:
@@ -30,5 +30,5 @@ internal class Entitlement
|
||||
public Optional<DateTimeOffset> StartsAt { get; set; }
|
||||
|
||||
[JsonProperty("ends_at")]
|
||||
public Optional<DateTimeOffset> EndsAt { get; set; }
|
||||
public Optional<DateTimeOffset?> EndsAt { get; set; }
|
||||
}
|
||||
|
||||
@@ -18,4 +18,7 @@ internal class SKU
|
||||
|
||||
[JsonProperty("slug")]
|
||||
public string Slug { get; set; }
|
||||
|
||||
[JsonProperty("flags")]
|
||||
public SKUFlags Flags { get; set; }
|
||||
}
|
||||
|
||||
34
src/Discord.Net.Rest/API/Common/Subscription.cs
Normal file
34
src/Discord.Net.Rest/API/Common/Subscription.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
internal class Subscription
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
|
||||
[JsonProperty("user_id")]
|
||||
public ulong UserId { get; set; }
|
||||
|
||||
[JsonProperty("sku_ids")]
|
||||
public ulong[] SKUIds { get; set; }
|
||||
|
||||
[JsonProperty("entitlement_ids")]
|
||||
public ulong[] EntitlementIds { get; set; }
|
||||
|
||||
[JsonProperty("current_period_start")]
|
||||
public DateTimeOffset CurrentPeriodStart { get; set; }
|
||||
|
||||
[JsonProperty("current_period_end")]
|
||||
public DateTimeOffset CurrentPeriodEnd { get; set; }
|
||||
|
||||
[JsonProperty("status")]
|
||||
public SubscriptionStatus Status { get; set; }
|
||||
|
||||
[JsonProperty("canceled_at")]
|
||||
public DateTimeOffset? CanceledAt { get; set; }
|
||||
|
||||
[JsonProperty("country")]
|
||||
public string Country { get; set; }
|
||||
}
|
||||
@@ -286,7 +286,7 @@ namespace Discord.Rest
|
||||
/// <summary>
|
||||
/// Returns all entitlements for a given app.
|
||||
/// </summary>
|
||||
IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> IDiscordClient.GetEntitlementsAsync(int? limit, ulong? afterId, ulong? beforeId,
|
||||
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>>();
|
||||
|
||||
/// <summary>
|
||||
@@ -299,6 +299,17 @@ namespace Discord.Rest
|
||||
/// </summary>
|
||||
Task IDiscordClient.ConsumeEntitlementAsync(ulong entitlementId, RequestOptions options) => Task.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Returns all subscriptions for a given SKU.
|
||||
/// </summary>
|
||||
IAsyncEnumerable<IReadOnlyCollection<ISubscription>> IDiscordClient.GetSKUSubscriptionsAsync(ulong skuId, int limit, ulong? afterId,
|
||||
ulong? beforeId, ulong? userId, RequestOptions options) => AsyncEnumerable.Empty<IReadOnlyCollection<ISubscription>>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a subscription by its id.
|
||||
/// </summary>
|
||||
Task<ISubscription> IDiscordClient.GetSKUSubscriptionAsync(ulong skuId, ulong subscriptionId, RequestOptions options) => Task.FromResult<ISubscription>(null);
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
Task<Emote> IDiscordClient.GetApplicationEmoteAsync(ulong emoteId, RequestOptions options) => Task.FromResult<Emote>(null);
|
||||
|
||||
@@ -443,12 +443,46 @@ namespace Discord.Rest
|
||||
{
|
||||
var models = await client.ApiClient.ListSKUsAsync(options).ConfigureAwait(false);
|
||||
|
||||
return models.Select(x => new SKU(x.Id, x.Type, x.ApplicationId, x.Name, x.Slug)).ToImmutableArray();
|
||||
return models.Select(x => new SKU(x.Id, x.Type, x.ApplicationId, x.Name, x.Slug, x.Flags)).ToImmutableArray();
|
||||
}
|
||||
|
||||
public static Task ConsumeEntitlementAsync(BaseDiscordClient client, ulong entitlementId, RequestOptions options = null)
|
||||
=> client.ApiClient.ConsumeEntitlementAsync(entitlementId, options);
|
||||
|
||||
public static async Task<RestSubscription> GetSKUSubscriptionAsync(BaseDiscordClient client, ulong skuId, ulong subscriptionId, RequestOptions options = null)
|
||||
{
|
||||
var model = await client.ApiClient.GetSKUSubscriptionAsync(skuId, subscriptionId, options);
|
||||
|
||||
return RestSubscription.Create(client, model);
|
||||
}
|
||||
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestSubscription>> ListSubscriptionsAsync(BaseDiscordClient client, ulong skuId, int limit = 100,
|
||||
ulong? afterId = null, ulong? beforeId = null, ulong? userId = null, RequestOptions options = null)
|
||||
{
|
||||
return new PagedAsyncEnumerable<RestSubscription>(
|
||||
DiscordConfig.MaxSubscriptionsPerBatch,
|
||||
async (info, ct) =>
|
||||
{
|
||||
var _afterId = afterId;
|
||||
if (info.Position != null)
|
||||
_afterId = info.Position.Value;
|
||||
var models = await client.ApiClient.ListSKUSubscriptionsAsync(skuId, beforeId, _afterId, limit, userId, options).ConfigureAwait(false);
|
||||
return models
|
||||
.Select(x => RestSubscription.Create(client, x))
|
||||
.ToImmutableArray();
|
||||
},
|
||||
nextPage: (info, lastPage) =>
|
||||
{
|
||||
if (lastPage.Count != DiscordConfig.MaxSubscriptionsPerBatch)
|
||||
return false;
|
||||
info.Position = lastPage.Max(x => x.Id);
|
||||
return true;
|
||||
},
|
||||
start: afterId,
|
||||
count: limit
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Application Emojis
|
||||
|
||||
@@ -2852,6 +2852,24 @@ namespace Discord.API
|
||||
public Task ConsumeEntitlementAsync(ulong entitlementId, RequestOptions options = null)
|
||||
=> SendAsync("POST", () => $"applications/{CurrentApplicationId}/entitlements/{entitlementId}/consume", new BucketIds(), options: options);
|
||||
|
||||
public Task<Subscription> GetSKUSubscriptionAsync(ulong skuId, ulong subscriptionId, RequestOptions options = null)
|
||||
=> SendAsync<Subscription>("GET", () => $"skus/{skuId}/subscriptions/{subscriptionId}", new BucketIds(), options: options);
|
||||
|
||||
public Task<Subscription[]> ListSKUSubscriptionsAsync(ulong skuId, ulong? before = null, ulong? after = null, int limit = 100, ulong? userId = null, RequestOptions options = null)
|
||||
{
|
||||
Preconditions.AtMost(100, limit, "Limit must be less or equal to 100.");
|
||||
Preconditions.AtLeast(1, limit, "Limit must be greater or equal to 1.");
|
||||
|
||||
var args = $"?limit={limit}";
|
||||
if (before is not null)
|
||||
args += $"&before={before}";
|
||||
if (after is not null)
|
||||
args += $"&after={after}";
|
||||
if (userId is not null)
|
||||
args += $"&user_id={userId}";
|
||||
|
||||
return SendAsync<Subscription[]>("GET", () => $"skus/{skuId}/subscriptions{args}", new BucketIds(), options: options);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Polls
|
||||
|
||||
@@ -300,6 +300,15 @@ namespace Discord.Rest
|
||||
public Task ConsumeEntitlementAsync(ulong entitlementId, RequestOptions options = null)
|
||||
=> ClientHelper.ConsumeEntitlementAsync(this, entitlementId, options);
|
||||
|
||||
/// <inheritdoc cref="IDiscordClient.GetSKUSubscriptionAsync" />
|
||||
public Task<RestSubscription> GetSKUSubscriptionAsync(ulong skuId, ulong subscriptionId, RequestOptions options = null)
|
||||
=> ClientHelper.GetSKUSubscriptionAsync(this, skuId, subscriptionId, options);
|
||||
|
||||
/// <inheritdoc cref="IDiscordClient.GetSKUSubscriptionsAsync" />
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestSubscription>> GetSKUSubscriptionsAsync(ulong skuId, int limit = 100, ulong? afterId = null,
|
||||
ulong? beforeId = null, ulong? userId = null, RequestOptions options = null)
|
||||
=> ClientHelper.ListSubscriptionsAsync(this, skuId, limit, afterId, beforeId, userId, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<Emote> GetApplicationEmoteAsync(ulong emoteId, RequestOptions options = null)
|
||||
=> ClientHelper.GetApplicationEmojiAsync(this, emoteId, options);
|
||||
@@ -330,6 +339,14 @@ namespace Discord.Rest
|
||||
async Task<IApplication> IDiscordClient.GetApplicationInfoAsync(RequestOptions options)
|
||||
=> await GetApplicationInfoAsync(options).ConfigureAwait(false);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task<ISubscription> IDiscordClient.GetSKUSubscriptionAsync(ulong skuId, ulong subscriptionId, RequestOptions options)
|
||||
=> await GetSKUSubscriptionAsync(skuId, subscriptionId, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
IAsyncEnumerable<IReadOnlyCollection<ISubscription>> IDiscordClient.GetSKUSubscriptionsAsync(ulong skuId, int limit, ulong? afterId,
|
||||
ulong? beforeId, ulong? userId, RequestOptions options) => GetSKUSubscriptionsAsync(skuId, limit, afterId, beforeId, userId, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace Discord.Rest;
|
||||
|
||||
public class RestEntitlement : RestEntity<ulong>, IEntitlement
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedAt { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ulong SkuId { get; private set; }
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Discord.Rest;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an application subscription.
|
||||
/// </summary>
|
||||
public class RestSubscription : RestEntity<ulong>, ISubscription
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong UserId { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ulong> SKUIds { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ulong> EntitlementIds { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CurrentPeriodStart { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CurrentPeriodEnd { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public SubscriptionStatus Status { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset? CanceledAt { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Country { get; private set; }
|
||||
|
||||
internal RestSubscription(BaseDiscordClient discord, ulong id) : base(discord, id)
|
||||
{
|
||||
}
|
||||
|
||||
internal static RestSubscription Create(BaseDiscordClient discord, API.Subscription model)
|
||||
{
|
||||
var s = new RestSubscription(discord, model.Id);
|
||||
s.Update(model);
|
||||
return s;
|
||||
}
|
||||
|
||||
internal void Update(API.Subscription model)
|
||||
{
|
||||
UserId = model.UserId;
|
||||
SKUIds = model.SKUIds.ToImmutableArray();
|
||||
EntitlementIds = model.EntitlementIds.ToImmutableArray();
|
||||
CurrentPeriodStart = model.CurrentPeriodStart;
|
||||
CurrentPeriodEnd = model.CurrentPeriodEnd;
|
||||
Status = model.Status;
|
||||
CanceledAt = model.CanceledAt;
|
||||
Country = model.Country;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user