Пример #1
0
        /// <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;
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        internal new static RestGroupUser Create(BaseDiscordClient discord, Model model)
        {
            RestGroupUser entity = new RestGroupUser(discord, model.Id);

            entity.Update(model);
            return(entity);
        }
Пример #4
0
        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);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
 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);
     }
 }
Пример #8
0
        //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);
        }
Пример #9
0
        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);
        }
Пример #10
0
 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;
     }
 }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        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);
        }
Пример #15
0
 internal static RestUser Create(BaseDiscordClient discord, Model model)
 => Create(discord, null, model, null);
Пример #16
0
        /// <inheritdoc />
        public virtual async Task UpdateAsync(RequestOptions options = null)
        {
            Model model = await Discord.ApiClient.GetUserAsync(Id, options).ConfigureAwait(false);

            Update(model);
        }
Пример #17
0
        internal static SocketUnknownUser Create(DiscordSocketClient discord, ClientState state, Model model)
        {
            SocketUnknownUser entity = new SocketUnknownUser(discord, model.Id);

            entity.Update(state, model);
            return(entity);
        }
Пример #18
0
        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);
        }