[Feature] Add purchase notification (#2942)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a guild product purchase.
|
||||
/// </summary>
|
||||
public readonly struct GuildProductPurchase
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the ID of the listing.
|
||||
/// </summary>
|
||||
public readonly ulong ListingId;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the product.
|
||||
/// </summary>
|
||||
public readonly string ProductName;
|
||||
|
||||
internal GuildProductPurchase(ulong listingId, string productName)
|
||||
{
|
||||
ListingId = listingId;
|
||||
ProductName = productName;
|
||||
}
|
||||
}
|
||||
@@ -226,6 +226,11 @@ namespace Discord
|
||||
/// </returns>
|
||||
MessageRoleSubscriptionData RoleSubscriptionData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the purchase notification for this message.
|
||||
/// </summary>
|
||||
PurchaseNotification PurchaseNotification { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the call data of the message.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a purchase notification.
|
||||
/// </summary>
|
||||
public readonly struct PurchaseNotification
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of the purchase.
|
||||
/// </summary>
|
||||
public readonly PurchaseType Type;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the purchased product.
|
||||
/// </summary>
|
||||
public readonly GuildProductPurchase? ProductPurchase;
|
||||
|
||||
internal PurchaseNotification(PurchaseType type, GuildProductPurchase? productPurchase)
|
||||
{
|
||||
Type = type;
|
||||
ProductPurchase = productPurchase;
|
||||
}
|
||||
}
|
||||
12
src/Discord.Net.Core/Entities/Messages/PurchaseType.cs
Normal file
12
src/Discord.Net.Core/Entities/Messages/PurchaseType.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Discord;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the type of purchase notification.
|
||||
/// </summary>
|
||||
public enum PurchaseType
|
||||
{
|
||||
/// <summary>
|
||||
/// A guild product purchase.
|
||||
/// </summary>
|
||||
GuildProduct = 0
|
||||
}
|
||||
12
src/Discord.Net.Rest/API/Common/GuildProductPurchase.cs
Normal file
12
src/Discord.Net.Rest/API/Common/GuildProductPurchase.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
internal class GuildProductPurchase
|
||||
{
|
||||
[JsonProperty("listing_id")]
|
||||
public ulong ListingId { get; set; }
|
||||
|
||||
[JsonProperty("product_name")]
|
||||
public string ProductName { get; set; }
|
||||
}
|
||||
@@ -105,6 +105,9 @@ internal class Message
|
||||
[JsonProperty("poll")]
|
||||
public Optional<Poll> Poll { get; set; }
|
||||
|
||||
[JsonProperty("purchase_notification")]
|
||||
public Optional<MessagePurchaseNotification> PurchaseNotification { get; set; }
|
||||
|
||||
[JsonProperty("call")]
|
||||
public Optional<MessageCallData> Call { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
internal class MessagePurchaseNotification
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
public PurchaseType Type { get; set; }
|
||||
|
||||
[JsonProperty("guild_product_purchase")]
|
||||
public Optional<GuildProductPurchase> ProductPurchase { get; set; }
|
||||
}
|
||||
@@ -93,6 +93,9 @@ namespace Discord.Rest
|
||||
/// <inheritdoc />
|
||||
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public PurchaseNotification PurchaseNotification { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public MessageCallData? CallData { get; private set; }
|
||||
|
||||
@@ -276,9 +279,18 @@ namespace Discord.Rest
|
||||
if (model.Thread.IsSpecified)
|
||||
Thread = RestThreadChannel.Create(Discord, new RestGuild(Discord, model.Thread.Value.GuildId.Value), model.Thread.Value);
|
||||
|
||||
if (model.PurchaseNotification.IsSpecified)
|
||||
{
|
||||
PurchaseNotification = new PurchaseNotification(model.PurchaseNotification.Value.Type,
|
||||
model.PurchaseNotification.Value.ProductPurchase.IsSpecified
|
||||
? new GuildProductPurchase(model.PurchaseNotification.Value.ProductPurchase.Value.ListingId, model.PurchaseNotification.Value.ProductPurchase.Value.ProductName)
|
||||
: null);
|
||||
}
|
||||
|
||||
if (model.Call.IsSpecified)
|
||||
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
|
||||
@@ -81,6 +81,9 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public PurchaseNotification PurchaseNotification { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IMessage.Thread"/>
|
||||
public SocketThreadChannel Thread { get; private set; }
|
||||
|
||||
@@ -303,6 +306,14 @@ namespace Discord.WebSocket
|
||||
Thread = guild?.AddOrUpdateChannel(state, model.Thread.Value) as SocketThreadChannel;
|
||||
}
|
||||
|
||||
if (model.PurchaseNotification.IsSpecified)
|
||||
{
|
||||
PurchaseNotification = new PurchaseNotification(model.PurchaseNotification.Value.Type,
|
||||
model.PurchaseNotification.Value.ProductPurchase.IsSpecified
|
||||
? new GuildProductPurchase(model.PurchaseNotification.Value.ProductPurchase.Value.ListingId, model.PurchaseNotification.Value.ProductPurchase.Value.ProductName)
|
||||
: null);
|
||||
}
|
||||
|
||||
if (model.Call.IsSpecified)
|
||||
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user