Skip to content

Commit

Permalink
[Feature] Add support for Guild Member Flags (#2571)
Browse files Browse the repository at this point in the history
* implement `GuildUserFlags`

Co-authored-by: Casmir <68127614+csmir@users.noreply.github.com>
  • Loading branch information
Misha-133 and csmir committed Jan 23, 2023
1 parent 94996e7 commit 7d8d6ec
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/Discord.Net.Core/Entities/Users/GuildUserFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Discord;


/// <summary>
/// Represents public flags for a guild member.
/// </summary>
public enum GuildUserFlags
{
/// <summary>
/// Member has no flags set.
/// </summary>
None = 0,

/// <summary>
/// Member has left and rejoined the guild.
/// </summary>
/// <remarks>
/// Cannot be modified.
/// </remarks>
DidRejoin = 1 << 0,

/// <summary>
/// Member has completed onboarding.
/// </summary>
/// <remarks>
/// Cannot be modified.
/// </remarks>
CompletedOnboarding = 1 << 1,

/// <summary>
/// Member bypasses guild verification requirements.
/// </summary>
BypassesVerification = 1 << 2,

/// <summary>
/// Member has started onboarding.
/// </summary>
/// <remarks>
/// Cannot be modified.
/// </remarks>
StartedOnboarding = 1 << 3,
}
8 changes: 8 additions & 0 deletions src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,13 @@ public class GuildUserProperties
/// <see langword="null"/> or a time in the past to clear a currently existing timeout.
/// </remarks>
public Optional<DateTimeOffset?> TimedOutUntil { get; set; }

/// <summary>
/// Gets or sets the flags of the guild member.
/// </summary>
/// <remarks>
/// Not all flags can be modified, these are reserved for Discord.
/// </remarks>
public Optional<GuildUserFlags> Flags { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Discord.Net.Core/Entities/Users/IGuildUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public interface IGuildUser : IUser, IVoiceState
/// </returns>
DateTimeOffset? TimedOutUntil { get; }

/// <summary>
/// Gets the public flags for this guild member.
/// </summary>
GuildUserFlags Flags { get; }

/// <summary>
/// Gets the level permissions granted to this user to a given channel.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Discord.Net.Rest/API/Common/GuildMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ internal class GuildMember
public Optional<DateTimeOffset?> PremiumSince { get; set; }
[JsonProperty("communication_disabled_until")]
public Optional<DateTimeOffset?> TimedOutUntil { get; set; }

[JsonProperty("flags")]
public GuildUserFlags Flags { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ internal class ModifyGuildMemberParams
public Optional<ulong?> ChannelId { get; set; }
[JsonProperty("communication_disabled_until")]
public Optional<DateTimeOffset?> TimedOutUntil { get; set; }

[JsonProperty("flags")]
public Optional<GuildUserFlags> Flags { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public class RestGuildUser : RestUser, IGuildUser
public ulong GuildId { get; }
/// <inheritdoc />
public bool? IsPending { get; private set; }

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

/// <inheritdoc />
public int Hierarchy
{
Expand Down Expand Up @@ -114,6 +118,7 @@ internal void Update(Model model)
_timedOutTicks = model.TimedOutUntil.Value?.UtcTicks;
if (model.Pending.IsSpecified)
IsPending = model.Pending.Value;
Flags = model.Flags;
}
private void UpdateRoles(ulong[] roleIds)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ IGuild IGuildUser.Guild
DateTimeOffset? IGuildUser.TimedOutUntil => null;
/// <inheritdoc />
GuildPermissions IGuildUser.GuildPermissions => GuildPermissions.Webhook;
/// <inheritdoc />
GuildUserFlags IGuildUser.Flags => GuildUserFlags.None;

/// <inheritdoc />
ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue);
Expand Down
3 changes: 2 additions & 1 deletion src/Discord.Net.Rest/Entities/Users/UserHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ internal static class UserHelper
Deaf = args.Deaf,
Mute = args.Mute,
Nickname = args.Nickname,
TimedOutUntil = args.TimedOutUntil
TimedOutUntil = args.TimedOutUntil,
Flags = args.Flags
};

if (args.Channel.IsSpecified)
Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class SocketGuildUser : SocketUser, IGuildUser
/// <inheritdoc />
public bool? IsPending { get; private set; }

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

/// <inheritdoc />
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks);
Expand Down Expand Up @@ -179,6 +181,8 @@ internal void Update(ClientState state, MemberModel model)
_timedOutTicks = model.TimedOutUntil.Value?.UtcTicks;
if (model.Pending.IsSpecified)
IsPending = model.Pending.Value;

Flags = model.Flags;
}
internal void Update(ClientState state, PresenceModel model, bool updatePresence)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public bool IsStreaming
public bool IsVideoing
=> GuildUser.IsVideoing;

/// <inheritdoc/>
public GuildUserFlags Flags
=> GuildUser.Flags;

/// <inheritdoc/>
public DateTimeOffset? RequestToSpeakTimestamp
=> GuildUser.RequestToSpeakTimestamp;
Expand Down
2 changes: 2 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ internal static SocketWebhookUser Create(SocketGuild guild, ClientState state, M
int IGuildUser.Hierarchy => 0;
/// <inheritdoc />
GuildPermissions IGuildUser.GuildPermissions => GuildPermissions.Webhook;
/// <inheritdoc />
GuildUserFlags IGuildUser.Flags => GuildUserFlags.None;

/// <inheritdoc />
ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue);
Expand Down

0 comments on commit 7d8d6ec

Please sign in to comment.