Esempio n. 1
0
        internal static RestGuild Create(BaseDiscordClient discord, Model model)
        {
            var entity = new RestGuild(discord, model.Id);

            entity.Update(model);
            return(entity);
        }
Esempio n. 2
0
        public Guild(DiscordRestClient discord, Model model)
            : base(model.Id)
        {
            Discord = discord;

            Update(model, UpdateSource.Creation);
        }
Esempio n. 3
0
        internal void Update(Model model)
        {
            AFKChannelId                = model.AFKChannelId;
            EmbedChannelId              = model.EmbedChannelId;
            SystemChannelId             = model.SystemChannelId;
            AFKTimeout                  = model.AFKTimeout;
            IsEmbeddable                = model.EmbedEnabled;
            IconId                      = model.Icon;
            Name                        = model.Name;
            OwnerId                     = model.OwnerId;
            VoiceRegionId               = model.Region;
            SplashId                    = model.Splash;
            VerificationLevel           = model.VerificationLevel;
            MfaLevel                    = model.MfaLevel;
            DefaultMessageNotifications = model.DefaultMessageNotifications;
            ExplicitContentFilter       = model.ExplicitContentFilter;
            ApplicationId               = model.ApplicationId;
            PremiumTier                 = model.PremiumTier;
            VanityURLCode               = model.VanityURLCode;
            BannerId                    = model.Banner;
            SystemChannelFlags          = model.SystemChannelFlags;
            Description                 = model.Description;
            PremiumSubscriptionCount    = model.PremiumSubscriptionCount.GetValueOrDefault();

            if (model.Emojis != null)
            {
                var emotes = ImmutableArray.CreateBuilder <GuildEmote>(model.Emojis.Length);
                for (int i = 0; i < model.Emojis.Length; i++)
                {
                    emotes.Add(model.Emojis[i].ToEntity());
                }
                _emotes = emotes.ToImmutableArray();
            }
            else
            {
                _emotes = ImmutableArray.Create <GuildEmote>();
            }

            if (model.Features != null)
            {
                _features = model.Features.ToImmutableArray();
            }
            else
            {
                _features = ImmutableArray.Create <string>();
            }

            var roles = ImmutableDictionary.CreateBuilder <ulong, RestRole>();

            if (model.Roles != null)
            {
                for (int i = 0; i < model.Roles.Length; i++)
                {
                    roles[model.Roles[i].Id] = RestRole.Create(Discord, this, model.Roles[i]);
                }
            }
            _roles = roles.ToImmutable();

            Available = true;
        }
Esempio n. 4
0
        public void Update(Model model, UpdateSource source)
        {
            if (source == UpdateSource.Rest && IsAttached)
            {
                return;
            }

            AFKChannelId                = model.AFKChannelId;
            EmbedChannelId              = model.EmbedChannelId;
            AFKTimeout                  = model.AFKTimeout;
            IsEmbeddable                = model.EmbedEnabled;
            _iconId                     = model.Icon;
            Name                        = model.Name;
            OwnerId                     = model.OwnerId;
            VoiceRegionId               = model.Region;
            _splashId                   = model.Splash;
            VerificationLevel           = model.VerificationLevel;
            MfaLevel                    = model.MfaLevel;
            DefaultMessageNotifications = model.DefaultMessageNotifications;

            if (model.Emojis != null)
            {
                var emojis = ImmutableArray.CreateBuilder <Emoji>(model.Emojis.Length);
                for (int i = 0; i < model.Emojis.Length; i++)
                {
                    emojis.Add(new Emoji(model.Emojis[i]));
                }
                Emojis = emojis.ToImmutableArray();
            }
            else
            {
                Emojis = ImmutableArray.Create <Emoji>();
            }

            if (model.Features != null)
            {
                Features = model.Features.ToImmutableArray();
            }
            else
            {
                Features = ImmutableArray.Create <string>();
            }

            var roles = new ConcurrentDictionary <ulong, Role>(1, model.Roles?.Length ?? 0);

            if (model.Roles != null)
            {
                for (int i = 0; i < model.Roles.Length; i++)
                {
                    roles[model.Roles[i].Id] = new Role(this, model.Roles[i]);
                }
            }
            _roles = roles;
        }
Esempio n. 5
0
        internal void Update(ClientState state, Model model)
        {
            AFKChannelId                = model.AFKChannelId;
            EmbedChannelId              = model.EmbedChannelId;
            SystemChannelId             = model.SystemChannelId;
            AFKTimeout                  = model.AFKTimeout;
            IsEmbeddable                = model.EmbedEnabled;
            IconId                      = model.Icon;
            Name                        = model.Name;
            OwnerId                     = model.OwnerId;
            VoiceRegionId               = model.Region;
            SplashId                    = model.Splash;
            VerificationLevel           = model.VerificationLevel;
            MfaLevel                    = model.MfaLevel;
            DefaultMessageNotifications = model.DefaultMessageNotifications;

            if (model.Emojis != null)
            {
                var emojis = ImmutableArray.CreateBuilder <GuildEmote>(model.Emojis.Length);
                for (int i = 0; i < model.Emojis.Length; i++)
                {
                    emojis.Add(model.Emojis[i].ToEntity());
                }
                _emotes = emojis.ToImmutable();
            }
            else
            {
                _emotes = ImmutableArray.Create <GuildEmote>();
            }

            if (model.Features != null)
            {
                _features = model.Features.ToImmutableArray();
            }
            else
            {
                _features = ImmutableArray.Create <string>();
            }

            var roles = new ConcurrentDictionary <ulong, SocketRole>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Roles.Length * 1.05));

            if (model.Roles != null)
            {
                for (int i = 0; i < model.Roles.Length; i++)
                {
                    var role = SocketRole.Create(this, state, model.Roles[i]);
                    roles.TryAdd(role.Id, role);
                }
            }
            _roles = roles;
        }
Esempio n. 6
0
        internal void Update(Model model)
        {
            AFKChannelId                = model.AFKChannelId;
            EmbedChannelId              = model.EmbedChannelId;
            AFKTimeout                  = model.AFKTimeout;
            IsEmbeddable                = model.EmbedEnabled;
            IconId                      = model.Icon;
            Name                        = model.Name;
            OwnerId                     = model.OwnerId;
            VoiceRegionId               = model.Region;
            SplashId                    = model.Splash;
            VerificationLevel           = model.VerificationLevel;
            MfaLevel                    = model.MfaLevel;
            DefaultMessageNotifications = model.DefaultMessageNotifications;

            if (model.Emojis != null)
            {
                var emotes = ImmutableArray.CreateBuilder <GuildEmote>(model.Emojis.Length);
                for (int i = 0; i < model.Emojis.Length; i++)
                {
                    emotes.Add(model.Emojis[i].ToEntity());
                }
                _emotes = emotes.ToImmutableArray();
            }
            else
            {
                _emotes = ImmutableArray.Create <GuildEmote>();
            }

            if (model.Features != null)
            {
                _features = model.Features.ToImmutableArray();
            }
            else
            {
                _features = ImmutableArray.Create <string>();
            }

            var roles = ImmutableDictionary.CreateBuilder <ulong, RestRole>();

            if (model.Roles != null)
            {
                for (int i = 0; i < model.Roles.Length; i++)
                {
                    roles[model.Roles[i].Id] = RestRole.Create(Discord, this, model.Roles[i]);
                }
            }
            _roles = roles.ToImmutable();

            Available = true;
        }