Skip to content

Commit

Permalink
[Feature] Add Role & Attachment flags (#2720)
Browse files Browse the repository at this point in the history
* initial commit

* oops

* another typo -_-

* Update AttachmentFlags.cs

Made this on my phone lol

* Update AttachmentFlags.cs

* -line
  • Loading branch information
Misha-133 authored Aug 10, 2023
1 parent 8cd4c1c commit a421715
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 56 deletions.
27 changes: 27 additions & 0 deletions src/Discord.Net.Core/Entities/Messages/AttachmentFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

namespace Discord;

[Flags]
public enum AttachmentFlags
{
/// <summary>
/// The attachment has no flags.
/// </summary>
None = 0,

/// <summary>
/// Indicates that this attachment is a clip.
/// </summary>
IsClip = 1 << 0,

/// <summary>
/// Indicates that this attachment is a thumbnail.
/// </summary>
IsThumbnail = 1 << 1,

/// <summary>
/// Indicates that this attachment has been edited using the remix feature on mobile.
/// </summary>
IsRemix = 1 << 2,
}
5 changes: 5 additions & 0 deletions src/Discord.Net.Core/Entities/Messages/IAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,10 @@ public interface IAttachment
/// Gets the base64 encoded bytearray representing a sampled waveform. <see langword="null"/> if the attachment is not a voice message.
/// </summary>
public string Waveform { get; }

/// <summary>
/// Gets flags related to this to this attachment.
/// </summary>
public AttachmentFlags Flags { get; }
}
}
5 changes: 5 additions & 0 deletions src/Discord.Net.Core/Entities/Roles/IRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable
/// </returns>
RoleTags Tags { get; }

/// <summary>
/// Gets flags related to this role.
/// </summary>
RoleFlags Flags { get; }

/// <summary>
/// Modifies this role.
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions src/Discord.Net.Core/Entities/Roles/RoleFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace Discord;

[Flags]
public enum RoleFlags
{
/// <summary>
/// The role has no flags.
/// </summary>
None = 0,

/// <summary>
/// Indicates that the role can be selected by members in an onboarding.
/// </summary>
InPrompt = 1 << 0,
}
69 changes: 41 additions & 28 deletions src/Discord.Net.Rest/API/Common/Attachment.cs
Original file line number Diff line number Diff line change
@@ -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<string> Description { get; set; }
[JsonProperty("content_type")]
public Optional<string> 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<int> Height { get; set; }
[JsonProperty("width")]
public Optional<int> Width { get; set; }
[JsonProperty("ephemeral")]
public Optional<bool> Ephemeral { get; set; }
[JsonProperty("duration_secs")]
public Optional<double> DurationSeconds { get; set; }
[JsonProperty("waveform")]
public Optional<string> Waveform { get; set; }
}
[JsonProperty("id")]
public ulong Id { get; set; }

[JsonProperty("filename")]
public string Filename { get; set; }

[JsonProperty("description")]
public Optional<string> Description { get; set; }

[JsonProperty("content_type")]
public Optional<string> 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<int> Height { get; set; }

[JsonProperty("width")]
public Optional<int> Width { get; set; }

[JsonProperty("ephemeral")]
public Optional<bool> Ephemeral { get; set; }

[JsonProperty("duration_secs")]
public Optional<double> DurationSeconds { get; set; }

[JsonProperty("waveform")]
public Optional<string> Waveform { get; set; }

[JsonProperty("flags")]
public Optional<AttachmentFlags> Flags { get; set; }
}
64 changes: 38 additions & 26 deletions src/Discord.Net.Rest/API/Common/Role.cs
Original file line number Diff line number Diff line change
@@ -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<string> Icon { get; set; }
[JsonProperty("unicode_emoji")]
public Optional<string> 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<RoleTags> Tags { get; set; }
}
[JsonProperty("id")]
public ulong Id { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("icon")]
public Optional<string> Icon { get; set; }

[JsonProperty("unicode_emoji")]
public Optional<string> 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<RoleTags> Tags { get; set; }

[JsonProperty("flags")]
public RoleFlags Flags { get; set; }
}
9 changes: 7 additions & 2 deletions src/Discord.Net.Rest/Entities/Messages/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public class Attachment : IAttachment
/// <inheritdoc />
public double? Duration { get; }

/// <inheritdoc />
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;
Expand All @@ -47,6 +50,7 @@ internal Attachment(ulong id, string filename, string url, string proxyUrl, int
ContentType = contentType;
Duration = duration;
Waveform = waveform;
Flags = flags;
}
internal static Attachment Create(Model model)
{
Expand All @@ -56,7 +60,8 @@ internal static Attachment Create(Model model)
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));
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Discord.Net.Rest/Entities/Roles/RestRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class RestRole : RestEntity<ulong>, IRole
/// <inheritdoc />
public RoleTags Tags { get; private set; }

/// <inheritdoc />
public RoleFlags Flags { get; private set; }

/// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
/// <summary>
Expand Down Expand Up @@ -63,6 +66,8 @@ internal void Update(Model model)
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();

Expand Down
5 changes: 5 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class SocketRole : SocketEntity<ulong>, IRole
/// <inheritdoc />
public RoleTags Tags { get; private set; }

/// <inheritdoc />
public RoleFlags Flags { get; private set; }

/// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
/// <summary>
Expand Down Expand Up @@ -82,6 +85,8 @@ internal void Update(ClientState state, Model model)
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();

Expand Down

0 comments on commit a421715

Please sign in to comment.