internal DiscordGuildMember(DiscordHttpClient http, DiscordApiData data, Snowflake guildId) // We do not specify the base constructor here because the member ID must be // manually retrieved, as it is actually the user ID rather than a unique one. { this.http = http; GuildId = guildId; Nickname = data.GetString("nick"); JoinedAt = data.GetDateTime("joined_at").Value; IsDeaf = data.GetBoolean("deaf") ?? false; IsMute = data.GetBoolean("mute") ?? false; IList <DiscordApiData> rolesArray = data.GetArray("roles"); Snowflake[] roleIds = new Snowflake[rolesArray.Count]; for (int i = 0; i < rolesArray.Count; i++) { roleIds[i] = rolesArray[i].ToSnowflake().Value; } RoleIds = roleIds; DiscordApiData userData = data.Get("user"); User = new DiscordUser(false, userData); Id = User.Id; }
internal DiscordIntegration(DiscordHttpClient http, DiscordApiData data) : base(data) { this.http = http; Name = data.GetString("name"); Type = data.GetString("type"); IsEnabled = data.GetBoolean("enabled"); IsSyncing = data.GetBoolean("syncing"); ExpireBehavior = data.GetInteger("expire_behavior"); ExpireGracePeriod = data.GetInteger("expire_grace_period"); SyncedAt = data.GetDateTime("synced_at"); RoleId = data.GetSnowflake("role_id"); DiscordApiData userData = data.Get("user"); if (userData != null) { User = new DiscordUser(false, userData); } DiscordApiData accountData = data.Get("account"); if (accountData != null) { Account = new DiscordIntegrationAccount(accountData); } }
internal DiscordInviteMetadata(DiscordHttpClient http, DiscordApiData data) : base(http, data) { DiscordApiData inviterData = data.Get("inviter"); if (inviterData != null) { Inviter = new DiscordUser(false, inviterData); } Uses = data.GetInteger("uses").Value; MaxUses = data.GetInteger("max_uses").Value; MaxAge = data.GetInteger("max_age").Value; IsTemporary = data.GetBoolean("temporary").Value; CreatedAt = data.GetDateTime("created_at").Value; IsRevoked = data.GetBoolean("revoked") ?? false; }
internal DiscordMessageMember(DiscordApiData data) { Nickname = data.GetString("nick"); JoinedAt = data.GetDateTime("joined_at").Value; IsDeaf = data.GetBoolean("deaf") ?? false; IsMute = data.GetBoolean("mute") ?? false; IList <DiscordApiData> rolesArray = data.GetArray("roles"); if (rolesArray != null) { Snowflake[] roleIds = new Snowflake[rolesArray.Count]; for (int i = 0; i < rolesArray.Count; i++) { roleIds[i] = rolesArray[i].ToSnowflake().Value; } RoleIds = roleIds; } }
internal DiscordEmbed(DiscordApiData data) { Title = data.GetString("title"); Type = data.GetString("type"); Description = data.GetString("description"); Url = data.GetString("url"); Timestamp = data.GetDateTime("timestamp"); Color = data.GetInteger("color"); DiscordApiData footerData = data.Get("footer"); if (footerData != null) { Footer = new DiscordEmbedFooter(footerData); } DiscordApiData imageData = data.Get("image"); if (imageData != null) { Image = new DiscordEmbedImage(imageData); } DiscordApiData thumbnailData = data.Get("thumbnail"); if (thumbnailData != null) { Thumbnail = new DiscordEmbedThumbnail(thumbnailData); } DiscordApiData videoData = data.Get("video"); if (videoData != null) { Video = new DiscordEmbedVideo(videoData); } DiscordApiData providerData = data.Get("provider"); if (providerData != null) { Provider = new DiscordEmbedProvider(providerData); } DiscordApiData authorData = data.Get("author"); if (authorData != null) { Author = new DiscordEmbedAuthor(authorData); } IList <DiscordApiData> fieldArray = data.GetArray("fields"); if (fieldArray != null) { DiscordEmbedField[] fields = new DiscordEmbedField[fieldArray.Count]; for (int i = 0; i < fields.Length; i++) { fields[i] = new DiscordEmbedField(fieldArray[i]); } Fields = fields; } }
internal DiscordMessage(DiscordHttpClient http, DiscordApiData data) : base(data) { this.http = http; originalData = data; Content = data.GetString("content"); Timestamp = data.GetDateTime("timestamp").GetValueOrDefault(); EditedTimestamp = data.GetDateTime("edited_timestamp").GetValueOrDefault(); TextToSpeech = data.GetBoolean("tts").GetValueOrDefault(); MentionEveryone = data.GetBoolean("mention_everyone").GetValueOrDefault(); Nonce = data.GetSnowflake("nonce"); IsPinned = data.GetBoolean("pinned").GetValueOrDefault(); ChannelId = data.GetSnowflake("channel_id").GetValueOrDefault(); WebhookId = data.GetSnowflake("webhook_id"); Type = (DiscordMessageType)(data.GetInteger("type") ?? 0); Flags = (DiscordMessageFlags)(data.GetInteger("flags") ?? 0); // Get author DiscordApiData authorData = data.Get("author"); if (authorData != null) { Author = new DiscordUser(WebhookId.HasValue, authorData); } // Get member DiscordApiData memberData = data.Get("member"); if (memberData != null) { Member = new DiscordMessageMember(memberData); } // Get activity DiscordApiData activityData = data.Get("activity"); if (activityData != null) { Activity = new DiscordMessageActivity(activityData); } // Get application DiscordApiData applicationData = data.Get("application"); if (applicationData != null) { Application = new DiscordMessageApplication(applicationData); } // Get reference DiscordApiData messageReferenceData = data.Get("message_reference"); if (messageReferenceData != null) { MessageReference = new DiscordMessageReference(messageReferenceData); } // Get mentions IList <DiscordApiData> mentionsArray = data.GetArray("mentions"); if (mentionsArray != null) { DiscordUser[] mentions = new DiscordUser[mentionsArray.Count]; for (int i = 0; i < mentionsArray.Count; i++) { mentions[i] = new DiscordUser(false, mentionsArray[i]); } Mentions = mentions; } // Get mentioned roles IList <DiscordApiData> mentionRolesArray = data.GetArray("mention_roles"); if (mentionRolesArray != null) { Snowflake[] mentionedRoles = new Snowflake[mentionRolesArray.Count]; for (int i = 0; i < mentionRolesArray.Count; i++) { mentionedRoles[i] = mentionRolesArray[i].ToSnowflake().Value; } MentionedRoleIds = mentionedRoles; } // Get channel mentions IList <DiscordApiData> channelMentionsArray = data.GetArray("mention_channels"); if (channelMentionsArray != null) { DiscordChannelMention[] mentions = new DiscordChannelMention[channelMentionsArray.Count]; for (int i = 0; i < channelMentionsArray.Count; i++) { mentions[i] = new DiscordChannelMention(channelMentionsArray[i]); } MentionedChannels = mentions; } // Get attachments IList <DiscordApiData> attachmentsArray = data.GetArray("attachments"); if (attachmentsArray != null) { DiscordAttachment[] attachments = new DiscordAttachment[attachmentsArray.Count]; for (int i = 0; i < attachmentsArray.Count; i++) { attachments[i] = new DiscordAttachment(attachmentsArray[i]); } Attachments = attachments; } // Get embeds IList <DiscordApiData> embedsArray = data.GetArray("embeds"); if (embedsArray != null) { DiscordEmbed[] embeds = new DiscordEmbed[embedsArray.Count]; for (int i = 0; i < embedsArray.Count; i++) { embeds[i] = new DiscordEmbed(embedsArray[i]); } Embeds = embeds; } // Get reactions IList <DiscordApiData> reactionsArray = data.GetArray("reactions"); if (reactionsArray != null) { DiscordReaction[] reactions = new DiscordReaction[reactionsArray.Count]; for (int i = 0; i < reactionsArray.Count; i++) { reactions[i] = new DiscordReaction(reactionsArray[i]); } Reactions = reactions; } }