Skip to content

Commit 9d92435

Browse files
authored
[Feature] Add purchase notification (#2942)
1 parent 21195a8 commit 9d92435

File tree

9 files changed

+113
-0
lines changed

9 files changed

+113
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Discord;
2+
3+
/// <summary>
4+
/// Represents a guild product purchase.
5+
/// </summary>
6+
public readonly struct GuildProductPurchase
7+
{
8+
/// <summary>
9+
/// Gets the ID of the listing.
10+
/// </summary>
11+
public readonly ulong ListingId;
12+
13+
/// <summary>
14+
/// Gets the name of the product.
15+
/// </summary>
16+
public readonly string ProductName;
17+
18+
internal GuildProductPurchase(ulong listingId, string productName)
19+
{
20+
ListingId = listingId;
21+
ProductName = productName;
22+
}
23+
}

src/Discord.Net.Core/Entities/Messages/IMessage.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ public interface IMessage : ISnowflakeEntity, IDeletable
226226
/// </returns>
227227
MessageRoleSubscriptionData RoleSubscriptionData { get; }
228228

229+
/// <summary>
230+
/// Gets the purchase notification for this message.
231+
/// </summary>
232+
PurchaseNotification PurchaseNotification { get; }
233+
229234
/// <summary>
230235
/// Gets the call data of the message.
231236
/// </summary>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Discord;
2+
3+
/// <summary>
4+
/// Represents a purchase notification.
5+
/// </summary>
6+
public readonly struct PurchaseNotification
7+
{
8+
/// <summary>
9+
/// Gets the type of the purchase.
10+
/// </summary>
11+
public readonly PurchaseType Type;
12+
13+
/// <summary>
14+
/// Gets the purchased product.
15+
/// </summary>
16+
public readonly GuildProductPurchase? ProductPurchase;
17+
18+
internal PurchaseNotification(PurchaseType type, GuildProductPurchase? productPurchase)
19+
{
20+
Type = type;
21+
ProductPurchase = productPurchase;
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Discord;
2+
3+
/// <summary>
4+
/// Represents the type of purchase notification.
5+
/// </summary>
6+
public enum PurchaseType
7+
{
8+
/// <summary>
9+
/// A guild product purchase.
10+
/// </summary>
11+
GuildProduct = 0
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Discord.API;
4+
5+
internal class GuildProductPurchase
6+
{
7+
[JsonProperty("listing_id")]
8+
public ulong ListingId { get; set; }
9+
10+
[JsonProperty("product_name")]
11+
public string ProductName { get; set; }
12+
}

src/Discord.Net.Rest/API/Common/Message.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ internal class Message
105105
[JsonProperty("poll")]
106106
public Optional<Poll> Poll { get; set; }
107107

108+
[JsonProperty("purchase_notification")]
109+
public Optional<MessagePurchaseNotification> PurchaseNotification { get; set; }
110+
108111
[JsonProperty("call")]
109112
public Optional<MessageCallData> Call { get; set; }
110113
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Discord.API;
4+
5+
internal class MessagePurchaseNotification
6+
{
7+
[JsonProperty("type")]
8+
public PurchaseType Type { get; set; }
9+
10+
[JsonProperty("guild_product_purchase")]
11+
public Optional<GuildProductPurchase> ProductPurchase { get; set; }
12+
}

src/Discord.Net.Rest/Entities/Messages/RestMessage.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public abstract class RestMessage : RestEntity<ulong>, IMessage, IUpdateable
9393
/// <inheritdoc />
9494
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
9595

96+
/// <inheritdoc />
97+
public PurchaseNotification PurchaseNotification { get; private set; }
98+
9699
/// <inheritdoc />
97100
public MessageCallData? CallData { get; private set; }
98101

@@ -276,9 +279,18 @@ internal virtual void Update(Model model)
276279
if (model.Thread.IsSpecified)
277280
Thread = RestThreadChannel.Create(Discord, new RestGuild(Discord, model.Thread.Value.GuildId.Value), model.Thread.Value);
278281

282+
if (model.PurchaseNotification.IsSpecified)
283+
{
284+
PurchaseNotification = new PurchaseNotification(model.PurchaseNotification.Value.Type,
285+
model.PurchaseNotification.Value.ProductPurchase.IsSpecified
286+
? new GuildProductPurchase(model.PurchaseNotification.Value.ProductPurchase.Value.ListingId, model.PurchaseNotification.Value.ProductPurchase.Value.ProductName)
287+
: null);
288+
}
289+
279290
if (model.Call.IsSpecified)
280291
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
281292
}
293+
282294
/// <inheritdoc />
283295
public async Task UpdateAsync(RequestOptions options = null)
284296
{

src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public abstract class SocketMessage : SocketEntity<ulong>, IMessage
8181
/// <inheritdoc />
8282
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
8383

84+
/// <inheritdoc />
85+
public PurchaseNotification PurchaseNotification { get; private set; }
86+
8487
/// <inheritdoc cref="IMessage.Thread"/>
8588
public SocketThreadChannel Thread { get; private set; }
8689

@@ -303,6 +306,14 @@ internal virtual void Update(ClientState state, Model model)
303306
Thread = guild?.AddOrUpdateChannel(state, model.Thread.Value) as SocketThreadChannel;
304307
}
305308

309+
if (model.PurchaseNotification.IsSpecified)
310+
{
311+
PurchaseNotification = new PurchaseNotification(model.PurchaseNotification.Value.Type,
312+
model.PurchaseNotification.Value.ProductPurchase.IsSpecified
313+
? new GuildProductPurchase(model.PurchaseNotification.Value.ProductPurchase.Value.ListingId, model.PurchaseNotification.Value.ProductPurchase.Value.ProductName)
314+
: null);
315+
}
316+
306317
if (model.Call.IsSpecified)
307318
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
308319
}

0 commit comments

Comments
 (0)