From 547719d99a52fc6dfe22468d655ccb2109eaa722 Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Tue, 29 Jan 2019 19:53:15 -0800 Subject: [PATCH] Move oauth-only user fields to SelfUser classes Moves the implementation of the Flags, PremiumType, and Locale user fields to ISelfUser classes. In testing, it seemed that normal bot accounts did not have this information supplied to them. When tested with a Bearer token in the Rest client, these fields are set. --- .../Entities/Users/ISelfUser.cs | 28 ++++++++++++++++++ src/Discord.Net.Core/Entities/Users/IUser.cs | 29 ------------------- src/Discord.Net.Rest/API/Common/User.cs | 2 +- .../Entities/Users/RestSelfUser.cs | 12 ++++++++ .../Entities/Users/RestUser.cs | 12 -------- .../Entities/Users/SocketSelfUser.cs | 21 ++++++++++++++ .../Entities/Users/SocketUser.cs | 21 -------------- 7 files changed, 62 insertions(+), 63 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Users/ISelfUser.cs b/src/Discord.Net.Core/Entities/Users/ISelfUser.cs index c1d7874eb..04c655212 100644 --- a/src/Discord.Net.Core/Entities/Users/ISelfUser.cs +++ b/src/Discord.Net.Core/Entities/Users/ISelfUser.cs @@ -26,6 +26,34 @@ namespace Discord /// true if this user has enabled multi-factor authentication on their account; false if not. /// bool IsMfaEnabled { get; } + /// + /// Gets the flags that are applied to a user's account. + /// + /// + /// This value is determined by bitwise OR-ing values together. + /// + /// + /// The value of flags for this user. + /// + UserProperties Flags { get; } + /// + /// Gets the type of Nitro subscription that is active on this user's account. + /// + /// + /// This information may only be available with the identify OAuth scope. + /// + /// + /// The type of Nitro subscription the user subscribes to, if any. + /// + PremiumType PremiumType { get; } + /// + /// Gets the user's chosen language option. + /// + /// + /// The IETF language tag of the user's chosen region, if provided. + /// For example, a locale of "English, US" is "en-US", "Chinese (Taiwan)" is "zh-TW", etc. + /// + string Locale { get; } /// /// Modifies the user's properties. diff --git a/src/Discord.Net.Core/Entities/Users/IUser.cs b/src/Discord.Net.Core/Entities/Users/IUser.cs index 99f709717..5d7d0a0b0 100644 --- a/src/Discord.Net.Core/Entities/Users/IUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IUser.cs @@ -112,34 +112,5 @@ namespace Discord /// contains the DM channel associated with this user. /// Task GetOrCreateDMChannelAsync(RequestOptions options = null); - /// - /// Gets the flags that are applied to a user's account. - /// - /// - /// This value is determined by bitwise OR-ing values together. - /// - /// - /// The value of flags for this user. - /// - UserProperties Flags { get; } - /// - /// Gets the type of Nitro subscription that is active on this user's account. - /// - /// - /// This information may only be available with the identify OAuth scope, - /// meaning that users and bots will not have access to this information. - /// - /// - /// The type of Nitro subscription the user subscribes to, or null if this value could not be determined. - /// - PremiumType? PremiumType { get; } - /// - /// Gets the user's chosen language option. - /// - /// - /// The IETF language tag of the user's chosen region, if provided. - /// For example, a locale of "English, US" is "en-US", "Chinese (Taiwan)" is "zh-TW", etc. - /// - string Locale { get; } } } diff --git a/src/Discord.Net.Rest/API/Common/User.cs b/src/Discord.Net.Rest/API/Common/User.cs index e1a5d2915..2eff3753d 100644 --- a/src/Discord.Net.Rest/API/Common/User.cs +++ b/src/Discord.Net.Rest/API/Common/User.cs @@ -24,7 +24,7 @@ namespace Discord.API [JsonProperty("mfa_enabled")] public Optional MfaEnabled { get; set; } [JsonProperty("flags")] - public Optional Flags { get; set; } + public Optional Flags { get; set; } [JsonProperty("premium_type")] public Optional PremiumType { get; set; } [JsonProperty("locale")] diff --git a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs index 7f3a3faa8..b5ef01c53 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs @@ -17,6 +17,12 @@ namespace Discord.Rest public bool IsVerified { get; private set; } /// public bool IsMfaEnabled { get; private set; } + /// + public UserProperties Flags { get; private set; } + /// + public PremiumType PremiumType { get; private set; } + /// + public string Locale { get; private set; } internal RestSelfUser(BaseDiscordClient discord, ulong id) : base(discord, id) @@ -39,6 +45,12 @@ namespace Discord.Rest IsVerified = model.Verified.Value; if (model.MfaEnabled.IsSpecified) IsMfaEnabled = model.MfaEnabled.Value; + if (model.Flags.IsSpecified) + Flags = (UserProperties)model.Flags.Value; + if (model.PremiumType.IsSpecified) + PremiumType = model.PremiumType.Value; + if (model.Locale.IsSpecified) + Locale = model.Locale.Value; } /// diff --git a/src/Discord.Net.Rest/Entities/Users/RestUser.cs b/src/Discord.Net.Rest/Entities/Users/RestUser.cs index ffcd67681..6af5b5c95 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestUser.cs @@ -32,12 +32,6 @@ namespace Discord.Rest public virtual UserStatus Status => UserStatus.Offline; /// public virtual bool IsWebhook => false; - /// - public UserProperties Flags { get; private set; } - /// - public PremiumType? PremiumType { get; private set; } - /// - public string Locale { get; private set; } internal RestUser(BaseDiscordClient discord, ulong id) : base(discord, id) @@ -65,12 +59,6 @@ namespace Discord.Rest IsBot = model.Bot.Value; if (model.Username.IsSpecified) Username = model.Username.Value; - if (model.Flags.IsSpecified) - Flags = (UserProperties) model.Flags.Value; - if (model.PremiumType.IsSpecified) - PremiumType = model.PremiumType.Value; - if (model.Locale.IsSpecified) - Locale = model.Locale.Value; } /// diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs index ae705109c..7b11257a3 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs @@ -30,6 +30,12 @@ namespace Discord.WebSocket public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } } /// internal override SocketPresence Presence { get { return GlobalUser.Presence; } set { GlobalUser.Presence = value; } } + /// + public UserProperties Flags { get; internal set; } + /// + public PremiumType PremiumType { get; internal set; } + /// + public string Locale { get; internal set; } /// public override bool IsWebhook => false; @@ -63,6 +69,21 @@ namespace Discord.WebSocket IsMfaEnabled = model.MfaEnabled.Value; hasGlobalChanges = true; } + if (model.Flags.IsSpecified && model.Flags.Value != Flags) + { + Flags = (UserProperties)model.Flags.Value; + hasGlobalChanges = true; + } + if (model.PremiumType.IsSpecified && model.PremiumType.Value != PremiumType) + { + PremiumType = model.PremiumType.Value; + hasGlobalChanges = true; + } + if (model.Locale.IsSpecified && model.Locale.Value != Locale) + { + Locale = model.Locale.Value; + hasGlobalChanges = true; + } return hasGlobalChanges; } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 818c8f269..4832e7311 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -38,12 +38,6 @@ namespace Discord.WebSocket public IActivity Activity => Presence.Activity; /// public UserStatus Status => Presence.Status; - /// - public UserProperties Flags { get; internal set; } - /// - public PremiumType? PremiumType { get; internal set; } - /// - public string Locale { get; internal set; } /// /// Gets mutual guilds shared with this user. /// @@ -81,21 +75,6 @@ namespace Discord.WebSocket Username = model.Username.Value; hasChanges = true; } - if (model.Flags.IsSpecified && model.Flags.Value != (int) Flags) - { - Flags = (UserProperties) model.Flags.Value; - hasChanges = true; - } - if (model.PremiumType.IsSpecified && model.PremiumType.Value != PremiumType) - { - PremiumType = model.PremiumType.Value; - hasChanges = true; - } - if (model.Locale.IsSpecified && model.Locale.Value != Locale) - { - Locale = model.Locale.Value; - hasChanges = true; - } return hasChanges; }