From a4217154f075dcd2bb54c28e07f4c7931d11a724 Mon Sep 17 00:00:00 2001 From: Misha133 <61027276+Misha-133@users.noreply.github.com> Date: Thu, 10 Aug 2023 16:08:42 +0300 Subject: [PATCH] [Feature] Add Role & Attachment flags (#2720) * initial commit * oops * another typo -_- * Update AttachmentFlags.cs Made this on my phone lol * Update AttachmentFlags.cs * -line --- .../Entities/Messages/AttachmentFlags.cs | 27 ++++++++ .../Entities/Messages/IAttachment.cs | 5 ++ src/Discord.Net.Core/Entities/Roles/IRole.cs | 5 ++ .../Entities/Roles/RoleFlags.cs | 17 +++++ src/Discord.Net.Rest/API/Common/Attachment.cs | 69 +++++++++++-------- src/Discord.Net.Rest/API/Common/Role.cs | 64 ++++++++++------- .../Entities/Messages/Attachment.cs | 9 ++- .../Entities/Roles/RestRole.cs | 5 ++ .../Entities/Roles/SocketRole.cs | 5 ++ 9 files changed, 150 insertions(+), 56 deletions(-) create mode 100644 src/Discord.Net.Core/Entities/Messages/AttachmentFlags.cs create mode 100644 src/Discord.Net.Core/Entities/Roles/RoleFlags.cs diff --git a/src/Discord.Net.Core/Entities/Messages/AttachmentFlags.cs b/src/Discord.Net.Core/Entities/Messages/AttachmentFlags.cs new file mode 100644 index 00000000..83a61baf --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/AttachmentFlags.cs @@ -0,0 +1,27 @@ +using System; + +namespace Discord; + +[Flags] +public enum AttachmentFlags +{ + /// + /// The attachment has no flags. + /// + None = 0, + + /// + /// Indicates that this attachment is a clip. + /// + IsClip = 1 << 0, + + /// + /// Indicates that this attachment is a thumbnail. + /// + IsThumbnail = 1 << 1, + + /// + /// Indicates that this attachment has been edited using the remix feature on mobile. + /// + IsRemix = 1 << 2, +} diff --git a/src/Discord.Net.Core/Entities/Messages/IAttachment.cs b/src/Discord.Net.Core/Entities/Messages/IAttachment.cs index 75d1262e..6e9b4df2 100644 --- a/src/Discord.Net.Core/Entities/Messages/IAttachment.cs +++ b/src/Discord.Net.Core/Entities/Messages/IAttachment.cs @@ -80,5 +80,10 @@ namespace Discord /// Gets the base64 encoded bytearray representing a sampled waveform. if the attachment is not a voice message. /// public string Waveform { get; } + + /// + /// Gets flags related to this to this attachment. + /// + public AttachmentFlags Flags { get; } } } diff --git a/src/Discord.Net.Core/Entities/Roles/IRole.cs b/src/Discord.Net.Core/Entities/Roles/IRole.cs index edb92fb1..ac4719e7 100644 --- a/src/Discord.Net.Core/Entities/Roles/IRole.cs +++ b/src/Discord.Net.Core/Entities/Roles/IRole.cs @@ -87,6 +87,11 @@ namespace Discord /// RoleTags Tags { get; } + /// + /// Gets flags related to this role. + /// + RoleFlags Flags { get; } + /// /// Modifies this role. /// diff --git a/src/Discord.Net.Core/Entities/Roles/RoleFlags.cs b/src/Discord.Net.Core/Entities/Roles/RoleFlags.cs new file mode 100644 index 00000000..0ed8f12c --- /dev/null +++ b/src/Discord.Net.Core/Entities/Roles/RoleFlags.cs @@ -0,0 +1,17 @@ +using System; + +namespace Discord; + +[Flags] +public enum RoleFlags +{ + /// + /// The role has no flags. + /// + None = 0, + + /// + /// Indicates that the role can be selected by members in an onboarding. + /// + InPrompt = 1 << 0, +} diff --git a/src/Discord.Net.Rest/API/Common/Attachment.cs b/src/Discord.Net.Rest/API/Common/Attachment.cs index e26cddb5..0cb858af 100644 --- a/src/Discord.Net.Rest/API/Common/Attachment.cs +++ b/src/Discord.Net.Rest/API/Common/Attachment.cs @@ -1,32 +1,45 @@ using Newtonsoft.Json; -namespace Discord.API +namespace Discord.API; + +internal class Attachment { - internal class Attachment - { - [JsonProperty("id")] - public ulong Id { get; set; } - [JsonProperty("filename")] - public string Filename { get; set; } - [JsonProperty("description")] - public Optional Description { get; set; } - [JsonProperty("content_type")] - public Optional ContentType { get; set; } - [JsonProperty("size")] - public int Size { get; set; } - [JsonProperty("url")] - public string Url { get; set; } - [JsonProperty("proxy_url")] - public string ProxyUrl { get; set; } - [JsonProperty("height")] - public Optional Height { get; set; } - [JsonProperty("width")] - public Optional Width { get; set; } - [JsonProperty("ephemeral")] - public Optional Ephemeral { get; set; } - [JsonProperty("duration_secs")] - public Optional DurationSeconds { get; set; } - [JsonProperty("waveform")] - public Optional Waveform { get; set; } - } + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("filename")] + public string Filename { get; set; } + + [JsonProperty("description")] + public Optional Description { get; set; } + + [JsonProperty("content_type")] + public Optional ContentType { get; set; } + + [JsonProperty("size")] + public int Size { get; set; } + + [JsonProperty("url")] + public string Url { get; set; } + + [JsonProperty("proxy_url")] + public string ProxyUrl { get; set; } + + [JsonProperty("height")] + public Optional Height { get; set; } + + [JsonProperty("width")] + public Optional Width { get; set; } + + [JsonProperty("ephemeral")] + public Optional Ephemeral { get; set; } + + [JsonProperty("duration_secs")] + public Optional DurationSeconds { get; set; } + + [JsonProperty("waveform")] + public Optional Waveform { get; set; } + + [JsonProperty("flags")] + public Optional Flags { get; set; } } diff --git a/src/Discord.Net.Rest/API/Common/Role.cs b/src/Discord.Net.Rest/API/Common/Role.cs index 81f54ccc..c8564004 100644 --- a/src/Discord.Net.Rest/API/Common/Role.cs +++ b/src/Discord.Net.Rest/API/Common/Role.cs @@ -1,30 +1,42 @@ using Newtonsoft.Json; -namespace Discord.API +namespace Discord.API; + +internal class Role { - internal class Role - { - [JsonProperty("id")] - public ulong Id { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("icon")] - public Optional Icon { get; set; } - [JsonProperty("unicode_emoji")] - public Optional Emoji { get; set; } - [JsonProperty("color")] - public uint Color { get; set; } - [JsonProperty("hoist")] - public bool Hoist { get; set; } - [JsonProperty("mentionable")] - public bool Mentionable { get; set; } - [JsonProperty("position")] - public int Position { get; set; } - [JsonProperty("permissions"), Int53] - public string Permissions { get; set; } - [JsonProperty("managed")] - public bool Managed { get; set; } - [JsonProperty("tags")] - public Optional Tags { get; set; } - } + [JsonProperty("id")] + public ulong Id { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("icon")] + public Optional Icon { get; set; } + + [JsonProperty("unicode_emoji")] + public Optional Emoji { get; set; } + + [JsonProperty("color")] + public uint Color { get; set; } + + [JsonProperty("hoist")] + public bool Hoist { get; set; } + + [JsonProperty("mentionable")] + public bool Mentionable { get; set; } + + [JsonProperty("position")] + public int Position { get; set; } + + [JsonProperty("permissions"), Int53] + public string Permissions { get; set; } + + [JsonProperty("managed")] + public bool Managed { get; set; } + + [JsonProperty("tags")] + public Optional Tags { get; set; } + + [JsonProperty("flags")] + public RoleFlags Flags { get; set; } } diff --git a/src/Discord.Net.Rest/Entities/Messages/Attachment.cs b/src/Discord.Net.Rest/Entities/Messages/Attachment.cs index fef5207d..0c425126 100644 --- a/src/Discord.Net.Rest/Entities/Messages/Attachment.cs +++ b/src/Discord.Net.Rest/Entities/Messages/Attachment.cs @@ -32,8 +32,11 @@ namespace Discord /// public double? Duration { get; } + /// + public AttachmentFlags Flags { get; } + internal Attachment(ulong id, string filename, string url, string proxyUrl, int size, int? height, int? width, - bool? ephemeral, string description, string contentType, double? duration, string waveform) + bool? ephemeral, string description, string contentType, double? duration, string waveform, AttachmentFlags flags) { Id = id; Filename = filename; @@ -47,6 +50,7 @@ namespace Discord ContentType = contentType; Duration = duration; Waveform = waveform; + Flags = flags; } internal static Attachment Create(Model model) { @@ -56,7 +60,8 @@ namespace Discord model.Ephemeral.ToNullable(), model.Description.GetValueOrDefault(), model.ContentType.GetValueOrDefault(), model.DurationSeconds.IsSpecified ? model.DurationSeconds.Value : null, - model.Waveform.GetValueOrDefault(null)); + model.Waveform.GetValueOrDefault(null), + model.Flags.GetValueOrDefault(AttachmentFlags.None)); } /// diff --git a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs index df629bec..ef111a40 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs @@ -34,6 +34,9 @@ namespace Discord.Rest /// public RoleTags Tags { get; private set; } + /// + public RoleFlags Flags { get; private set; } + /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); /// @@ -63,6 +66,8 @@ namespace Discord.Rest Position = model.Position; Color = new Color(model.Color); Permissions = new GuildPermissions(model.Permissions); + Flags = model.Flags; + if (model.Tags.IsSpecified) Tags = model.Tags.Value.ToEntity(); diff --git a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs index a399f2c1..d5b52da0 100644 --- a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs +++ b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs @@ -44,6 +44,9 @@ namespace Discord.WebSocket /// public RoleTags Tags { get; private set; } + /// + public RoleFlags Flags { get; private set; } + /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); /// @@ -82,6 +85,8 @@ namespace Discord.WebSocket Position = model.Position; Color = new Color(model.Color); Permissions = new GuildPermissions(model.Permissions); + Flags = model.Flags; + if (model.Tags.IsSpecified) Tags = model.Tags.Value.ToEntity();