Skip to content

Commit

Permalink
feature: Add user public flags (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
SubZero0 authored Dec 23, 2020
1 parent 6a62c47 commit c683b29
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/Discord.Net.Core/Entities/Users/IUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public interface IUser : ISnowflakeEntity, IMentionable, IPresence
/// Gets the username for this user.
/// </summary>
string Username { get; }
/// <summary>
/// Gets the public flags that are applied to this user's account.
/// </summary>
/// <remarks>
/// This value is determined by bitwise OR-ing <see cref="UserProperties"/> values together.
/// </remarks>
/// <returns>
/// The value of public flags for this user.
/// </returns>
UserProperties? PublicFlags { get; }

/// <summary>
/// Gets the direct message channel of this user, or create one if it does not already exist.
Expand Down
48 changes: 39 additions & 9 deletions src/Discord.Net.Core/Entities/Users/UserProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,62 @@ public enum UserProperties
/// </summary>
None = 0,
/// <summary>
/// Flag given to Discord staff.
/// Flag given to users who are a Discord employee.
/// </summary>
Staff = 0b1,
Staff = 1 << 0,
/// <summary>
/// Flag given to Discord partners.
/// Flag given to users who are owners of a partnered Discord server.
/// </summary>
Partner = 0b10,
Partner = 1 << 1,
/// <summary>
/// Flag given to users in HypeSquad events.
/// </summary>
HypeSquadEvents = 1 << 2,
/// <summary>
/// Flag given to users who have participated in the bug report program.
/// This flag is obsolete, use <see cref="BugHunterLevel1"/> instead.
/// </summary>
[Obsolete("Use BugHunterLevel1 instead.")]
BugHunter = 1 << 3,
/// <summary>
/// Flag given to users who have participated in the bug report program and are level 1.
/// </summary>
BugHunter = 0b1000,
BugHunterLevel1 = 1 << 3,
/// <summary>
/// Flag given to users who are in the HypeSquad House of Bravery.
/// </summary>
HypeSquadBravery = 0b100_0000,
HypeSquadBravery = 1 << 6,
/// <summary>
/// Flag given to users who are in the HypeSquad House of Brilliance.
/// </summary>
HypeSquadBrilliance = 0b1000_0000,
HypeSquadBrilliance = 1 << 7,
/// <summary>
/// Flag given to users who are in the HypeSquad House of Balance.
/// </summary>
HypeSquadBalance = 0b1_0000_0000,
HypeSquadBalance = 1 << 8,
/// <summary>
/// Flag given to users who subscribed to Nitro before games were added.
/// </summary>
EarlySupporter = 0b10_0000_0000,
EarlySupporter = 1 << 9,
/// <summary>
/// Flag given to users who are part of a team.
/// </summary>
TeamUser = 1 << 10,
/// <summary>
/// Flag given to users who represent Discord (System).
/// </summary>
System = 1 << 12,
/// <summary>
/// Flag given to users who have participated in the bug report program and are level 2.
/// </summary>
BugHunterLevel2 = 1 << 14,
/// <summary>
/// Flag given to users who are verified bots.
/// </summary>
VerifiedBot = 1 << 16,
/// <summary>
/// Flag given to users that developed bots and early verified their accounts.
/// </summary>
EarlyVerifiedBotDeveloper = 1 << 17,
}
}
2 changes: 2 additions & 0 deletions src/Discord.Net.Rest/API/Common/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ internal class User
public Optional<PremiumType> PremiumType { get; set; }
[JsonProperty("locale")]
public Optional<string> Locale { get; set; }
[JsonProperty("public_flags")]
public Optional<UserProperties> PublicFlags { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/RestUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class RestUser : RestEntity<ulong>, IUser, IUpdateable
public ushort DiscriminatorValue { get; private set; }
/// <inheritdoc />
public string AvatarId { get; private set; }
/// <inheritdoc />
public UserProperties? PublicFlags { get; private set; }

/// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
Expand Down Expand Up @@ -65,6 +67,8 @@ internal virtual void Update(Model model)
IsBot = model.Bot.Value;
if (model.Username.IsSpecified)
Username = model.Username.Value;
if (model.PublicFlags.IsSpecified)
PublicFlags = model.PublicFlags.Value;
}

/// <inheritdoc />
Expand Down
7 changes: 7 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public abstract class SocketUser : SocketEntity<ulong>, IUser
public abstract string AvatarId { get; internal set; }
/// <inheritdoc />
public abstract bool IsWebhook { get; }
/// <inheritdoc />
public UserProperties? PublicFlags { get; private set; }
internal abstract SocketGlobalUser GlobalUser { get; }
internal abstract SocketPresence Presence { get; set; }

Expand Down Expand Up @@ -83,6 +85,11 @@ internal virtual bool Update(ClientState state, Model model)
Username = model.Username.Value;
hasChanges = true;
}
if (model.PublicFlags.IsSpecified && model.PublicFlags.Value != PublicFlags)
{
PublicFlags = model.PublicFlags.Value;
hasChanges = true;
}
return hasChanges;
}

Expand Down

0 comments on commit c683b29

Please sign in to comment.