using Discord.Rest; using System; using Model = Discord.API.Entitlement; namespace Discord.WebSocket; public class SocketEntitlement : SocketEntity, IEntitlement { /// public DateTimeOffset CreatedAt { get; private set; } /// public ulong SkuId { get; private set; } /// public Cacheable? User { get; private set; } /// public Cacheable? Guild { get; private set; } /// public ulong ApplicationId { get; private set; } /// public EntitlementType Type { get; private set; } /// public bool IsConsumed { get; private set; } /// public DateTimeOffset? StartsAt { get; private set; } /// 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(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(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 /// ulong? IEntitlement.GuildId => Guild?.Id; /// ulong? IEntitlement.UserId => User?.Id; #endregion }