[Feature] Premium subscriptions (#2781)
* what a big commit lel, add app sub enums * work * ah yup lol * `?` * events 1 * typo * `list` => `get` | remaining events * add `RespondWithPremiumRequiredAsync` to interaction module base
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
|
||||
using Model = Discord.API.Entitlement;
|
||||
|
||||
namespace Discord.WebSocket;
|
||||
|
||||
public class SocketEntitlement : SocketEntity<ulong>, IEntitlement
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedAt { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ulong SkuId { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IEntitlement.UserId"/>
|
||||
public Cacheable<SocketUser, RestUser, IUser, ulong>? User { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IEntitlement.GuildId"/>
|
||||
public Cacheable<SocketGuild, RestGuild, IGuild, ulong>? Guild { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ulong ApplicationId { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public EntitlementType Type { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsConsumed { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset? StartsAt { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset? EndsAt { get; private set; }
|
||||
|
||||
internal SocketEntitlement(DiscordSocketClient discord, ulong id) : base(discord, id)
|
||||
{
|
||||
}
|
||||
|
||||
internal static SocketEntitlement Create(DiscordSocketClient discord, Model model)
|
||||
{
|
||||
var entity = new SocketEntitlement(discord, model.Id);
|
||||
entity.Update(model);
|
||||
return entity;
|
||||
}
|
||||
|
||||
internal void Update(Model model)
|
||||
{
|
||||
SkuId = model.SkuId;
|
||||
|
||||
if (model.UserId.IsSpecified)
|
||||
{
|
||||
var user = Discord.GetUser(model.UserId.Value);
|
||||
|
||||
User = new Cacheable<SocketUser, RestUser, IUser, ulong>(user, model.UserId.Value, user is not null, async ()
|
||||
=> await Discord.Rest.GetUserAsync(model.UserId.Value));
|
||||
}
|
||||
|
||||
if (model.GuildId.IsSpecified)
|
||||
{
|
||||
var guild = Discord.GetGuild(model.GuildId.Value);
|
||||
|
||||
Guild = new Cacheable<SocketGuild, RestGuild, IGuild, ulong>(guild, model.GuildId.Value, guild is not null, async ()
|
||||
=> await Discord.Rest.GetGuildAsync(model.GuildId.Value));
|
||||
}
|
||||
|
||||
ApplicationId = model.ApplicationId;
|
||||
Type = model.Type;
|
||||
IsConsumed = model.IsConsumed;
|
||||
StartsAt = model.StartsAt.IsSpecified
|
||||
? model.StartsAt.Value
|
||||
: null;
|
||||
EndsAt = model.EndsAt.IsSpecified
|
||||
? model.EndsAt.Value
|
||||
: null;
|
||||
}
|
||||
|
||||
internal SocketEntitlement Clone() => MemberwiseClone() as SocketEntitlement;
|
||||
|
||||
#region IEntitlement
|
||||
|
||||
/// <inheritdoc/>
|
||||
ulong? IEntitlement.GuildId => Guild?.Id;
|
||||
|
||||
/// <inheritdoc/>
|
||||
ulong? IEntitlement.UserId => User?.Id;
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -2,7 +2,9 @@ using Discord.Net;
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DataModel = Discord.API.ApplicationCommandInteractionData;
|
||||
using Model = Discord.API.Interaction;
|
||||
@@ -71,6 +73,9 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc/>
|
||||
public ulong ApplicationId { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IDiscordInteraction.Entitlements" />
|
||||
public IReadOnlyCollection<RestEntitlement> Entitlements { get; private set; }
|
||||
|
||||
internal SocketInteraction(DiscordSocketClient client, ulong id, ISocketMessageChannel channel, SocketUser user)
|
||||
: base(client, id)
|
||||
{
|
||||
@@ -142,6 +147,8 @@ namespace Discord.WebSocket
|
||||
GuildLocale = model.GuildLocale.IsSpecified
|
||||
? model.GuildLocale.Value
|
||||
: null;
|
||||
|
||||
Entitlements = model.Entitlements.Select(x => RestEntitlement.Create(Discord, x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -398,6 +405,11 @@ namespace Discord.WebSocket
|
||||
/// <param name="options">The request options for this <see langword="async"/> request.</param>
|
||||
/// <returns>A task that represents the asynchronous operation of responding to the interaction.</returns>
|
||||
public abstract Task RespondWithModalAsync(Modal modal, RequestOptions options = null);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task RespondWithPremiumRequiredAsync(RequestOptions options = null)
|
||||
=> InteractionHelper.RespondWithPremiumRequiredAsync(Discord, Id, Token, options);
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -423,6 +435,9 @@ namespace Discord.WebSocket
|
||||
}
|
||||
|
||||
#region IDiscordInteraction
|
||||
/// <inheritdoc/>
|
||||
IReadOnlyCollection<IEntitlement> IDiscordInteraction.Entitlements => Entitlements;
|
||||
|
||||
/// <inheritdoc/>
|
||||
IUser IDiscordInteraction.User => User;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user