Skip to content

Commit

Permalink
Add role subscription system channel flags and message field (discord…
Browse files Browse the repository at this point in the history
  • Loading branch information
KubaZ2 committed Jan 13, 2023
1 parent 37846ba commit 7478a73
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NetCord/JsonModels/JsonMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public partial class JsonMessage : JsonEntity
[JsonPropertyName("position")]
public int? Position { get; set; }

[JsonPropertyName("role_subscription_data")]
public JsonRoleSubscriptionData RoleSubscriptionData { get; set; }

[JsonPropertyName("guild_id")]
public ulong? GuildId { get; set; }

Expand Down
18 changes: 18 additions & 0 deletions NetCord/JsonModels/JsonRoleSubscriptionData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace NetCord.JsonModels;

public class JsonRoleSubscriptionData
{
[JsonPropertyName("role_subscription_listing_id")]
public ulong RoleSubscriptionListingId { get; set; }

[JsonPropertyName("tier_name")]
public string TierName { get; set; }

[JsonPropertyName("total_months_subscribed")]
public int TotalMonthsSubscribed { get; set; }

[JsonPropertyName("is_renewal")]
public bool IsRenewal { get; set; }
}
3 changes: 3 additions & 0 deletions NetCord/Rest/RestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class RestMessage : ClientEntity, IJsonModel<JsonModels.JsonMessage>
public IEnumerable<IComponent> Components { get; }
public IReadOnlyDictionary<ulong, MessageSticker> Stickers { get; }
public int? Position => _jsonModel.Position;
public RoleSubscriptionData? RoleSubscriptionData { get; }

public RestMessage(JsonModels.JsonMessage jsonModel, RestClient client) : base(client)
{
Expand Down Expand Up @@ -76,6 +77,8 @@ public RestMessage(JsonModels.JsonMessage jsonModel, RestClient client) : base(c
StartedThread = (GuildThread)Channel.CreateFromJson(jsonModel.StartedThread, client);
Components = jsonModel.Components.SelectOrEmpty(IComponent.CreateFromJson);
Stickers = jsonModel.Stickers.ToDictionaryOrEmpty(s => s.Id, s => new MessageSticker(s, client));
if (jsonModel.RoleSubscriptionData != null)
RoleSubscriptionData = new(jsonModel.RoleSubscriptionData);
}

public Task<RestMessage> ReplyAsync(string content, bool replyMention = false, bool failIfNotExists = true)
Expand Down
32 changes: 32 additions & 0 deletions NetCord/Rest/RoleSubscriptionData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace NetCord.Rest;

public class RoleSubscriptionData : IJsonModel<JsonModels.JsonRoleSubscriptionData>
{
JsonModels.JsonRoleSubscriptionData IJsonModel<JsonModels.JsonRoleSubscriptionData>.JsonModel => _jsonModel;
private readonly JsonModels.JsonRoleSubscriptionData _jsonModel;

public RoleSubscriptionData(JsonModels.JsonRoleSubscriptionData jsonModel)
{
_jsonModel = jsonModel;
}

/// <summary>
/// The id of the sku and listing that the user is subscribed to.
/// </summary>
public ulong RoleSubscriptionListingId => _jsonModel.RoleSubscriptionListingId;

/// <summary>
/// The name of the tier that the user is subscribed to.
/// </summary>
public string TierName => _jsonModel.TierName;

/// <summary>
/// The cumulative number of months that the user has been subscribed for.
/// </summary>
public int TotalMonthsSubscribed => _jsonModel.TotalMonthsSubscribed;

/// <summary>
/// Whether this notification is for a renewal rather than a new purchase.
/// </summary>
public bool IsRenewal => _jsonModel.IsRenewal;
}
25 changes: 25 additions & 0 deletions NetCord/Rest/SystemChannelFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,33 @@
[Flags]
public enum SystemChannelFlags
{
/// <summary>
/// Suppress member join notifications.
/// </summary>
SuppressJoinNotifications = 1 << 0,

/// <summary>
/// Suppress server boost notifications.
/// </summary>
SuppressPremiumSubscriptions = 1 << 1,

/// <summary>
/// Suppress server setup tips.
/// </summary>
SuppressGuildReminderNotifications = 1 << 2,

/// <summary>
/// Hide member join sticker reply buttons.
/// </summary>
SuppressJoinNotificationReplies = 1 << 3,

/// <summary>
/// Suppress role subscription purchase and renewal notifications.
/// </summary>
SuppressRoleSubscriptionPurchaseNotifications = 1 << 4,

/// <summary>
/// Hide role subscription sticker reply buttons.
/// </summary>
SuppressRoleSubscriptionPurchaseNotificationReplies = 1 << 5,
}

0 comments on commit 7478a73

Please sign in to comment.