[Feature] Add purchase notification (#2942)

This commit is contained in:
Mihail Gribkov
2024-06-16 20:33:40 +03:00
committed by GitHub
parent 21195a8a93
commit 9d92435493
9 changed files with 113 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -226,6 +226,11 @@ namespace Discord
/// </returns> /// </returns>
MessageRoleSubscriptionData RoleSubscriptionData { get; } MessageRoleSubscriptionData RoleSubscriptionData { get; }
/// <summary>
/// Gets the purchase notification for this message.
/// </summary>
PurchaseNotification PurchaseNotification { get; }
/// <summary> /// <summary>
/// Gets the call data of the message. /// Gets the call data of the message.
/// </summary> /// </summary>

View File

@@ -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;
}
}

View 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
}

View 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; }
}

View File

@@ -105,6 +105,9 @@ internal class Message
[JsonProperty("poll")] [JsonProperty("poll")]
public Optional<Poll> Poll { get; set; } public Optional<Poll> Poll { get; set; }
[JsonProperty("purchase_notification")]
public Optional<MessagePurchaseNotification> PurchaseNotification { get; set; }
[JsonProperty("call")] [JsonProperty("call")]
public Optional<MessageCallData> Call { get; set; } public Optional<MessageCallData> Call { get; set; }
} }

View File

@@ -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; }
}

View File

@@ -93,6 +93,9 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; } public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
/// <inheritdoc />
public PurchaseNotification PurchaseNotification { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public MessageCallData? CallData { get; private set; } public MessageCallData? CallData { get; private set; }
@@ -276,9 +279,18 @@ namespace Discord.Rest
if (model.Thread.IsSpecified) if (model.Thread.IsSpecified)
Thread = RestThreadChannel.Create(Discord, new RestGuild(Discord, model.Thread.Value.GuildId.Value), model.Thread.Value); 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) if (model.Call.IsSpecified)
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable()); CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task UpdateAsync(RequestOptions options = null) public async Task UpdateAsync(RequestOptions options = null)
{ {

View File

@@ -81,6 +81,9 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; } public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
/// <inheritdoc />
public PurchaseNotification PurchaseNotification { get; private set; }
/// <inheritdoc cref="IMessage.Thread"/> /// <inheritdoc cref="IMessage.Thread"/>
public SocketThreadChannel Thread { get; private set; } public SocketThreadChannel Thread { get; private set; }
@@ -303,6 +306,14 @@ namespace Discord.WebSocket
Thread = guild?.AddOrUpdateChannel(state, model.Thread.Value) as SocketThreadChannel; 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) if (model.Call.IsSpecified)
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable()); CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
} }