/// <inheritdoc /> internal override void Update(Model model) { base.Update(model); if (model.Email.IsSpecified) { Email = model.Email.Value; } if (model.Verified.IsSpecified) { 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; } }
internal virtual bool Update(ClientState state, Model model) { bool hasChanges = false; if (model.Avatar.IsSpecified && model.Avatar.Value != AvatarId) { AvatarId = model.Avatar.Value; hasChanges = true; } if (model.Discriminator.IsSpecified) { ushort newVal = ushort.Parse(model.Discriminator.Value, NumberStyles.None, CultureInfo.InvariantCulture); if (newVal != DiscriminatorValue) { DiscriminatorValue = ushort.Parse(model.Discriminator.Value, NumberStyles.None, CultureInfo.InvariantCulture); hasChanges = true; } } if (model.Bot.IsSpecified && model.Bot.Value != IsBot) { IsBot = model.Bot.Value; hasChanges = true; } if (model.Username.IsSpecified && model.Username.Value != Username) { Username = model.Username.Value; hasChanges = true; } if (model.PublicFlags.IsSpecified && model.PublicFlags.Value != PublicFlags) { PublicFlags = model.PublicFlags.Value; hasChanges = true; } return(hasChanges); }
internal new static RestGroupUser Create(BaseDiscordClient discord, Model model) { RestGroupUser entity = new RestGroupUser(discord, model.Id); entity.Update(model); return(entity); }
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, UserModel model) { SocketGuildUser entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model)); entity.Update(state, model); entity.UpdateRoles(new ulong[0]); return(entity); }
/// <inheritdoc /> /// <exception cref="InvalidOperationException">Unable to modify this object using a different token.</exception> public async Task ModifyAsync(Action <SelfUserProperties> func, RequestOptions options = null) { if (Id != Discord.CurrentUser.Id) { throw new InvalidOperationException("Unable to modify this object using a different token."); } Model model = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); }
/// <inheritdoc /> /// <exception cref="InvalidOperationException">Unable to update this object using a different token.</exception> public override async Task UpdateAsync(RequestOptions options = null) { Model model = await Discord.ApiClient.GetMyUserAsync(options).ConfigureAwait(false); if (model.Id != Id) { throw new InvalidOperationException("Unable to update this object using a different token."); } Update(model); }
internal SocketGroupUser GetOrAddUser(UserModel model) { if (_users.TryGetValue(model.Id, out SocketGroupUser user)) { return(user); } else { SocketGroupUser privateUser = SocketGroupUser.Create(this, Discord.State, model); privateUser.GlobalUser.AddRef(); _users[privateUser.Id] = privateUser; return(privateUser); } }
//Helpers private static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong?webhookId) { IUser author = null; if (guild != null) { author = guild.GetUserAsync(model.Id, CacheMode.CacheOnly).Result; } if (author == null) { author = RestUser.Create(client, guild, model, webhookId); } return(author); }
internal static RestUser Create(BaseDiscordClient discord, IGuild guild, Model model, ulong?webhookId) { RestUser entity; if (webhookId.HasValue) { entity = new RestWebhookUser(discord, guild, model.Id, webhookId.Value); } else { entity = new RestUser(discord, model.Id); } entity.Update(model); return(entity); }
internal virtual void Update(Model model) { if (model.Avatar.IsSpecified) { AvatarId = model.Avatar.Value; } if (model.Discriminator.IsSpecified) { DiscriminatorValue = ushort.Parse(model.Discriminator.Value, NumberStyles.None, CultureInfo.InvariantCulture); } if (model.Bot.IsSpecified) { IsBot = model.Bot.Value; } if (model.Username.IsSpecified) { Username = model.Username.Value; } if (model.PublicFlags.IsSpecified) { PublicFlags = model.PublicFlags.Value; } }
internal override bool Update(ClientState state, Model model) { bool hasGlobalChanges = base.Update(state, model); if (model.Email.IsSpecified) { Email = model.Email.Value; hasGlobalChanges = true; } if (model.Verified.IsSpecified) { IsVerified = model.Verified.Value; hasGlobalChanges = true; } if (model.MfaEnabled.IsSpecified) { 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); }
internal static SocketSelfUser Create(DiscordSocketClient discord, ClientState state, Model model) { SocketSelfUser entity = new SocketSelfUser(discord, discord.GetOrCreateSelfUser(state, model)); entity.Update(state, model); return(entity); }
internal static RestWebhookUser Create(BaseDiscordClient discord, IGuild guild, Model model, ulong webhookId) { RestWebhookUser entity = new RestWebhookUser(discord, guild, model.Id, webhookId); entity.Update(model); return(entity); }
internal static SocketWebhookUser Create(SocketGuild guild, ClientState state, Model model, ulong webhookId) { SocketWebhookUser entity = new SocketWebhookUser(guild, model.Id, webhookId); entity.Update(state, model); return(entity); }
internal static RestUser Create(BaseDiscordClient discord, Model model) => Create(discord, null, model, null);
/// <inheritdoc /> public virtual async Task UpdateAsync(RequestOptions options = null) { Model model = await Discord.ApiClient.GetUserAsync(Id, options).ConfigureAwait(false); Update(model); }
internal static SocketUnknownUser Create(DiscordSocketClient discord, ClientState state, Model model) { SocketUnknownUser entity = new SocketUnknownUser(discord, model.Id); entity.Update(state, model); return(entity); }
internal static SocketGroupUser Create(SocketGroupChannel channel, ClientState state, Model model) { SocketGroupUser entity = new SocketGroupUser(channel, channel.Discord.GetOrCreateUser(state, model)); entity.Update(state, model); return(entity); }