internal DiscordWebhook(DiscordHttpClient http, DiscordApiData data) : base(data) { this.http = http; GuildId = data.GetSnowflake("guild_id").Value; ChannelId = data.GetSnowflake("channel_id").Value; DiscordApiData userData = data.Get("user"); if (!userData.IsNull) { User = new DiscordUser(false, userData); } Name = data.GetString("name"); Token = data.GetString("token"); string avatarHash = data.GetString("avatar"); if (avatarHash != null) { Avatar = DiscordCdnUrl.ForUserAvatar(Id, avatarHash); } }
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 DiscordGame(DiscordApiData data) { Name = data.GetString("name"); Type = (DiscordGameType)(data.GetInteger("type") ?? 0); Url = data.GetString("url"); CreatedAt = data.GetInt64("created_at"); ApplicationId = data.GetSnowflake("application_id"); Details = data.GetString("details"); State = data.GetString("state"); Instance = data.GetBoolean("instance"); Flags = (DiscordActivityFlag)(data.GetInteger("flags") ?? 0); DiscordApiData timestampsData = data.Get("timestamps"); if (timestampsData != null) { Timestamps = new DiscordActivityTimestamps(timestampsData); } DiscordApiData emojiData = data.Get("emoji"); if (emojiData != null) { Emoji = new DiscordActivityEmoji(emojiData); } DiscordApiData partyData = data.Get("party"); if (partyData != null) { Party = new DiscordActivityParty(partyData); } DiscordApiData assetsData = data.Get("assets"); if (assetsData != null) { Assets = new DiscordActivityAssets(assetsData); } DiscordApiData secretsData = data.Get("secrets"); if (secretsData != null) { Secrets = new DiscordActivitySecrets(secretsData); } IList <DiscordApiData> buttonsArray = data.GetArray("buttons"); if (buttonsArray != null) { Buttons = buttonsArray.Select(d => d.ToString()).ToArray(); } }
internal DiscordInvite(DiscordHttpClient http, DiscordApiData data) { this.http = http; Code = data.GetString("code"); TargetUserType = (DiscordInviteTargetUserType?)data.GetInteger("target_user_type"); ApproximatePresenceCount = data.GetInteger("approximate_presence_count"); ApproximateMemberCount = data.GetInteger("approximate_member_count"); DiscordApiData guildData = data.Get("guild"); if (guildData != null) { Guild = new DiscordInviteGuild(guildData); } DiscordApiData channelData = data.Get("channel"); if (channelData != null) { Channel = new DiscordInviteChannel(channelData); } DiscordApiData userData = data.Get("target_user"); if (userData != null) { TargetUser = new DiscordUser(isWebhookUser: false, userData); } }
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 DiscordUserPresence(Snowflake userId, DiscordApiData data) { UserId = userId; // Game DiscordApiData gameData = data.Get("game"); if (gameData != null) { if (gameData.IsNull) { Game = null; } else { Game = new DiscordGame(gameData); } } // Status string statusStr = data.GetString("status"); if (statusStr != null) { DiscordUserStatus?status = Utils.ParseUserStatus(statusStr); if (!status.HasValue) { // If we don't have a value for the status yet, // we at least know that they aren't offline. Status = DiscordUserStatus.Online; // However, this should issue a warning. DiscoreLogger.Global.LogWarning($"[DiscordUserPresence] Failed to deserialize status for user {UserId}. " + $"status = {statusStr}"); } else { Status = status.Value; } } // Client status DiscordApiData clientStatusData = data.Get("client_status"); if (clientStatusData != null) { ClientStatus = new DiscordClientStatus(clientStatusData); } // Activites IList <DiscordApiData> activitiesArray = data.GetArray("activities"); if (activitiesArray != null) { Activities = activitiesArray.Select(a => new DiscordGame(a)).ToArray(); } }
internal DiscordUser(bool isWebhookUser, DiscordApiData data) : base(data) { IsWebhookUser = isWebhookUser; Username = data.GetString("username"); Discriminator = data.GetString("discriminator"); IsBot = data.GetBoolean("bot") ?? false; HasTwoFactorAuth = data.GetBoolean("mfa_enabled") ?? false; IsVerified = data.GetBoolean("verified") ?? false; Email = data.GetString("email"); string avatarHash = data.GetString("avatar"); if (avatarHash != null) { Avatar = DiscordCdnUrl.ForUserAvatar(Id, avatarHash); } }
internal DiscordGuildNewsChannel(DiscordHttpClient http, DiscordApiData data, Snowflake?guildId = null) : base(http, data, DiscordChannelType.GuildNews, guildId) { this.http = http; Topic = data.GetString("topic"); Nsfw = data.GetBoolean("nsfw") ?? false; ParentId = data.GetSnowflake("parent_id"); lastMessageId = data.GetSnowflake("last_message_id") ?? default(Snowflake); }
internal DiscordEmoji(DiscordApiData data) : base(data) { Name = data.GetString("name"); UserId = data.LocateSnowflake("user.id"); RequireColons = data.GetBoolean("require_colons") ?? false; IsManaged = data.GetBoolean("managed") ?? false; IsAnimated = data.GetBoolean("animated") ?? false; IList <DiscordApiData> roles = data.GetArray("roles"); Snowflake[] roleIds = new Snowflake[roles.Count]; for (int i = 0; i < roleIds.Length; i++) { roleIds[i] = (roles[i].ToSnowflake().Value); } RoleIds = roleIds; }
internal DiscordInvite(DiscordHttpClient http, DiscordApiData data) { this.http = http; Code = data.GetString("code"); DiscordApiData guildData = data.Get("guild"); if (guildData != null) { Guild = new DiscordInviteGuild(guildData); } DiscordApiData channelData = data.Get("channel"); if (channelData != null) { Channel = new DiscordInviteChannel(channelData); } }
internal DiscordRole(DiscordHttpClient http, Snowflake guildId, DiscordApiData data) : base(data) { this.http = http; GuildId = guildId; Name = data.GetString("name"); IsHoisted = data.GetBoolean("hoist").Value; Position = data.GetInteger("position").Value; IsManaged = data.GetBoolean("managed").Value; IsMentionable = data.GetBoolean("mentionable").Value; int color = data.GetInteger("color").Value; Color = DiscordColor.FromHexadecimal(color); long permissions = data.GetInt64("permissions").Value; Permissions = (DiscordPermission)permissions; }
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 DiscordGuildChannel(DiscordHttpClient http, DiscordApiData data, DiscordChannelType type, Snowflake?guildId) : base(http, data, type) { this.http = http; GuildId = guildId ?? data.GetSnowflake("guild_id").Value; Name = data.GetString("name"); Position = data.GetInteger("position").Value; IList <DiscordApiData> overwrites = data.GetArray("permission_overwrites"); Dictionary <Snowflake, DiscordOverwrite> permissionOverwrites = new Dictionary <Snowflake, DiscordOverwrite>(); for (int i = 0; i < overwrites.Count; i++) { DiscordOverwrite overwrite = new DiscordOverwrite(http, Id, overwrites[i]); permissionOverwrites.Add(overwrite.Id, overwrite); } PermissionOverwrites = permissionOverwrites; }
internal DiscordOverwrite(DiscordHttpClient http, Snowflake channelId, DiscordApiData data) : base(data) { this.http = http; ChannelId = channelId; string typeStr = data.GetString("type"); DiscordOverwriteType type; if (Enum.TryParse(typeStr, true, out type)) { Type = type; } long allow = data.GetInt64("allow").Value; Allow = (DiscordPermission)allow; long deny = data.GetInt64("deny").Value; Deny = (DiscordPermission)deny; }
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; } }
internal DiscordGuild(DiscordHttpClient http, DiscordApiData data) : base(data) { this.http = http; Name = data.GetString("name"); 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; // Get image hashes string iconHash = data.GetString("icon"); if (iconHash != null) { Icon = DiscordCdnUrl.ForGuildIcon(Id, iconHash); } string splashHash = data.GetString("splash"); if (splashHash != null) { Splash = DiscordCdnUrl.ForGuildSplash(Id, splashHash); } // Get features IList <DiscordApiData> featuresData = data.GetArray("features"); string[] features = new string[featuresData.Count]; for (int i = 0; i < features.Length; i++) { features[i] = featuresData[i].ToString(); } Features = features; // Get roles IList <DiscordApiData> rolesData = data.GetArray("roles"); Dictionary <Snowflake, DiscordRole> roles = new Dictionary <Snowflake, DiscordRole>(); for (int i = 0; i < rolesData.Count; i++) { DiscordRole role = new DiscordRole(http, Id, rolesData[i]); roles.Add(role.Id, role); } Roles = roles; // Get emojis IList <DiscordApiData> emojisArray = data.GetArray("emojis"); Dictionary <Snowflake, DiscordEmoji> emojis = new Dictionary <Snowflake, DiscordEmoji>(); for (int i = 0; i < emojisArray.Count; i++) { DiscordEmoji emoji = new DiscordEmoji(emojisArray[i]); emojis.Add(emoji.Id, emoji); } Emojis = emojis; }
internal DiscordActivityParty(DiscordApiData data) { Id = data.GetString("id"); Size = data.GetArray("size")?.Select(d => d.ToInteger().Value).ToArray(); }