Ejemplo n.º 1
0
        public void Update(DiscordApiData data)
        {
            Nickname = data.GetString("nick");
            JoinedAt = data.GetDateTime("joined_at").Value;
            IsDeaf   = data.GetBoolean("deaf") ?? false;
            IsMute   = data.GetBoolean("mute") ?? false;

            UpdateRoles(data);

            Dirty();
        }
Ejemplo n.º 2
0
        public void Update(DiscordApiData data)
        {
            Name            = data.GetString("name");
            Icon            = data.GetString("icon");
            Splash          = data.GetString("splash");
            RegionId        = data.GetString("region");
            AfkTimeout      = data.GetInteger("afk_timeout").Value;
            IsEmbedEnabled  = data.GetBoolean("embed_enabled") ?? false;
            OwnerId         = data.GetSnowflake("owner_id").Value;
            AfkChannelId    = data.GetSnowflake("afk_channel_id");
            EmbedChannelId  = data.GetSnowflake("embed_channel_id");
            ApplicationId   = data.GetSnowflake("application_id");
            IsWidgetEnabled = data.GetBoolean("widget_enabled") ?? false;
            WidgetChannelId = data.GetSnowflake("widget_channel_id");
            SystemChannelId = data.GetSnowflake("system_channel_id");

            ExplicitContentFilter       = (GuildExplicitContentFilterLevel)data.GetInteger("explicit_content_filter").Value;
            VerificationLevel           = (GuildVerificationLevel)data.GetInteger("verification_level").Value;
            DefaultMessageNotifications = (GuildNotificationOption)(data.GetInteger("default_message_notifications") ?? 0);
            MfaLevel = (GuildMfaLevel)data.GetInteger("mfa_level").Value;

            // Deserialize features
            IList <DiscordApiData> featuresArray = data.GetArray("features");
            List <string>          features      = new List <string>(featuresArray.Count);

            for (int i = 0; i < features.Count; i++)
            {
                features[i] = featuresArray[i].ToString();
            }

            Features = features;

            // Deserialize roles
            Roles.Clear();
            IList <DiscordApiData> rolesArray = data.GetArray("roles");

            for (int i = 0; i < rolesArray.Count; i++)
            {
                DiscordRole role = new DiscordRole(Http, Id, rolesArray[i]);
                Roles[role.Id] = role;
            }

            // Deserialize emojis
            Emojis.Clear();
            IList <DiscordApiData> emojisArray = data.GetArray("emojis");

            for (int i = 0; i < emojisArray.Count; i++)
            {
                DiscordEmoji emoji = new DiscordEmoji(emojisArray[i]);
                Emojis[emoji.Id] = emoji;
            }

            Dirty();
        }
Ejemplo n.º 3
0
 internal DiscordVoiceRegion(DiscordApiData data)
 {
     Id             = data.GetString("id");
     Name           = data.GetString("name");
     SampleHostname = data.GetString("sample_hostname");
     SamplePort     = data.GetInteger("sample_port").Value;
     IsVIPOnly      = data.GetBoolean("vip").Value;
     IsOptimal      = data.GetBoolean("optimal").Value;
     IsDeprecated   = data.GetBoolean("deprecated").Value;
     IsCustom       = data.GetBoolean("custom").Value;
 }
Ejemplo n.º 4
0
        internal DiscordVoiceState(Snowflake guildId, DiscordApiData data)
        {
            GuildId = guildId;

            ChannelId = data.GetSnowflake("channel_id");
            UserId    = data.GetSnowflake("user_id").Value;

            SessionId    = data.GetString("session_id");
            IsServerDeaf = data.GetBoolean("deaf").Value;
            IsServerMute = data.GetBoolean("mute").Value;
            IsSelfDeaf   = data.GetBoolean("self_deaf").Value;
            IsSelfMute   = data.GetBoolean("self_mute").Value;
            IsSuppressed = data.GetBoolean("suppress").Value;
        }
Ejemplo n.º 5
0
        public void PartialUpdate(DiscordApiData data)
        {
            Username         = data.GetString("username") ?? Username;
            Avatar           = data.GetString("avatar") ?? Avatar;
            HasTwoFactorAuth = data.GetBoolean("mfa_enabled") ?? HasTwoFactorAuth;
            IsVerified       = data.GetBoolean("verified") ?? IsVerified;
            Email            = data.GetString("email") ?? Email;

            // To avoid causing every entity that references this user to be unncessarily
            // dirtied, check to see if any properties actually changed with this update.
            if (Changed())
            {
                Dirty();
            }
        }
Ejemplo n.º 6
0
 internal DiscordGuildMetadata(DiscordApiData data)
 {
     GuildId     = data.GetSnowflake("id").Value;
     IsLarge     = data.GetBoolean("large") ?? false;
     JoinedAt    = data.GetDateTime("joined_at").Value;
     MemberCount = data.GetInteger("member_count").Value;
 }
Ejemplo n.º 7
0
        void HandleSpeaking(DiscordApiData payload, DiscordApiData data)
        {
            Snowflake userId     = data.GetSnowflake("user_id").Value;
            int       ssrc       = data.GetInteger("ssrc").Value;
            bool      isSpeaking = data.GetBoolean("speaking").Value;

            OnUserSpeaking?.Invoke(this, new VoiceSpeakingEventArgs(userId, ssrc, isSpeaking));
        }
Ejemplo n.º 8
0
        public void Update(DiscordApiData data)
        {
            Username         = data.GetString("username");
            Discriminator    = data.GetString("discriminator");
            Avatar           = data.GetString("avatar");
            IsBot            = data.GetBoolean("bot") ?? false;
            HasTwoFactorAuth = data.GetBoolean("mfa_enabled") ?? false;
            IsVerified       = data.GetBoolean("verified") ?? false;
            Email            = data.GetString("email");

            // To avoid causing every entity that references this user to be unncessarily
            // dirtied, check to see if any properties actually changed with this update.
            if (!initialized || Changed())
            {
                Dirty();
            }

            initialized = true;
        }
Ejemplo n.º 9
0
        internal DiscordReaction(DiscordApiData data)
        {
            Count = data.GetInteger("count").Value;
            Me    = data.GetBoolean("me").Value;

            DiscordApiData emojiData = data.Get("emoji");

            if (emojiData != null)
            {
                Emoji = new DiscordReactionEmoji(emojiData);
            }
        }
Ejemplo n.º 10
0
        internal DiscordUserGuild(DiscordApiData data)
            : base(data)
        {
            Name    = data.GetString("name");
            IsOwner = data.GetBoolean("owner").Value;

            string iconHash = data.GetString("icon");

            if (iconHash != null)
            {
                Icon = DiscordCdnUrl.ForGuildIcon(Id, iconHash);
            }

            long permissions = data.GetInt64("permissions").Value;

            Permissions = (DiscordPermission)permissions;
        }
Ejemplo n.º 11
0
        async Task HandleGuildDeleteEvent(DiscordApiData data)
        {
            Snowflake guildId     = data.GetSnowflake("id").Value;
            bool      unavailable = data.GetBoolean("unavailable") ?? false;

            if (unavailable)
            {
                // Tell the cache this guild is no longer available
                cache.SetGuildAvailability(guildId, false);

                if (cache.Guilds.TryGetValue(guildId, out MutableGuild mutableGuild))
                {
                    // Fire event
                    OnGuildUnavailable?.Invoke(this, new GuildEventArgs(shard, mutableGuild.ImmutableEntity));
                }
                else
                {
                    throw new ShardCacheException($"Guild {guildId} was not in the cache! unavailable = true");
                }
            }
            else
            {
                // Disconnect the voice connection for this guild if connected.
                if (shard.Voice.TryGetVoiceConnection(guildId, out DiscordVoiceConnection voiceConnection) &&
                    voiceConnection.IsConnected)
                {
                    CancellationTokenSource cts = new CancellationTokenSource();
                    cts.CancelAfter(5000);

                    await voiceConnection.DisconnectWithReasonAsync(VoiceConnectionInvalidationReason.BotRemovedFromGuild,
                                                                    cts.Token).ConfigureAwait(false);
                }

                // Clear all cache data related to the guild
                cache.GuildMetadata.TryRemove(guildId, out _);
                cache.GuildMembers.RemoveParent(guildId);
                cache.GuildPresences.RemoveParent(guildId);
                cache.GuildVoiceStates.RemoveParent(guildId);

                if (cache.GuildChannelIds.TryRemove(guildId, out ConcurrentHashSet <Snowflake> channelIds))
                {
                    foreach (Snowflake channelId in channelIds)
                    {
                        cache.GuildChannels.TryRemove(channelId, out _);
                    }
                }

                // Remove the guild from cache
                cache.RemoveGuildId(guildId);
                if (cache.Guilds.TryRemove(guildId, out MutableGuild mutableGuild))
                {
                    // Ensure all references are cleared
                    mutableGuild.ClearReferences();

                    // Fire event
                    OnGuildRemoved?.Invoke(this, new GuildEventArgs(shard, mutableGuild.ImmutableEntity));
                }
                else
                {
                    throw new ShardCacheException($"Guild {guildId} was not in the cache! unavailable = false");
                }
            }
        }
Ejemplo n.º 12
0
 internal DiscordEmbedField(DiscordApiData data)
 {
     Name     = data.GetString("name");
     Value    = data.GetString("value");
     IsInline = data.GetBoolean("inline").Value;
 }
Ejemplo n.º 13
0
 internal DiscordActivityEmoji(DiscordApiData data)
 {
     Name     = data.GetString("name");
     Id       = data.GetSnowflake("id");
     Animated = data.GetBoolean("animated") ?? false;
 }