diff --git a/Directory.Build.targets b/Directory.Build.targets index 50fad77750..c0bca72b48 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -22,12 +22,13 @@ - - + + + diff --git a/Discord.Net.sln b/Discord.Net.sln index 8635159e4d..2f4c96a9a4 100644 --- a/Discord.Net.sln +++ b/Discord.Net.sln @@ -17,6 +17,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Gateway.UnitTes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Models", "src\Models\Discord.Net.Models.csproj", "{564A2E82-CE92-42F6-9D4E-8CC09C5CDF17}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{80F15CCA-4587-49F9-81FE-73FFC3E131BD}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SourceGenerators", "SourceGenerators", "{811BBF1D-D37B-415A-969F-2BF354F3082E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.SourceGenerators.Serialization", "tools\SourceGenerators\Serialization\Discord.Net.SourceGenerators.Serialization.csproj", "{2B1C884B-F8AC-450B-BAA4-210F717DAA42}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Serialization", "src\Serialization\Discord.Net.Serialization.csproj", "{1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -75,6 +83,30 @@ Global {564A2E82-CE92-42F6-9D4E-8CC09C5CDF17}.Release|x64.Build.0 = Release|Any CPU {564A2E82-CE92-42F6-9D4E-8CC09C5CDF17}.Release|x86.ActiveCfg = Release|Any CPU {564A2E82-CE92-42F6-9D4E-8CC09C5CDF17}.Release|x86.Build.0 = Release|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Debug|x64.ActiveCfg = Debug|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Debug|x64.Build.0 = Debug|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Debug|x86.ActiveCfg = Debug|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Debug|x86.Build.0 = Debug|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Release|Any CPU.Build.0 = Release|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Release|x64.ActiveCfg = Release|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Release|x64.Build.0 = Release|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Release|x86.ActiveCfg = Release|Any CPU + {2B1C884B-F8AC-450B-BAA4-210F717DAA42}.Release|x86.Build.0 = Release|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Debug|x64.ActiveCfg = Debug|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Debug|x64.Build.0 = Debug|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Debug|x86.ActiveCfg = Debug|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Debug|x86.Build.0 = Debug|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Release|Any CPU.Build.0 = Release|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Release|x64.ActiveCfg = Release|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Release|x64.Build.0 = Release|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Release|x86.ActiveCfg = Release|Any CPU + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -84,6 +116,9 @@ Global {54A6E396-5186-4D79-893B-6EFD1CF658CB} = {6D7B7A29-83FE-44F2-85E1-7D44B061EA27} {7EC53EB6-6C15-4FD7-9B83-95F96025C14D} = {A47FC28E-1835-46C3-AFD5-7C048A43C157} {564A2E82-CE92-42F6-9D4E-8CC09C5CDF17} = {CD5CFA4B-143E-4495-8BFD-AF419226CBE5} + {811BBF1D-D37B-415A-969F-2BF354F3082E} = {80F15CCA-4587-49F9-81FE-73FFC3E131BD} + {2B1C884B-F8AC-450B-BAA4-210F717DAA42} = {811BBF1D-D37B-415A-969F-2BF354F3082E} + {1288AE15-BFE7-45E4-9769-9D45FE9DD1D3} = {CD5CFA4B-143E-4495-8BFD-AF419226CBE5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {36B0BFC9-AF79-4D25-89D4-2EE3C961612B} diff --git a/samples/PingPong/PingPong.csproj b/samples/PingPong/PingPong.csproj index 3a0beba950..a11fbc8f13 100644 --- a/samples/PingPong/PingPong.csproj +++ b/samples/PingPong/PingPong.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Models/Application/Application.cs b/src/Models/Application/Application.cs deleted file mode 100644 index 4adddeedf5..0000000000 --- a/src/Models/Application/Application.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an application object. - /// - public record Application - { - /// - /// Creates a with the provided parameters. - /// - /// The id of the app. - /// The name of the app. - /// The icon hash of the app. - /// The description of the app. - /// An array of rpc origin urls, if rpc is enabled. - /// When false only app owner can join the app's bot to guilds. - /// When true the app's bot will only join upon completion of the full oauth2 code grant flow. - /// The url of the app's terms of service. - /// The url of the app's privacy policy. - /// Partial user object containing info on the owner of the application. - /// If this application is a game sold on Discord, this field will be the summary field for the store page of its primary sku. - /// The hex encoded key for verification in interactions and the GameSDK's GetTicket. - /// If the application belongs to a team, this will be a list of the members of that team. - /// If this application is a game sold on Discord, this field will be the guild to which it has been linked. - /// If this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists. - /// If this application is a game sold on Discord, this field will be the URL slug that links to the store page. - /// The application's default rich presence invite cover image hash. - /// The application's public flags. - [JsonConstructor] - public Application(Snowflake id, string name, string? icon, string description, Optional rpcOrigins, bool botPublic, bool botRequireCodeGrant, Optional termsOfServiceUrl, Optional privacyPolicyUrl, User owner, string summary, string verifyKey, Team? team, Optional guildId, Optional primarySkuId, Optional slug, Optional coverImage, ApplicationFlags flags) - { - Id = id; - Name = name; - Icon = icon; - Description = description; - RpcOrigins = rpcOrigins; - BotPublic = botPublic; - BotRequireCodeGrant = botRequireCodeGrant; - TermsOfServiceUrl = termsOfServiceUrl; - PrivacyPolicyUrl = privacyPolicyUrl; - Owner = owner; - Summary = summary; - VerifyKey = verifyKey; - Team = team; - GuildId = guildId; - PrimarySkuId = primarySkuId; - Slug = slug; - CoverImage = coverImage; - Flags = flags; - - } - - /// - /// The id of the app. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The name of the app. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// The icon hash of the app. - /// - [JsonPropertyName("icon")] - public string? Icon { get; } - - /// - /// The description of the app. - /// - [JsonPropertyName("description")] - public string Description { get; } - - /// - /// An array of rpc origin urls, if rpc is enabled. - /// - [JsonPropertyName("rpc_origins")] - public Optional RpcOrigins { get; } - - /// - /// When false only app owner can join the app's bot to guilds. - /// - [JsonPropertyName("bot_public")] - public bool BotPublic { get; } - - /// - /// When true the app's bot will only join upon completion of the full oauth2 code grant flow. - /// - [JsonPropertyName("bot_require_code_grant")] - public bool BotRequireCodeGrant { get; } - - /// - /// The url of the app's terms of service. - /// - [JsonPropertyName("terms_of_service_url")] - public Optional TermsOfServiceUrl { get; } - - /// - /// The url of the app's privacy policy. - /// - [JsonPropertyName("privacy_policy_url")] - public Optional PrivacyPolicyUrl { get; } - - /// - /// Partial user object containing info on the owner of the application. - /// - [JsonPropertyName("owner")] - public User Owner { get; } - - /// - /// If this application is a game sold on Discord, this field will be the summary field for the store page of its primary sku. - /// - [JsonPropertyName("summary")] - public string Summary { get; } - - /// - /// The hex encoded key for verification in interactions and the GameSDK's GetTicket. - /// - [JsonPropertyName("verify_key")] - public string VerifyKey { get; } - - /// - /// If the application belongs to a team, this will be a list of the members of that team. - /// - [JsonPropertyName("team")] - public Team? Team { get; } - - /// - /// If this application is a game sold on Discord, this field will be the guild to which it has been linked. - /// - [JsonPropertyName("guild_id")] - public Optional GuildId { get; } - - /// - /// If this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists. - /// - [JsonPropertyName("primary_sku_id")] - public Optional PrimarySkuId { get; } - - /// - /// If this application is a game sold on Discord, this field will be the URL slug that links to the store page. - /// - [JsonPropertyName("slug")] - public Optional Slug { get; } - - /// - /// The application's default rich presence invite cover image hash. - /// - [JsonPropertyName("cover_image")] - public Optional CoverImage { get; } - - /// - /// The application's public flags. - /// - [JsonPropertyName("flags")] - public ApplicationFlags Flags { get; } - } -} diff --git a/src/Models/Application/ApplicationFlags.cs b/src/Models/Application/ApplicationFlags.cs deleted file mode 100644 index 7370e137b4..0000000000 --- a/src/Models/Application/ApplicationFlags.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the application flags. - /// - [Flags] - public enum ApplicationFlags - { - /// - /// This application has the gateway presence privileged intent. - /// - GatewayPresence = 1 << 12, - - /// - /// This application has the gateway presence limited. - /// - GatewayPresenceLimited = 1 << 13, - - /// - /// This application has the gateway guild members privileged intent. - /// - GatewayGuildMembers = 1 << 14, - - /// - /// This application has the gateway guid members limited. - /// - GatewayGuildMembersLimited = 1 << 15, - - /// - /// This application has the verification for the increase of the guild limit pending. - /// - VerificationPendingGuildLimit = 1 << 16, - - /// - /// This application is embedded. - /// - Embedded = 1 << 17, - } -} diff --git a/src/Models/AuditLog/AuditEntryInfo.cs b/src/Models/AuditLog/AuditEntryInfo.cs deleted file mode 100644 index c8a5f2c9a8..0000000000 --- a/src/Models/AuditLog/AuditEntryInfo.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an audit entry info object. - /// - public record AuditEntryInfo - { - /// - /// Creates a with the provided parameters. - /// - /// Number of days after which inactive members were kicked. - /// Number of members removed by the prune. - /// Channel in which the entities were targeted. - /// Id of the message that was targeted. - /// Number of entities that were targeted. - /// Id of the overwritten entity. - /// Type of overwritten entity. - /// Name of the role if type is (not present if type is ). - [JsonConstructor] - public AuditEntryInfo(int? deleteMemberDays, int? membersRemoved, Snowflake? channelId, Snowflake? messageId, int? count, Snowflake? id, AuditEntryInfoType? type, string? roleName) - { - DeleteMemberDays = deleteMemberDays; - MembersRemoved = membersRemoved; - ChannelId = channelId; - MessageId = messageId; - Count = count; - Id = id; - Type = type; - RoleName = roleName; - } - - /// - /// Number of days after which inactive members were kicked. - /// - [JsonPropertyName("delete_member_days")] - public int? DeleteMemberDays { get; } - - /// - /// Number of members removed by the prune. - /// - [JsonPropertyName("members_removed")] - public int? MembersRemoved { get; } - - /// - /// Channel in which the entities were targeted. - /// - [JsonPropertyName("channel_id")] - public Snowflake? ChannelId { get; } - - /// - /// Id of the message that was targeted. - /// - [JsonPropertyName("message_id")] - public Snowflake? MessageId { get; } - - /// - /// Number of entities that were targeted. - /// - [JsonPropertyName("count")] - public int? Count { get; } - - /// - /// Id of the overwritten entity. - /// - [JsonPropertyName("id")] - public Snowflake? Id { get; } - - /// - /// Type of overwritten entity. - /// - [JsonPropertyName("type")] - public AuditEntryInfoType? Type { get; } - - /// - /// Name of the role if type is (not present if type is ). - /// - [JsonPropertyName("role_name")] - public string? RoleName { get; } - } -} diff --git a/src/Models/AuditLog/AuditEntryInfoType.cs b/src/Models/AuditLog/AuditEntryInfoType.cs deleted file mode 100644 index b487c2aa4e..0000000000 --- a/src/Models/AuditLog/AuditEntryInfoType.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Represents the type of the overwritten entity for an audit entry info. - /// - public enum AuditEntryInfoType - { - /// - /// The type of the overwritten entity is a role. - /// - Role = 0, - /// - /// The type of the overwritten entity is a member. - /// - Member = 1, - } -} diff --git a/src/Models/AuditLog/AuditLog.cs b/src/Models/AuditLog/AuditLog.cs deleted file mode 100644 index 960e2607a5..0000000000 --- a/src/Models/AuditLog/AuditLog.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an audit log object. - /// - public record AuditLog - { - /// - /// Creates a with the provided parameters. - /// - /// List of webhooks found in the audit log. - /// List of users found in the audit log. - /// List of audit log entries. - /// List of partial integration objects. - [JsonConstructor] - public AuditLog(Webhook[] webhooks, User[] users, AuditLogEntry[] auditLogEntries, Integration[] integrations) - { - Webhooks = webhooks; - Users = users; - AuditLogEntries = auditLogEntries; - Integrations = integrations; - } - - /// - /// List of webhooks found in the audit log. - /// - [JsonPropertyName("webhooks")] - public Webhook[] Webhooks { get; } - - /// - /// List of users found in the audit log. - /// - [JsonPropertyName("users")] - public User[] Users { get; } - - /// - /// List of audit log entries. - /// - [JsonPropertyName("audit_log_entries")] - public AuditLogEntry[] AuditLogEntries { get; } - - /// - /// List of partial integration objects. - /// - [JsonPropertyName("integrations")] - public Integration[] Integrations { get; } - } -} diff --git a/src/Models/AuditLog/AuditLogChange.cs b/src/Models/AuditLog/AuditLogChange.cs deleted file mode 100644 index e5cdca8e40..0000000000 --- a/src/Models/AuditLog/AuditLogChange.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an audit log change object. - /// - public record AuditLogChange - { - /// - /// Creates a with the provided parameters. - /// - /// New value of the key. - /// Old value of the key. - /// Name of audit log change key. - [JsonConstructor] - public AuditLogChange(Optional newValue, Optional oldValue, string key) - { - NewValue = newValue; - OldValue = oldValue; - Key = key; - } - - /// - /// New value of the key. - /// - [JsonPropertyName("new_value")] - public Optional NewValue { get; } - - /// - /// Old value of the key. - /// - [JsonPropertyName("old_value")] - public Optional OldValue { get; } - - /// - /// Name of audit log change key. - /// - [JsonPropertyName("key")] - public string Key { get; } - } -} diff --git a/src/Models/AuditLog/AuditLogEntry.cs b/src/Models/AuditLog/AuditLogEntry.cs deleted file mode 100644 index 499413166a..0000000000 --- a/src/Models/AuditLog/AuditLogEntry.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an audit log entry object. - /// - public record AuditLogEntry - { - /// - /// Creates a with the provided parameters. - /// - /// Id of the affected entity (webhook, user, role, etc.). - /// Changes made to the target_id. - /// The user who made the changes. - /// Id of the entry. - /// Type of action that occurred. - /// Additional info for certain action types. - /// The reason for the change (0-512 characters). - [JsonConstructor] - public AuditLogEntry(string? targetId, Optional changes, Snowflake? userId, Snowflake id, AuditLogEvent actionType, Optional options, Optional reason) - { - TargetId = targetId; - Changes = changes; - UserId = userId; - Id = id; - ActionType = actionType; - Options = options; - Reason = reason; - } - - /// - /// Id of the affected entity (webhook, user, role, etc.). - /// - [JsonPropertyName("target_id")] - public string? TargetId { get; } - - /// - /// Changes made to the target_id. - /// - [JsonPropertyName("changes")] - public Optional Changes { get; } - - /// - /// The user who made the changes. - /// - [JsonPropertyName("user_id")] - public Snowflake? UserId { get; } - - /// - /// Id of the entry. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Type of action that occurred. - /// - [JsonPropertyName("action_type")] - public AuditLogEvent ActionType { get; } - - /// - /// Additional info for certain action types. - /// - [JsonPropertyName("options")] - public Optional Options { get; } - - /// - /// The reason for the change (0-512 characters). - /// - [JsonPropertyName("reason")] - public Optional Reason { get; } - } -} diff --git a/src/Models/AuditLog/AuditLogEvent.cs b/src/Models/AuditLog/AuditLogEvent.cs deleted file mode 100644 index f3dc94c599..0000000000 --- a/src/Models/AuditLog/AuditLogEvent.cs +++ /dev/null @@ -1,153 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Specifies the type of audit log event. - /// - public enum AuditLogEvent : int - { - /// - /// Default value of this type. - /// - None = 0, - /// - /// The guild was updated. - /// - GuildUpdate = 1, - /// - /// A channel was created. - /// - ChannelCreate = 10, - /// - /// A channel was updated. - /// - ChannelUpdate = 11, - /// - /// A channel was deleted. - /// - ChannelDelete = 12, - /// - /// A channel overwrite was created. - /// - ChannelOverwriteCreate = 13, - /// - /// A channel overwrite was updated. - /// - ChannelOverwriteUpdate = 14, - /// - /// A channel overwrite was deleted. - /// - ChannelOverwriteDelete = 15, - /// - /// A guild member was kicked. - /// - MemberKick = 20, - /// - /// A guild member was pruned. - /// - MemberPrune = 21, - /// - /// A guild member was banned. - /// - MemberBanAdd = 22, - /// - /// A guild member was unbanned. - /// - MemberBanRemove = 23, - /// - /// A guild member was updated. - /// - MemberUpdate = 24, - /// - /// A guild role was updated. - /// - MemberRoleUpdate = 25, - /// - /// A guild member was moved. - /// - MemberMove = 26, - /// - /// A guild member was disconnected. - /// - MemberDisconnect = 27, - /// - /// A bot was added. - /// - BotAdd = 28, - /// - /// A role was created. - /// - RoleCreate = 30, - /// - /// A role was updated. - /// - RoleUpdate = 31, - /// - /// A role was deleted. - /// - RoleDelete = 32, - /// - /// An invite was created. - /// - InviteCreate = 40, - /// - /// An invite was updated. - /// - InviteUpdate = 41, - /// - /// An invite was deleted. - /// - InviteDelete = 42, - /// - /// A webhook was created. - /// - WebhookCreate = 50, - /// - /// A webhook was updated. - /// - WebhookUpdate = 51, - /// - /// A webhook was deleted. - /// - WebhookDelete = 52, - /// - /// An emoji was created. - /// - EmojiCreate = 60, - /// - /// An emoji was updated. - /// - EmojiUpdate = 61, - /// - /// An emoji was deleted. - /// - EmojiDelete = 62, - /// - /// A message was deleted. - /// - MessageDelete = 72, - /// - /// Message were deleted in bulk. - /// - MessageBulkDelete = 73, - /// - /// A message was pinned. - /// - MessagePin = 74, - /// - /// A message was unpinned. - /// - MessageUnpin = 75, - /// - /// An integration was created. - /// - IntegrationCreate = 80, - /// - /// An integration was updated. - /// - IntegrationUpdate = 81, - /// - /// An integration was deleted. - /// - IntegrationDelete = 82, - } -} diff --git a/src/Models/Channel.cs b/src/Models/Channel.cs new file mode 100644 index 0000000000..af9c61452b --- /dev/null +++ b/src/Models/Channel.cs @@ -0,0 +1,241 @@ +using System; +using Discord.Net.Serialization; + +namespace Discord.Net.Models +{ + /// + /// Represents a guild or DM channel within Discord. + /// + /// + /// + /// + /// + /// The id of this channel. + /// + /// + /// The type of channel. + /// + [DiscriminatedUnion(nameof(Channel.Type))] + [GenerateSerializer] + public record Channel( + ChannelType Type, + Snowflake Id); + + /// + /// Represents a text channel within a server. + /// + [DiscriminatedUnionMember(ChannelType.GuildText)] + [GenerateSerializer] + public record GuildTextChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + /*Overwrite[] PermissionOverwrites,*/ + string Name, + string? Topic, + bool Nsfw, + Snowflake LastMessageId, + int RateLimitPerUser, + Snowflake? ParentId, + DateTimeOffset? LastPinTimestamp) + : Channel( + ChannelType.GuildText, + Id); + + /* + + /// + /// Represents a direct message between users. + /// + [DiscriminatedUnionMember(ChannelType.DM)] + [GenerateSerializer] + public record DMChannel( + Snowflake Id, + User[] Recipients) + : Channel( + ChannelType.DM, + Id); + + /// + /// Represents a voice channel within a server. + /// + [DiscriminatedUnionMember(ChannelType.GuildVoice)] + [GenerateSerializer] + public record GuildVoiceChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + Overwrite[] PermissionOverwrites, + string Name, + bool Nsfw, + int Bitrate, + int UserLimit, + Snowflake? ParentId, + string? RtcRegion, + int VideoQualityMode) + : Channel( + ChannelType.GuildVoice, + Id); + + /// + /// Represents a direct message between multiple users. + /// + [DiscriminatedUnionMember(ChannelType.GroupDM)] + [GenerateSerializer] + public record GroupDMChannel( + Snowflake Id, + string Name, + Snowflake LastMessageId, + User[] Recipients, + string? Icon, + Snowflake? OwnerId, + Snowflake? ApplicationId, + DateTimeOffset? LastPinTimestamp) + : Channel( + ChannelType.GroupDM, + Id); + + /// + /// Represents an organizational category that contains up to 50 channels. + /// + [DiscriminatedUnionMember(ChannelType.GuildCategory)] + [GenerateSerializer] + public record GuildCategoryChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + Overwrite[] PermissionOverwrites, + string Name) + : Channel( + ChannelType.GuildCategory, + Id); + + /// + /// Represents a channel that users can follow and crosspost into their own + /// server. + /// + [DiscriminatedUnionMember(ChannelType.GuildNews)] + [GenerateSerializer] + public record GuildNewsChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + Overwrite[] PermissionOverwrites, + string Name, + string? Topic, + bool Nsfw, + Snowflake? LastMessageId, + int RateLimitPerUser, + Snowflake? ParentId, + Snowflake? LastPinTimestamp) + : Channel( + ChannelType.GuildNews, + Id); + + /// + /// Represents a channel in which game developers can sell their game on + /// Discord. + /// + [DiscriminatedUnionMember(ChannelType.GuildStore)] + [GenerateSerializer] + public record GuildStoreChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + Overwrite[] PermissionOverwrites, // I guess??? + string? Name, + Snowflake? ParentId) + : Channel( + ChannelType.GuildStore, + Id); + + /// + /// Represents a temporary sub-channel within a + /// . + /// + [DiscriminatedUnionMember(ChannelType.GuildNewsThread)] + [GenerateSerializer] + public record GuildNewsThreadChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + Overwrite[] PermissionOverwrites, // I guess?? + string Name, + Snowflake? LastMessageId, + Snowflake? ParentId, + Snowflake? LastPinTimestamp, + int MessageCount, + int MemberCount, + ThreadMetadata ThreadMetadata, + ThreadMember Member) + : Channel( + ChannelType.GuildNewsThread, + Id); + + /// + /// Represents a temporary sub-channel within a + /// . + /// + [DiscriminatedUnionMember(ChannelType.GuildPublicThread)] + [GenerateSerializer] + public record GuildPublicThreadChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + Overwrite[] PermissionOverwrites, // I guess?? + string Name, + Snowflake? LastMessageId, + Snowflake? ParentId, + Snowflake? LastPinTimestamp, + int MessageCount, + int MemberCount, + ThreadMetadata ThreadMetadata, + ThreadMember Member) + : Channel( + ChannelType.GuildPublicThread, + Id); + + /// + /// Represents a temporary sub-channel within a + /// that is only viewable by those invited + /// and those with the MANAGE_THREADS permission. + /// + [DiscriminatedUnionMember(ChannelType.GuildPrivateThread)] + [GenerateSerializer] + public record GuildPrivateThreadChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + Overwrite[] PermissionOverwrites, // I guess??? + string Name, + Snowflake? LastMessageId, + Snowflake? ParentId, + Snowflake? LastPinTimestamp, + int MessageCount, + int MemberCount, + ThreadMetadata ThreadMetadata, + ThreadMember Member) + : Channel( + ChannelType.GuildPrivateThread, + Id); + + /// + /// Represents a voice channel for hosting events with an audience. + /// + [DiscriminatedUnionMember(ChannelType.GuildStageVoice)] + [GenerateSerializer] + public record GuildStageVoiceChannel( + Snowflake Id, + Snowflake GuildId, + int Position, + Overwrite[] PermissionOverwrites, + string Name, + int Bitrate, + int UserLimit, + string? RtcRegion) + : Channel( + ChannelType.GuildStageVoice, + Id); + + */ +} diff --git a/src/Models/Channel/Channel.cs b/src/Models/Channel/Channel.cs deleted file mode 100644 index 2d8e3d370f..0000000000 --- a/src/Models/Channel/Channel.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a channel object. - /// - public record Channel - { - /// - /// Creates a with the provided parameters. - /// - /// The id of this channel. - /// The type of channel. - /// The id of the guild (may be missing for some channel objects received over gateway guild dispatches). - /// Sorting position of the channel. - /// Explicit permission overwrites for members and roles. - /// The name of the channel (2-100 characters). - /// The channel topic (0-1024 characters). - /// Whether the channel is nsfw. - /// The id of the last message sent in this channel (may not point to an existing or valid message). - /// The bitrate (in bits) of the voice channel. - /// The user limit of the voice channel. - /// Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission manage_messages or manage_channel, are unaffected. - /// The recipients of the DM. - /// Icon hash. - /// Id of the creator of the group DM or thread. - /// Application id of the group DM creator if it is bot-created. - /// For guild channels: id of the parent category for a channel (each parent category can contain up to 50 channels), for threads: id of the text channel this thread was created. - /// When the last pinned message was pinned. This may be null in events such as GUILD_CREATE when a message is not pinned. - /// Voice region id for the voice channel, automatic when set to null. - /// The camera video quality mode of the voice channel, 1 when not present. - /// An approximate count of messages in a thread, stops counting at 50. - /// An approximate count of users in a thread, stops counting at 50. - /// Thread-specific fields not needed by other channels. - /// Thread member object for the current user, if they have joined the thread, only included on certain API endpoints. - [JsonConstructor] - public Channel(Snowflake id, ChannelType type, Optional guildId, Optional position, Optional permissionOverwrites, Optional name, Optional topic, Optional nsfw, Optional lastMessageId, Optional bitrate, Optional userLimit, Optional rateLimitPerUser, Optional recipients, Optional icon, Optional ownerId, Optional applicationId, Optional parentId, Optional lastPinTimestamp, Optional rtcRegion, Optional videoQualityMode, Optional messageCount, Optional memberCount, Optional threadMetadata, Optional member) - { - Id = id; - Type = type; - GuildId = guildId; - Position = position; - PermissionOverwrites = permissionOverwrites; - Name = name; - Topic = topic; - Nsfw = nsfw; - LastMessageId = lastMessageId; - Bitrate = bitrate; - UserLimit = userLimit; - RateLimitPerUser = rateLimitPerUser; - Recipients = recipients; - Icon = icon; - OwnerId = ownerId; - ApplicationId = applicationId; - ParentId = parentId; - LastPinTimestamp = lastPinTimestamp; - RtcRegion = rtcRegion; - VideoQualityMode = videoQualityMode; - MessageCount = messageCount; - MemberCount = memberCount; - ThreadMetadata = threadMetadata; - Member = member; - } - - /// - /// The id of this channel. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The type of channel. - /// - [JsonPropertyName("type")] - public ChannelType Type { get; } - - /// - /// The id of the guild (may be missing for some channel objects received over gateway guild dispatches). - /// - [JsonPropertyName("guild_id")] - public Optional GuildId { get; } - - /// - /// Sorting position of the channel. - /// - [JsonPropertyName("position")] - public Optional Position { get; } - - /// - /// Explicit permission overwrites for members and roles. - /// - [JsonPropertyName("permission_overwrites")] - public Optional PermissionOverwrites { get; } - - /// - /// The name of the channel (2-100 characters). - /// - [JsonPropertyName("name")] - public Optional Name { get; } - - /// - /// The channel topic (0-1024 characters). - /// - [JsonPropertyName("topic")] - public Optional Topic { get; } - - /// - /// Whether the channel is nsfw. - /// - [JsonPropertyName("nsfw")] - public Optional Nsfw { get; } - - /// - /// The id of the last message sent in this channel (may not point to an existing or valid message). - /// - [JsonPropertyName("last_message_id")] - public Optional LastMessageId { get; } - - /// - /// The bitrate (in bits) of the voice channel. - /// - [JsonPropertyName("bitrate")] - public Optional Bitrate { get; } - - /// - /// The user limit of the voice channel. - /// - [JsonPropertyName("user_limit")] - public Optional UserLimit { get; } - - /// - /// Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission manage_messages or manage_channel, are unaffected. - /// - [JsonPropertyName("rate_limit_per_user")] - public Optional RateLimitPerUser { get; } - - /// - /// The recipients of the DM. - /// - [JsonPropertyName("recipients")] - public Optional Recipients { get; } - - /// - /// Icon hash. - /// - [JsonPropertyName("icon")] - public Optional Icon { get; } - - /// - /// Id of the creator of the group DM or thread. - /// - [JsonPropertyName("owner_id")] - public Optional OwnerId { get; } - - /// - /// Application id of the group DM creator if it is bot-created. - /// - [JsonPropertyName("application_id")] - public Optional ApplicationId { get; } - - /// - /// For guild channels: id of the parent category for a channel (each parent category can contain up to 50 channels), for threads: id of the text channel this thread was created. - /// - [JsonPropertyName("parent_id")] - public Optional ParentId { get; } - - /// - /// When the last pinned message was pinned. This may be null in events such as GUILD_CREATE when a message is not pinned. - /// - [JsonPropertyName("last_pin_timestamp")] - public Optional LastPinTimestamp { get; } - - /// - /// Voice region id for the voice channel, automatic when set to null. - /// - [JsonPropertyName("rtc_region")] - public Optional RtcRegion { get; } - - /// - /// The camera video quality mode of the voice channel, 1 when not present. - /// - [JsonPropertyName("video_quality_mode")] - public Optional VideoQualityMode { get; } - - /// - /// An approximate count of messages in a thread, stops counting at 50. - /// - [JsonPropertyName("message_count")] - public Optional MessageCount { get; } - - /// - /// An approximate count of users in a thread, stops counting at 50. - /// - [JsonPropertyName("member_count")] - public Optional MemberCount { get; } - - /// - /// Thread-specific fields not needed by other channels. - /// - [JsonPropertyName("thread_metadata")] - public Optional ThreadMetadata { get; } - - /// - /// Thread member object for the current user, if they have joined the thread, only included on certain API endpoints. - /// - [JsonPropertyName("member")] - public Optional Member { get; } - } -} diff --git a/src/Models/Channel/ChannelType.cs b/src/Models/Channel/ChannelType.cs deleted file mode 100644 index e2d874171f..0000000000 --- a/src/Models/Channel/ChannelType.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the channel type. - /// - [Flags] - public enum ChannelType - { - /// - /// A text channel within a server. - /// - GuildText = 0, - - /// - /// A direct message between users. - /// - Dm = 1, - - /// - /// A voice channel within a server. - /// - GuildVoice = 2, - - /// - /// A direct message between multiple users. - /// - GroupDm = 3, - - /// - /// An organizational category that contains up to 50 channels. - /// - GuildCategory = 4, - - /// - /// A channel that users can follow and crosspost into their own server. - /// - GuildNews = 5, - - /// - /// A channel in which game developers can sell their game on Discord. - /// - GuildStore = 6, - - /// - /// A temporary sub-channel within a GUILD_NEWS channel. - /// - GuildNewsThread = 10, - - /// - /// A temporary sub-channel within a GUILD_TEXT channel. - /// - GuildPublicThread = 11, - - /// - /// A temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission. - /// - GuildPrivateThread = 12, - - /// - /// A voice channel for hosting events with an audience. - /// - GuildStageVoice = 13, - } -} diff --git a/src/Models/Channel/FollowedChannel.cs b/src/Models/Channel/FollowedChannel.cs deleted file mode 100644 index f641f032f9..0000000000 --- a/src/Models/Channel/FollowedChannel.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a followed channel object. - /// - public record FollowedChannel - { - /// - /// Creates a with the provided parameters. - /// - /// Source channel id. - /// Created target webhook id. - [JsonConstructor] - public FollowedChannel(Snowflake channelId, Snowflake webhookId) - { - ChannelId = channelId; - WebhookId = webhookId; - } - - /// - /// Source channel id. - /// - [JsonPropertyName("channel_id")] - public Snowflake ChannelId { get; } - - /// - /// Created target webhook id. - /// - [JsonPropertyName("webhook_id")] - public Snowflake WebhookId { get; } - } -} diff --git a/src/Models/Channel/Message/AllowedMentions.cs b/src/Models/Channel/Message/AllowedMentions.cs deleted file mode 100644 index a818053d0d..0000000000 --- a/src/Models/Channel/Message/AllowedMentions.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an allowed mentions object. - /// - public record AllowedMentions - { - /// - /// Creates a with the provided parameters. - /// - /// An array of allowed mention types to parse from the content. - /// Array of role_ids to mention (Max size of 100). - /// Array of user_ids to mention (Max size of 100). - /// For replies, whether to mention the author of the message being replied to (default false). - [JsonConstructor] - public AllowedMentions(string[] parse, Snowflake[] roles, Snowflake[] users, bool repliedUser) - { - Parse = parse; - Roles = roles; - Users = users; - RepliedUser = repliedUser; - } - - /// - /// An array of allowed mention types to parse from the content. - /// - [JsonPropertyName("parse")] - public string[] Parse { get; } - - /// - /// Array of role_ids to mention (Max size of 100). - /// - [JsonPropertyName("roles")] - public Snowflake[] Roles { get; } - - /// - /// Array of user_ids to mention (Max size of 100). - /// - [JsonPropertyName("users")] - public Snowflake[] Users { get; } - - /// - /// For replies, whether to mention the author of the message being replied to (default false). - /// - [JsonPropertyName("replied_user")] - public bool RepliedUser { get; } - } -} diff --git a/src/Models/Channel/Message/Attachment.cs b/src/Models/Channel/Message/Attachment.cs deleted file mode 100644 index 1b72bfd854..0000000000 --- a/src/Models/Channel/Message/Attachment.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an attachment object. - /// - public record Attachment - { - /// - /// Creates a with the provided parameters. - /// - /// Attachment id. - /// Name of file attached. - /// The attachment's media type. - /// Size of file in bytes. - /// Source url of file. - /// A proxied url of file. - /// Height of file (if image). - /// Width of file (if image). - [JsonConstructor] - public Attachment(Snowflake id, string filename, Optional contentType, int size, string url, string proxyUrl, Optional height, Optional width) - { - Id = id; - Filename = filename; - ContentType = contentType; - Size = size; - Url = url; - ProxyUrl = proxyUrl; - Height = height; - Width = width; - } - - /// - /// Attachment id. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Name of file attached. - /// - [JsonPropertyName("filename")] - public string Filename { get; } - - /// - /// The attachment's media type. - /// - [JsonPropertyName("content_type")] - public Optional ContentType { get; } - - /// - /// Size of file in bytes. - /// - [JsonPropertyName("size")] - public int Size { get; } - - /// - /// Source url of file. - /// - [JsonPropertyName("url")] - public string Url { get; } - - /// - /// A proxied url of file. - /// - [JsonPropertyName("proxy_url")] - public string ProxyUrl { get; } - - /// - /// Height of file (if image). - /// - [JsonPropertyName("height")] - public Optional Height { get; } - - /// - /// Width of file (if image). - /// - [JsonPropertyName("width")] - public Optional Width { get; } - } -} diff --git a/src/Models/Channel/Message/ChannelMention.cs b/src/Models/Channel/Message/ChannelMention.cs deleted file mode 100644 index 886683323d..0000000000 --- a/src/Models/Channel/Message/ChannelMention.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a channel mention object. - /// - public record ChannelMention - { - /// - /// Creates a with the provided parameters. - /// - /// Id of the channel. - /// Id of the guild containing the channel. - /// The type of channel. - /// The name of the channel. - [JsonConstructor] - public ChannelMention(Snowflake id, Snowflake guildId, ChannelType type, string name) - { - Id = id; - GuildId = guildId; - Type = type; - Name = name; - } - - /// - /// Id of the channel. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Id of the guild containing the channel. - /// - [JsonPropertyName("guild_id")] - public Snowflake GuildId { get; } - - /// - /// The type of channel. - /// - [JsonPropertyName("type")] - public ChannelType Type { get; } - - /// - /// The name of the channel. - /// - [JsonPropertyName("name")] - public string Name { get; } - } -} diff --git a/src/Models/Channel/Message/Embed/Embed.cs b/src/Models/Channel/Message/Embed/Embed.cs deleted file mode 100644 index 9ee90565d8..0000000000 --- a/src/Models/Channel/Message/Embed/Embed.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a embed object. - /// - public record Embed - { - /// - /// Creates a with the provided parameters. - /// - /// Title of embed. - /// Type of embed (always "rich" for webhook embeds). - /// Description of embed. - /// Url of embed. - /// Timestamp of embed content. - /// Color code of the embed. - /// Footer information. - /// Image information. - /// Thumbnail information. - /// Video information. - /// Provider information. - /// Author information. - /// Fields information. - [JsonConstructor] - public Embed(Optional title, Optional type, Optional description, Optional url, Optional timestamp, Optional color, Optional footer, Optional image, Optional thumbnail, Optional video, Optional provider, Optional author, Optional fields) - { - Title = title; - Type = type; - Description = description; - Url = url; - Timestamp = timestamp; - Color = color; - Footer = footer; - Image = image; - Thumbnail = thumbnail; - Video = video; - Provider = provider; - Author = author; - Fields = fields; - } - - /// - /// Title of embed. - /// - [JsonPropertyName("title")] - public Optional Title { get; } - - /// - /// Type of embed (always "rich" for webhook embeds). - /// - [JsonPropertyName("type")] - public Optional Type { get; } - - /// - /// Description of embed. - /// - [JsonPropertyName("description")] - public Optional Description { get; } - - /// - /// Url of embed. - /// - [JsonPropertyName("url")] - public Optional Url { get; } - - /// - /// Timestamp of embed content. - /// - [JsonPropertyName("timestamp")] - public Optional Timestamp { get; } - - /// - /// Color code of the embed. - /// - [JsonPropertyName("color")] - public Optional Color { get; } - - /// - /// Footer information. - /// - [JsonPropertyName("footer")] - public Optional Footer { get; } - - /// - /// Image information. - /// - [JsonPropertyName("image")] - public Optional Image { get; } - - /// - /// Thumbnail information. - /// - [JsonPropertyName("thumbnail")] - public Optional Thumbnail { get; } - - /// - /// Video information. - /// - [JsonPropertyName("video")] - public Optional Video { get; } - - /// - /// Provider information. - /// - [JsonPropertyName("provider")] - public Optional Provider { get; } - - /// - /// Author information. - /// - [JsonPropertyName("author")] - public Optional Author { get; } - - /// - /// Fields information. - /// - [JsonPropertyName("fields")] - public Optional Fields { get; } - } -} diff --git a/src/Models/Channel/Message/Embed/EmbedAuthor.cs b/src/Models/Channel/Message/Embed/EmbedAuthor.cs deleted file mode 100644 index 344c404141..0000000000 --- a/src/Models/Channel/Message/Embed/EmbedAuthor.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a embed author object. - /// - public record EmbedAuthor - { - /// - /// Creates a with the provided parameters. - /// - /// Name of author. - /// Url of author. - /// Url of author icon (only supports http(s) and attachments). - /// A proxied url of author icon. - [JsonConstructor] - public EmbedAuthor(Optional name, Optional url, Optional iconUrl, Optional proxyIconUrl) - { - Name = name; - Url = url; - IconUrl = iconUrl; - ProxyIconUrl = proxyIconUrl; - } - - /// - /// Name of author. - /// - [JsonPropertyName("name")] - public Optional Name { get; } - - /// - /// Url of author. - /// - [JsonPropertyName("url")] - public Optional Url { get; } - - /// - /// Url of author icon (only supports http(s) and attachments). - /// - [JsonPropertyName("icon_url")] - public Optional IconUrl { get; } - - /// - /// A proxied url of author icon. - /// - [JsonPropertyName("proxy_icon_url")] - public Optional ProxyIconUrl { get; } - } -} diff --git a/src/Models/Channel/Message/Embed/EmbedField.cs b/src/Models/Channel/Message/Embed/EmbedField.cs deleted file mode 100644 index b4a39de5ab..0000000000 --- a/src/Models/Channel/Message/Embed/EmbedField.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a embed field object. - /// - public record EmbedField - { - /// - /// Creates a with the provided parameters. - /// - /// Name of the field. - /// Value of the field. - /// Whether or not this field should display inline. - [JsonConstructor] - public EmbedField(string name, string value, Optional inline) - { - Name = name; - Value = value; - Inline = inline; - } - - /// - /// Name of the field. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// Value of the field. - /// - [JsonPropertyName("value")] - public string Value { get; } - - /// - /// Whether or not this field should display inline. - /// - [JsonPropertyName("inline")] - public Optional Inline { get; } - } -} diff --git a/src/Models/Channel/Message/Embed/EmbedFooter.cs b/src/Models/Channel/Message/Embed/EmbedFooter.cs deleted file mode 100644 index ba172dd1b0..0000000000 --- a/src/Models/Channel/Message/Embed/EmbedFooter.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a embed footer object. - /// - public record EmbedFooter - { - /// - /// Creates a with the provided parameters. - /// - /// Footer text. - /// Url of footer icon (only supports http(s) and attachments). - /// A proxied url of footer icon. - [JsonConstructor] - public EmbedFooter(string text, Optional iconUrl, Optional proxyIconUrl) - { - Text = text; - IconUrl = iconUrl; - ProxyIconUrl = proxyIconUrl; - } - - /// - /// Footer text. - /// - [JsonPropertyName("text")] - public string Text { get; } - - /// - /// Url of footer icon (only supports http(s) and attachments). - /// - [JsonPropertyName("icon_url")] - public Optional IconUrl { get; } - - /// - /// A proxied url of footer icon. - /// - [JsonPropertyName("proxy_icon_url")] - public Optional ProxyIconUrl { get; } - } -} diff --git a/src/Models/Channel/Message/Embed/EmbedImage.cs b/src/Models/Channel/Message/Embed/EmbedImage.cs deleted file mode 100644 index 75984072ad..0000000000 --- a/src/Models/Channel/Message/Embed/EmbedImage.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a embed image object. - /// - public record EmbedImage - { - /// - /// Creates a with the provided parameters. - /// - /// Source url of image (only supports http(s) and attachments). - /// A proxied url of the image. - /// Height of image. - /// Width of image. - [JsonConstructor] - public EmbedImage(Optional url, Optional proxyUrl, Optional height, Optional width) - { - Url = url; - ProxyUrl = proxyUrl; - Height = height; - Width = width; - } - - /// - /// Source url of image (only supports http(s) and attachments). - /// - [JsonPropertyName("url")] - public Optional Url { get; } - - /// - /// A proxied url of the image. - /// - [JsonPropertyName("proxy_url")] - public Optional ProxyUrl { get; } - - /// - /// Height of image. - /// - [JsonPropertyName("height")] - public Optional Height { get; } - - /// - /// Width of image. - /// - [JsonPropertyName("width")] - public Optional Width { get; } - } -} diff --git a/src/Models/Channel/Message/Embed/EmbedProvider.cs b/src/Models/Channel/Message/Embed/EmbedProvider.cs deleted file mode 100644 index 67349b0c71..0000000000 --- a/src/Models/Channel/Message/Embed/EmbedProvider.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a embed provider object. - /// - public record EmbedProvider - { - /// - /// Creates a with the provided parameters. - /// - /// Name of provider. - /// Url of provider. - [JsonConstructor] - public EmbedProvider(Optional name, Optional url) - { - Name = name; - Url = url; - } - - /// - /// Name of provider. - /// - [JsonPropertyName("name")] - public Optional Name { get; } - - /// - /// Url of provider. - /// - [JsonPropertyName("url")] - public Optional Url { get; } - } -} diff --git a/src/Models/Channel/Message/Embed/EmbedThumbnail.cs b/src/Models/Channel/Message/Embed/EmbedThumbnail.cs deleted file mode 100644 index dd20c3911c..0000000000 --- a/src/Models/Channel/Message/Embed/EmbedThumbnail.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a embed thumbnail object. - /// - public record EmbedThumbnail - { - /// - /// Creates a with the provided parameters. - /// - /// Source url of thumbnail (only supports http(s) and attachments). - /// A proxied url of the thumbnail. - /// Height of thumbnail. - /// Width of thumbnail. - [JsonConstructor] - public EmbedThumbnail(Optional url, Optional proxyUrl, Optional height, Optional width) - { - Url = url; - ProxyUrl = proxyUrl; - Height = height; - Width = width; - } - - /// - /// Source url of thumbnail (only supports http(s) and attachments). - /// - [JsonPropertyName("url")] - public Optional Url { get; } - - /// - /// A proxied url of the thumbnail. - /// - [JsonPropertyName("proxy_url")] - public Optional ProxyUrl { get; } - - /// - /// Height of thumbnail. - /// - [JsonPropertyName("height")] - public Optional Height { get; } - - /// - /// Width of thumbnail. - /// - [JsonPropertyName("width")] - public Optional Width { get; } - } -} diff --git a/src/Models/Channel/Message/Embed/EmbedType.cs b/src/Models/Channel/Message/Embed/EmbedType.cs deleted file mode 100644 index 5955608df3..0000000000 --- a/src/Models/Channel/Message/Embed/EmbedType.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Represents the type of embed. - /// - public enum EmbedType - { - /// - /// Generic embed rendered from embed attributes. - /// - Rich, - - /// - /// Image embed. - /// - Image, - - /// - /// Video embed. - /// - Video, - - /// - /// Animated gif image embed rendered as a video embed. - /// - Gifv, - - /// - /// Article embed. - /// - Article, - - /// - /// Link embed. - /// - Link, - } -} diff --git a/src/Models/Channel/Message/Embed/EmbedVideo.cs b/src/Models/Channel/Message/Embed/EmbedVideo.cs deleted file mode 100644 index f0e2cdf1c0..0000000000 --- a/src/Models/Channel/Message/Embed/EmbedVideo.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a embed video object. - /// - public record EmbedVideo - { - /// - /// Creates a with the provided parameters. - /// - /// Source url of video. - /// A proxied url of the video. - /// Height of video. - /// Width of video. - [JsonConstructor] - public EmbedVideo(Optional url, Optional proxyUrl, Optional height, Optional width) - { - Url = url; - ProxyUrl = proxyUrl; - Height = height; - Width = width; - } - - /// - /// Source url of video. - /// - [JsonPropertyName("url")] - public Optional Url { get; } - - /// - /// A proxied url of the video. - /// - [JsonPropertyName("proxy_url")] - public Optional ProxyUrl { get; } - - /// - /// Height of video. - /// - [JsonPropertyName("height")] - public Optional Height { get; } - - /// - /// Width of video. - /// - [JsonPropertyName("width")] - public Optional Width { get; } - } -} diff --git a/src/Models/Channel/Message/Message.cs b/src/Models/Channel/Message/Message.cs deleted file mode 100644 index 84a45e9b64..0000000000 --- a/src/Models/Channel/Message/Message.cs +++ /dev/null @@ -1,259 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a message object. - /// - public record Message - { - /// - /// Creates a with the provided parameters. - /// - /// Id of the message. - /// Id of the channel the message was sent in. - /// Id of the guild the message was sent in. - /// The author of this message (not guaranteed to be a valid user, see below). - /// Member properties for this message's author. - /// Contents of the message. - /// When this message was sent. - /// When this message was edited (or null if never). - /// Whether this was a TTS message. - /// Whether this message mentions everyone. - /// Users specifically mentioned in the message. - /// Roles specifically mentioned in this message. - /// Channels specifically mentioned in this message. - /// Any attached files. - /// Any embedded content. - /// Reactions to the message. - /// Used for validating a message was sent. - /// Whether this message is pinned. - /// If the message is generated by a webhook, this is the webhook's id. - /// Type of message. - /// Sent with Rich Presence-related chat embeds. - /// Sent with Rich Presence-related chat embeds. - /// If the message is a response to an Interaction, this is the id of the interaction's application. - /// Data showing the source of a crosspost, channel follow add, pin, or reply message. - /// Message flags combined as a bitfield. - /// The stickers sent with the message (bots currently can only receive messages with stickers, not send). - /// The message associated with the message_reference. - /// Sent if the message is a response to an Interaction. - /// The thread that was started from this message, includes thread member object. - /// Sent if the message contains components like buttons, action rows, or other interactive components. - [JsonConstructor] - public Message(Snowflake id, Snowflake channelId, Optional guildId, User author, Optional member, string content, DateTimeOffset timestamp, DateTimeOffset? editedTimestamp, bool tts, bool mentionEveryone, UserMention[] mentions, Snowflake[] mentionRoles, Optional mentionChannels, Attachment[] attachments, Embed[] embeds, Optional reactions, Optional nonce, bool pinned, Optional webhookId, int type, Optional activity, Optional application, Optional applicationId, Optional messageReference, Optional flags, Optional stickers, Optional referencedMessage, Optional interaction, Optional thread, Optional components) - { - Id = id; - ChannelId = channelId; - GuildId = guildId; - Author = author; - Member = member; - Content = content; - Timestamp = timestamp; - EditedTimestamp = editedTimestamp; - Tts = tts; - MentionEveryone = mentionEveryone; - Mentions = mentions; - MentionRoles = mentionRoles; - MentionChannels = mentionChannels; - Attachments = attachments; - Embeds = embeds; - Reactions = reactions; - Nonce = nonce; - Pinned = pinned; - WebhookId = webhookId; - Type = type; - Activity = activity; - Application = application; - ApplicationId = applicationId; - MessageReference = messageReference; - Flags = flags; - Stickers = stickers; - ReferencedMessage = referencedMessage; - Interaction = interaction; - Thread = thread; - Components = components; - } - - /// - /// Id of the message. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Id of the channel the message was sent in. - /// - [JsonPropertyName("channel_id")] - public Snowflake ChannelId { get; } - - /// - /// Id of the guild the message was sent in. - /// - [JsonPropertyName("guild_id")] - public Optional GuildId { get; } - - /// - /// The author of this message (not guaranteed to be a valid user, see below). - /// - [JsonPropertyName("author")] - public User Author { get; } - - /// - /// Member properties for this message's author. - /// - [JsonPropertyName("member")] - public Optional Member { get; } - - /// - /// Contents of the message. - /// - [JsonPropertyName("content")] - public string Content { get; } - - /// - /// When this message was sent. - /// - [JsonPropertyName("timestamp")] - public DateTimeOffset Timestamp { get; } - - /// - /// When this message was edited (or null if never). - /// - [JsonPropertyName("edited_timestamp")] - public DateTimeOffset? EditedTimestamp { get; } - - /// - /// Whether this was a TTS message. - /// - [JsonPropertyName("tts")] - public bool Tts { get; } - - /// - /// Whether this message mentions everyone. - /// - [JsonPropertyName("mention_everyone")] - public bool MentionEveryone { get; } - - /// - /// Users specifically mentioned in the message. - /// - [JsonPropertyName("mentions")] - public UserMention[] Mentions { get; } - - /// - /// Roles specifically mentioned in this message. - /// - [JsonPropertyName("mention_roles")] - public Snowflake[] MentionRoles { get; } - - /// - /// Channels specifically mentioned in this message. - /// - [JsonPropertyName("mention_channels")] - public Optional MentionChannels { get; } - - /// - /// Any attached files. - /// - [JsonPropertyName("attachments")] - public Attachment[] Attachments { get; } - - /// - /// Any embedded content. - /// - [JsonPropertyName("embeds")] - public Embed[] Embeds { get; } - - /// - /// Reactions to the message. - /// - [JsonPropertyName("reactions")] - public Optional Reactions { get; } - - /// - /// Used for validating a message was sent. - /// - [JsonPropertyName("nonce")] - public Optional Nonce { get; } - - /// - /// Whether this message is pinned. - /// - [JsonPropertyName("pinned")] - public bool Pinned { get; } - - /// - /// If the message is generated by a webhook, this is the webhook's id. - /// - [JsonPropertyName("webhook_id")] - public Optional WebhookId { get; } - - /// - /// Type of message. - /// - [JsonPropertyName("type")] - public int Type { get; } - - /// - /// Sent with Rich Presence-related chat embeds. - /// - [JsonPropertyName("activity")] - public Optional Activity { get; } - - /// - /// Sent with Rich Presence-related chat embeds. - /// - [JsonPropertyName("application")] - public Optional Application { get; } - - /// - /// If the message is a response to an Interaction, this is the id of the interaction's application. - /// - [JsonPropertyName("application_id")] - public Optional ApplicationId { get; } - - /// - /// Data showing the source of a crosspost, channel follow add, pin, or reply message. - /// - [JsonPropertyName("message_reference")] - public Optional MessageReference { get; } - - /// - /// Message flags combined as a bitfield. - /// - [JsonPropertyName("flags")] - public Optional Flags { get; } - - /// - /// The stickers sent with the message (bots currently can only receive messages with stickers, not send). - /// - [JsonPropertyName("stickers")] - public Optional Stickers { get; } - - /// - /// The message associated with the message_reference. - /// - [JsonPropertyName("referenced_message")] - public Optional ReferencedMessage { get; } - - /// - /// Sent if the message is a response to an Interaction. - /// - [JsonPropertyName("interaction")] - public Optional Interaction { get; } - - /// - /// The thread that was started from this message, includes thread member object. - /// - [JsonPropertyName("thread")] - public Optional Thread { get; } - - /// - /// Sent if the message contains components like buttons, action rows, or other interactive components. - /// - [JsonPropertyName("components")] - public Optional Components { get; } - } -} diff --git a/src/Models/Channel/Message/MessageActivity.cs b/src/Models/Channel/Message/MessageActivity.cs deleted file mode 100644 index 657b8b9cfa..0000000000 --- a/src/Models/Channel/Message/MessageActivity.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a message activity object. - /// - public record MessageActivity - { - /// - /// Creates a with the provided parameters. - /// - /// Type of message activity. - /// Party_id from a Rich Presence event. - [JsonConstructor] - public MessageActivity(int type, Optional partyId) - { - Type = type; - PartyId = partyId; - } - - /// - /// Type of message activity. - /// - [JsonPropertyName("type")] - public int Type { get; } - - /// - /// Party_id from a Rich Presence event. - /// - [JsonPropertyName("party_id")] - public Optional PartyId { get; } - } -} diff --git a/src/Models/Channel/Message/MessageActivityType.cs b/src/Models/Channel/Message/MessageActivityType.cs deleted file mode 100644 index 04de9bd331..0000000000 --- a/src/Models/Channel/Message/MessageActivityType.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the message activity type. - /// - [Flags] - public enum MessageActivityType - { - /// - /// The message activity is to join. - /// - Join = 1, - - /// - /// The message activity is to spectate a stream. - /// - Spectate = 2, - - /// - /// The message activity is to listen to music. - /// - Listen = 3, - - /// - /// The message activity is to request to join. - /// - JoinRequest = 5, - } -} diff --git a/src/Models/Channel/Message/MessageFlags.cs b/src/Models/Channel/Message/MessageFlags.cs deleted file mode 100644 index 4e16ed3238..0000000000 --- a/src/Models/Channel/Message/MessageFlags.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the message flags. - /// - [Flags] - public enum MessageFlags - { - /// - /// This message has been published to subscribed channels (via Channel Following). - /// - Crossposted = 1 << 0, - - /// - /// This message originated from a message in another channel (via Channel Following). - /// - IsCrosspost = 1 << 1, - - /// - /// Do not include any embeds when serializing this message. - /// - SuppressEmbeds = 1 << 2, - - /// - /// The source message for this crosspost has been deleted (via Channel Following). - /// - SourceMessageDeleted = 1 << 3, - - /// - /// This message came from the urgent message system. - /// - Urgent = 1 << 4, - - /// - /// This message has an associated thread, with the same id as the message. - /// - HasThread = 1 << 5, - - /// - /// This message is only visible to the user who invoked the Interaction. - /// - Ephemeral = 1 << 6, - - /// - /// This message is an Interaction Response and the bot is "thinking". - /// - Loading = 1 << 7, - } -} diff --git a/src/Models/Channel/Message/MessageReference.cs b/src/Models/Channel/Message/MessageReference.cs deleted file mode 100644 index d7e0e60cfe..0000000000 --- a/src/Models/Channel/Message/MessageReference.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a message reference object. - /// - public record MessageReference - { - /// - /// Creates a with the provided parameters. - /// - /// Id of the originating message. - /// Id of the originating message's channel. - /// Id of the originating message's guild. - /// When sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true. - [JsonConstructor] - public MessageReference(Optional messageId, Optional channelId, Optional guildId, Optional failIfNotExists) - { - MessageId = messageId; - ChannelId = channelId; - GuildId = guildId; - FailIfNotExists = failIfNotExists; - } - - /// - /// Id of the originating message. - /// - [JsonPropertyName("message_id")] - public Optional MessageId { get; } - - /// - /// Id of the originating message's channel. - /// - [JsonPropertyName("channel_id")] - public Optional ChannelId { get; } - - /// - /// Id of the originating message's guild. - /// - [JsonPropertyName("guild_id")] - public Optional GuildId { get; } - - /// - /// When sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true. - /// - [JsonPropertyName("fail_if_not_exists")] - public Optional FailIfNotExists { get; } - } -} diff --git a/src/Models/Channel/Message/MessageType.cs b/src/Models/Channel/Message/MessageType.cs deleted file mode 100644 index 042433d364..0000000000 --- a/src/Models/Channel/Message/MessageType.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the message type. - /// - [Flags] - public enum MessageType - { - /// - /// Default message type. - /// - Default = 0, - - /// - /// Recipient was added. - /// - RecipientAdd = 1, - - /// - /// Recipient was removed. - /// - RecipientRemove = 2, - - /// - /// Request to join a call. - /// - Call = 3, - - /// - /// Channel name was changed. - /// - ChannelNameChange = 4, - - /// - /// Channel icon was changed. - /// - ChannelIconChange = 5, - - /// - /// Message was pinned in this channel. - /// - ChannelPinnedMessage = 6, - - /// - /// User joined the guild. - /// - GuildMemberJoin = 7, - - /// - /// - /// - UserPremiumGuildSubscription = 8, - - /// - /// - /// - UserPremiumGuildSubscriptionTier1 = 9, - - /// - /// - /// - UserPremiumGuildSubscriptionTier2 = 10, - - /// - /// - /// - UserPremiumGuildSubscriptionTier3 = 11, - - /// - /// - /// - ChannelFollowAdd = 12, - - /// - /// - /// - GuildDiscoveryDisqualified = 14, - - /// - /// - /// - GuildDiscoveryRequalified = 15, - - /// - /// - /// - GuildDiscoveryGracePeriodInitialWarning = 16, - - /// - /// - /// - GuildDiscoveryGracePeriodFinalWarning = 17, - - /// - /// - /// - ThreadCreated = 18, - - /// - /// - /// - Reply = 19, - - /// - /// - /// - ApplicationCommand = 20, - - /// - /// - /// - ThreadStarterMessage = 21, - - /// - /// - /// - GuildInviteReminder = 22, - } -} diff --git a/src/Models/Channel/Message/Reaction.cs b/src/Models/Channel/Message/Reaction.cs deleted file mode 100644 index ec3201514c..0000000000 --- a/src/Models/Channel/Message/Reaction.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a reaction object. - /// - public record Reaction - { - /// - /// Creates a with the provided parameters. - /// - /// Times this emoji has been used to react. - /// Whether the current user reacted using this emoji. - /// Emoji information. - [JsonConstructor] - public Reaction(int count, bool me, Emoji emoji) - { - Count = count; - Me = me; - Emoji = emoji; - } - - /// - /// Times this emoji has been used to react. - /// - [JsonPropertyName("count")] - public int Count { get; } - - /// - /// Whether the current user reacted using this emoji. - /// - [JsonPropertyName("me")] - public bool Me { get; } - - /// - /// Emoji information. - /// - [JsonPropertyName("emoji")] - public Emoji Emoji { get; } - } -} diff --git a/src/Models/Channel/Message/Sticker.cs b/src/Models/Channel/Message/Sticker.cs deleted file mode 100644 index c4eefb8de3..0000000000 --- a/src/Models/Channel/Message/Sticker.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a sticker object. - /// - public record Sticker - { - /// - /// Creates a with the provided parameters. - /// - /// Id of the sticker. - /// Id of the pack the sticker is from. - /// Name of the sticker. - /// Description of the sticker. - /// A comma-separated list of tags for the sticker. - /// Sticker asset hash. - /// Type of sticker format. - [JsonConstructor] - public Sticker(Snowflake id, Snowflake packId, string name, string description, Optional tags, string asset, StickerFormatType formatType) - { - Id = id; - PackId = packId; - Name = name; - Description = description; - Tags = tags; - Asset = asset; - FormatType = formatType; - } - - /// - /// Id of the sticker. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Id of the pack the sticker is from. - /// - [JsonPropertyName("pack_id")] - public Snowflake PackId { get; } - - /// - /// Name of the sticker. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// Description of the sticker. - /// - [JsonPropertyName("description")] - public string Description { get; } - - /// - /// A comma-separated list of tags for the sticker. - /// - [JsonPropertyName("tags")] - public Optional Tags { get; } - - /// - /// Sticker asset hash. - /// - [JsonPropertyName("asset")] - public string Asset { get; } - - /// - /// Type of sticker format. - /// - [JsonPropertyName("format_type")] - public StickerFormatType FormatType { get; } - } -} diff --git a/src/Models/Channel/Message/StickerFormatType.cs b/src/Models/Channel/Message/StickerFormatType.cs deleted file mode 100644 index c735057a6c..0000000000 --- a/src/Models/Channel/Message/StickerFormatType.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the sticker format type. - /// - [Flags] - public enum StickerFormatType - { - /// - /// The sticker format is a png. - /// - Png = 1, - - /// - /// The sticker format is a apng. - /// - Apng = 2, - - /// - /// The sticker format is a lottie. - /// - Lottie = 3, - } -} diff --git a/src/Models/Channel/Message/UserMention.cs b/src/Models/Channel/Message/UserMention.cs deleted file mode 100644 index 59908b5862..0000000000 --- a/src/Models/Channel/Message/UserMention.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a user mention object. - /// - public record UserMention : User - { - /// - /// Creates a with the provided parameters. - /// - /// The user's id. - /// The user's username, not unique across the platform. - /// The user's 4-digit discord-tag. - /// The user's avatar hash. - /// Whether the user belongs to an OAuth2 application. - /// Whether the user is an Official Discord System user (part of the urgent message system). - /// Whether the user has two factor enabled on their account. - /// The user's chosen language option. - /// Whether the email on this account has been verified. - /// The user's email. - /// The flags on a user's account. - /// The type of Nitro subscription on a user's account. - /// The public flags on a user's account. - /// Additional partial member field. - [JsonConstructor] - public UserMention(Snowflake id, string username, string discriminator, string? avatar, Optional bot, Optional system, Optional mfaEnabled, Optional locale, Optional verified, Optional email, Optional flags, Optional premiumType, Optional publicFlags, Optional member) - : base(id, username, discriminator, avatar, bot, system, mfaEnabled, locale, verified, email, flags, premiumType, publicFlags) - { - Member = member; - } - - /// - /// Additional partial member field. - /// - [JsonPropertyName("member")] - public Optional Member { get; } - } -} diff --git a/src/Models/Channel/Overwrite.cs b/src/Models/Channel/Overwrite.cs deleted file mode 100644 index 692c9c38e4..0000000000 --- a/src/Models/Channel/Overwrite.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a overwrite object. - /// - public record Overwrite - { - /// - /// Creates a with the provided parameters. - /// - /// Role or user id. - /// Type of entity this overwrite belongs to. - /// Permission bit set. - /// Permission bit set. - [JsonConstructor] - public Overwrite(Snowflake id, OverwriteType type, string allow, string deny) - { - Id = id; - Type = type; - Allow = allow; - Deny = deny; - } - - /// - /// Role or user id. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Type of entity this overwrite belongs to. - /// - [JsonPropertyName("type")] - public OverwriteType Type { get; } - - /// - /// Permission bit set. - /// - [JsonPropertyName("allow")] - public string Allow { get; } - - /// - /// Permission bit set. - /// - [JsonPropertyName("deny")] - public string Deny { get; } - } -} diff --git a/src/Models/Channel/OverwriteType.cs b/src/Models/Channel/OverwriteType.cs deleted file mode 100644 index 405697f236..0000000000 --- a/src/Models/Channel/OverwriteType.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Represents the type of the overwrite. - /// - public enum OverwriteType - { - /// - /// The type of the overwrite is a role. - /// - Role = 0, - /// - /// The type of the overwrite is a member. - /// - Member = 1, - } -} diff --git a/src/Models/Channel/Thread/ThreadMember.cs b/src/Models/Channel/Thread/ThreadMember.cs deleted file mode 100644 index e28fe1c340..0000000000 --- a/src/Models/Channel/Thread/ThreadMember.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a thread member object. - /// - public record ThreadMember - { - /// - /// Creates a with the provided parameters. - /// - /// The id of the thread. - /// The id of the user. - /// The time the current user last joined the thread. - /// Any user-thread settings, currently only used for notifications. - [JsonConstructor] - public ThreadMember(Snowflake id, Snowflake userId, DateTimeOffset joinTimestamp, int flags) - { - Id = id; - UserId = userId; - JoinTimestamp = joinTimestamp; - Flags = flags; - } - - /// - /// The id of the thread. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The id of the user. - /// - [JsonPropertyName("user_id")] - public Snowflake UserId { get; } - - /// - /// The time the current user last joined the thread. - /// - [JsonPropertyName("join_timestamp")] - public DateTimeOffset JoinTimestamp { get; } - - /// - /// Any user-thread settings, currently only used for notifications. - /// - [JsonPropertyName("flags")] - public int Flags { get; } - } -} diff --git a/src/Models/Channel/Thread/ThreadMetadata.cs b/src/Models/Channel/Thread/ThreadMetadata.cs deleted file mode 100644 index dd653de384..0000000000 --- a/src/Models/Channel/Thread/ThreadMetadata.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a thread metadata object. - /// - public record ThreadMetadata - { - /// - /// Creates a with the provided parameters. - /// - /// Whether the thread is archived. - /// Id of the user that last archived or unarchived the thread. - /// Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080. - /// Timestamp when the thread's archive status was last changed, used for calculating recent activity. - /// When a thread is locked, only users with MANAGE_THREADS can unarchive it. - [JsonConstructor] - public ThreadMetadata(bool archived, Optional archiverId, int autoArchiveDuration, DateTimeOffset archiveTimestamp, Optional locked) - { - Archived = archived; - ArchiverId = archiverId; - AutoArchiveDuration = autoArchiveDuration; - ArchiveTimestamp = archiveTimestamp; - Locked = locked; - } - - /// - /// Whether the thread is archived. - /// - [JsonPropertyName("archived")] - public bool Archived { get; } - - /// - /// Id of the user that last archived or unarchived the thread. - /// - [JsonPropertyName("archiver_id")] - public Optional ArchiverId { get; } - - /// - /// Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080. - /// - [JsonPropertyName("auto_archive_duration")] - public int AutoArchiveDuration { get; } - - /// - /// Timestamp when the thread's archive status was last changed, used for calculating recent activity. - /// - [JsonPropertyName("archive_timestamp")] - public DateTimeOffset ArchiveTimestamp { get; } - - /// - /// When a thread is locked, only users with MANAGE_THREADS can unarchive it. - /// - [JsonPropertyName("locked")] - public Optional Locked { get; } - } -} diff --git a/src/Models/Channel/VideoQualityMode.cs b/src/Models/Channel/VideoQualityMode.cs deleted file mode 100644 index eecee2002a..0000000000 --- a/src/Models/Channel/VideoQualityMode.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the video quality mode type. - /// - [Flags] - public enum VideoQualityMode - { - /// - /// Discord chooses the quality for optimal performance. - /// - Auto = 1, - - /// - /// 720p. - /// - Full = 2, - } -} diff --git a/src/Models/ChannelType.cs b/src/Models/ChannelType.cs new file mode 100644 index 0000000000..ef050a637f --- /dev/null +++ b/src/Models/ChannelType.cs @@ -0,0 +1,68 @@ +namespace Discord.Net.Models +{ + /// + /// Declares an enum which represents the type of a . + /// + /// + /// + /// + public enum ChannelType + { + /// + /// A text channel within a server. + /// + GuildText = 0, + + /// + /// A direct message between users. + /// + DM = 1, + + /// + /// A voice channel within a server. + /// + GuildVoice = 2, + + /// + /// A direct message between multiple users. + /// + GroupDM = 3, + + /// + /// An organizational category that contains up to 50 channels. + /// + GuildCategory = 4, + + /// + /// A channel that users can follow and crosspost into their own server. + /// + GuildNews = 5, + + /// + /// A channel in which game developers can sell their game on Discord. + /// + GuildStore = 6, + + /// + /// A temporary sub-channel within a channel. + /// + GuildNewsThread = 10, + + /// + /// A temporary sub-channel within a channel. + /// + GuildPublicThread = 11, + + /// + /// A temporary sub-channel within a channel + /// that is only viewable by those invited and those with the + /// MANAGE_THREADS permission. + /// + GuildPrivateThread = 12, + + /// + /// A voice channel for hosting events with an audience. + /// + GuildStageVoice = 13 + } +} diff --git a/src/Models/Discord.Net.Models.csproj b/src/Models/Discord.Net.Models.csproj index b01c939526..35a3bb8210 100644 --- a/src/Models/Discord.Net.Models.csproj +++ b/src/Models/Discord.Net.Models.csproj @@ -7,10 +7,21 @@ $(Description) Shared models between the Discord REST API and Gateway. + + Discord.Net.Serialization - + + + + + + + + + + diff --git a/src/Models/Emoji/Emoji.cs b/src/Models/Emoji/Emoji.cs deleted file mode 100644 index b66d7da40c..0000000000 --- a/src/Models/Emoji/Emoji.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a emoji object. - /// - public record Emoji - { - /// - /// Creates a with the provided parameters. - /// - /// Emoji id. - /// Emoji name. - /// Roles allowed to use this emoji. - /// User that created this emoji. - /// Whether this emoji must be wrapped in colons. - /// Whether this emoji is managed. - /// Whether this emoji is animated. - /// Whether this emoji can be used, may be false due to loss of Server Boosts. - [JsonConstructor] - public Emoji(Snowflake? id, string? name, Optional roles, Optional user, Optional requireColons, Optional managed, Optional animated, Optional available) - { - Id = id; - Name = name; - Roles = roles; - User = user; - RequireColons = requireColons; - Managed = managed; - Animated = animated; - Available = available; - } - - /// - /// Emoji id. - /// - [JsonPropertyName("id")] - public Snowflake? Id { get; } - - /// - /// Emoji name. - /// - /// - /// Can be null only in reaction emoji objects. - /// - [JsonPropertyName("name")] - public string? Name { get; } - - /// - /// Roles allowed to use this emoji. - /// - [JsonPropertyName("roles")] - public Optional Roles { get; } - - /// - /// User that created this emoji. - /// - [JsonPropertyName("user")] - public Optional User { get; } - - /// - /// Whether this emoji must be wrapped in colons. - /// - [JsonPropertyName("require_colons")] - public Optional RequireColons { get; } - - /// - /// Whether this emoji is managed. - /// - [JsonPropertyName("managed")] - public Optional Managed { get; } - - /// - /// Whether this emoji is animated. - /// - [JsonPropertyName("animated")] - public Optional Animated { get; } - - /// - /// Whether this emoji can be used, may be false due to loss of Server Boosts. - /// - [JsonPropertyName("available")] - public Optional Available { get; } - } -} diff --git a/src/Models/Gateway/Activity.cs b/src/Models/Gateway/Activity.cs deleted file mode 100644 index 3ac1fb74ea..0000000000 --- a/src/Models/Gateway/Activity.cs +++ /dev/null @@ -1,138 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an activity object. - /// - public record Activity - { - /// - /// Creates a with the provided parameters. - /// - /// The activity's name. - /// Activity type. - /// Stream url, is validated when type is 1. - /// Unix timestamp of when the activity was added to the user's session. - /// Unix timestamps for start and/or end of the game. - /// Application id for the game. - /// What the player is currently doing. - /// The user's current party status. - /// The emoji used for a custom status. - /// Information for the current party of the player. - /// Images for the presence and their hover texts. - /// Secrets for Rich Presence joining and spectating. - /// Whether or not the activity is an instanced game session. - /// Activity flags ORd together, describes what the payload includes. - /// The custom buttons shown in the Rich Presence (max 2). - [JsonConstructor] - public Activity(string name, int type, Optional url, int createdAt, Optional timestamps, Optional applicationId, Optional details, Optional state, Optional emoji, Optional party, Optional assets, Optional secrets, Optional instance, Optional flags, Optional buttonLabels) - { - Name = name; - Type = type; - Url = url; - CreatedAt = createdAt; - Timestamps = timestamps; - ApplicationId = applicationId; - Details = details; - State = state; - Emoji = emoji; - Party = party; - Assets = assets; - Secrets = secrets; - Instance = instance; - Flags = flags; - ButtonLabels = buttonLabels; - } - - /// - /// The activity's name. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// Activity type. - /// - [JsonPropertyName("type")] - public int Type { get; } - - /// - /// Stream url, is validated when type is 1. - /// - [JsonPropertyName("url")] - public Optional Url { get; } - - /// - /// Unix timestamp of when the activity was added to the user's session. - /// - [JsonPropertyName("created_at")] - public int CreatedAt { get; } - - /// - /// Unix timestamps for start and/or end of the game. - /// - [JsonPropertyName("timestamps")] - public Optional Timestamps { get; } - - /// - /// Application id for the game. - /// - [JsonPropertyName("application_id")] - public Optional ApplicationId { get; } - - /// - /// What the player is currently doing. - /// - [JsonPropertyName("details")] - public Optional Details { get; } - - /// - /// The user's current party status. - /// - [JsonPropertyName("state")] - public Optional State { get; } - - /// - /// The emoji used for a custom status. - /// - [JsonPropertyName("emoji")] - public Optional Emoji { get; } - - /// - /// Information for the current party of the player. - /// - [JsonPropertyName("party")] - public Optional Party { get; } - - /// - /// Images for the presence and their hover texts. - /// - [JsonPropertyName("assets")] - public Optional Assets { get; } - - /// - /// Secrets for Rich Presence joining and spectating. - /// - [JsonPropertyName("secrets")] - public Optional Secrets { get; } - - /// - /// Whether or not the activity is an instanced game session. - /// - [JsonPropertyName("instance")] - public Optional Instance { get; } - - /// - /// Activity flags ORd together, describes what the payload includes. - /// - [JsonPropertyName("flags")] - public Optional Flags { get; } - - /// - /// The custom buttons shown in the Rich Presence (max 2). - /// - [JsonPropertyName("buttons")] - public Optional ButtonLabels { get; } - } -} diff --git a/src/Models/Gateway/ActivityAssets.cs b/src/Models/Gateway/ActivityAssets.cs deleted file mode 100644 index e80680280c..0000000000 --- a/src/Models/Gateway/ActivityAssets.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an activity assets object. - /// - public record ActivityAssets - { - /// - /// Creates a with the provided parameters. - /// - /// The id for a large asset of the activity, usually a snowflake. - /// Text displayed when hovering over the large image of the activity. - /// The id for a small asset of the activity, usually a snowflake. - /// Text displayed when hovering over the small image of the activity. - [JsonConstructor] - public ActivityAssets(Optional largeImage, Optional largeText, Optional smallImage, Optional smallText) - { - LargeImage = largeImage; - LargeText = largeText; - SmallImage = smallImage; - SmallText = smallText; - } - - /// - /// The id for a large asset of the activity, usually a snowflake. - /// - [JsonPropertyName("large_image")] - public Optional LargeImage { get; } - - /// - /// Text displayed when hovering over the large image of the activity. - /// - [JsonPropertyName("large_text")] - public Optional LargeText { get; } - - /// - /// The id for a small asset of the activity, usually a snowflake. - /// - [JsonPropertyName("small_image")] - public Optional SmallImage { get; } - - /// - /// Text displayed when hovering over the small image of the activity. - /// - [JsonPropertyName("small_text")] - public Optional SmallText { get; } - } -} diff --git a/src/Models/Gateway/ActivityEmoji.cs b/src/Models/Gateway/ActivityEmoji.cs deleted file mode 100644 index 123318ff16..0000000000 --- a/src/Models/Gateway/ActivityEmoji.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an activity emoji object. - /// - public record ActivityEmoji - { - /// - /// Creates a with the provided parameters. - /// - /// The name of the emoji. - /// The id of the emoji. - /// Whether this emoji is animated. - [JsonConstructor] - public ActivityEmoji(string name, Optional id, Optional animated) - { - Name = name; - Id = id; - Animated = animated; - } - - /// - /// The name of the emoji. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// The id of the emoji. - /// - [JsonPropertyName("id")] - public Optional Id { get; } - - /// - /// Whether this emoji is animated. - /// - [JsonPropertyName("animated")] - public Optional Animated { get; } - } -} diff --git a/src/Models/Gateway/ActivityFlags.cs b/src/Models/Gateway/ActivityFlags.cs deleted file mode 100644 index e5563c8db0..0000000000 --- a/src/Models/Gateway/ActivityFlags.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the activity flags. - /// - [Flags] - public enum ActivityFlags - { - /// - /// Activity instance. - /// - Instance = 1 << 0, - - /// - /// Activity join. - /// - Join = 1 << 1, - - /// - /// Activity spectate. - /// - Spectate = 1 << 2, - - /// - /// Activity join request. - /// - JoinRequest = 1 << 3, - - /// - /// Activity sync. - /// - Sync = 1 << 4, - - /// - /// Activity play. - /// - Play = 1 << 5, - } -} diff --git a/src/Models/Gateway/ActivityParty.cs b/src/Models/Gateway/ActivityParty.cs deleted file mode 100644 index 4512941ab8..0000000000 --- a/src/Models/Gateway/ActivityParty.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an activity party object. - /// - public record ActivityParty - { - /// - /// Creates a with the provided parameters. - /// - /// The id of the party. - /// Used to show the party's current and maximum size. - [JsonConstructor] - public ActivityParty(Optional id, Optional size) - { - Id = id; - Size = size; - } - - /// - /// The id of the party. - /// - [JsonPropertyName("id")] - public Optional Id { get; } - - /// - /// Used to show the party's current and maximum size. - /// - [JsonPropertyName("size")] - public Optional Size { get; } - } -} diff --git a/src/Models/Gateway/ActivitySecrets.cs b/src/Models/Gateway/ActivitySecrets.cs deleted file mode 100644 index dcae2096f6..0000000000 --- a/src/Models/Gateway/ActivitySecrets.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an activity secrets object. - /// - public record ActivitySecrets - { - /// - /// Creates a with the provided parameters. - /// - /// The secret for joining a party. - /// The secret for spectating a game. - /// The secret for a specific instanced match. - [JsonConstructor] - public ActivitySecrets(Optional join, Optional spectate, Optional match) - { - Join = join; - Spectate = spectate; - Match = match; - } - - /// - /// The secret for joining a party. - /// - [JsonPropertyName("join")] - public Optional Join { get; } - - /// - /// The secret for spectating a game. - /// - [JsonPropertyName("spectate")] - public Optional Spectate { get; } - - /// - /// The secret for a specific instanced match. - /// - [JsonPropertyName("match")] - public Optional Match { get; } - } -} diff --git a/src/Models/Gateway/ActivityTimestamps.cs b/src/Models/Gateway/ActivityTimestamps.cs deleted file mode 100644 index 89f752a432..0000000000 --- a/src/Models/Gateway/ActivityTimestamps.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents an activity timestamp object. - /// - public record ActivityTimestamps - { - /// - /// Creates a with the provided parameters. - /// - /// When the activity started. - /// When the activity ends. - [JsonConstructor] - public ActivityTimestamps(Optional start, Optional end) - { - Start = start; - End = end; - } - - /// - /// When the activity started. - /// - [JsonPropertyName("start")] - public Optional Start { get; } - - /// - /// When the activity ends. - /// - [JsonPropertyName("end")] - public Optional End { get; } - } -} diff --git a/src/Models/Gateway/ActivityType.cs b/src/Models/Gateway/ActivityType.cs deleted file mode 100644 index 150f627f57..0000000000 --- a/src/Models/Gateway/ActivityType.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Represents the activity type. - /// - public enum ActivityType - { - /// - /// Playing {name}. - /// - Game = 0, - - /// - /// Streaming {details}. - /// - Streaming = 1, - - /// - /// Listening to {name}. - /// - Listening = 2, - - /// - /// Watching {name}. - /// - Watching = 3, - - /// - /// {emoji} {name}. - /// - Custom = 4, - - /// - /// Competing in {name}. - /// - Competing = 5, - } -} diff --git a/src/Models/Gateway/ClientStatus.cs b/src/Models/Gateway/ClientStatus.cs deleted file mode 100644 index 4bd49f18b4..0000000000 --- a/src/Models/Gateway/ClientStatus.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a client status object. - /// - public record ClientStatus - { - /// - /// Creates a with the provided parameters. - /// - /// The user's status set for an active desktop (Windows, Linux, Mac) application session. - /// The user's status set for an active mobile (iOS, Android) application session. - /// The user's status set for an active web (browser, bot account) application session. - [JsonConstructor] - public ClientStatus(Optional desktop, Optional mobile, Optional web) - { - Desktop = desktop; - Mobile = mobile; - Web = web; - } - - /// - /// The user's status set for an active desktop (Windows, Linux, Mac) application session. - /// - [JsonPropertyName("desktop")] - public Optional Desktop { get; } - - /// - /// The user's status set for an active mobile (iOS, Android) application session. - /// - [JsonPropertyName("mobile")] - public Optional Mobile { get; } - - /// - /// The user's status set for an active web (browser, bot account) application session. - /// - [JsonPropertyName("web")] - public Optional Web { get; } - } -} diff --git a/src/Models/Gateway/Presence.cs b/src/Models/Gateway/Presence.cs deleted file mode 100644 index 7fb8bff129..0000000000 --- a/src/Models/Gateway/Presence.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a presence object. - /// - public record Presence - { - /// - /// Creates a with the provided parameters. - /// - /// The user presence is being updated for. - /// Id of the guild. - /// Either "idle", "dnd", "online", or "offline". - /// User's current activities. - /// User's platform-dependent status. - [JsonConstructor] - public Presence(User user, Snowflake guildId, string status, Activity[] activities, ClientStatus clientStatus) - { - User = user; - GuildId = guildId; - Status = status; - Activities = activities; - ClientStatus = clientStatus; - } - - /// - /// The user presence is being updated for. - /// - [JsonPropertyName("user")] - public User User { get; } - - /// - /// Id of the guild. - /// - [JsonPropertyName("guild_id")] - public Snowflake GuildId { get; } - - /// - /// Either "idle", "dnd", "online", or "offline". - /// - [JsonPropertyName("status")] - public string Status { get; } - - /// - /// User's current activities. - /// - [JsonPropertyName("activities")] - public Activity[] Activities { get; } - - /// - /// User's platform-dependent status. - /// - [JsonPropertyName("client_status")] - public ClientStatus ClientStatus { get; } - } -} diff --git a/src/Models/Guild/Ban.cs b/src/Models/Guild/Ban.cs deleted file mode 100644 index 6fac4bb22a..0000000000 --- a/src/Models/Guild/Ban.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a ban object. - /// - public record Ban - { - /// - /// Creates a with the provided parameters. - /// - /// The reason for the ban. - /// The banned user. - [JsonConstructor] - public Ban(string? reason, User user) - { - Reason = reason; - User = user; - } - - /// - /// The reason for the ban. - /// - [JsonPropertyName("reason")] - public string? Reason { get; } - - /// - /// The banned user. - /// - [JsonPropertyName("user")] - public User User { get; } - } -} diff --git a/src/Models/Guild/DefaultMessageNotificationLevel.cs b/src/Models/Guild/DefaultMessageNotificationLevel.cs deleted file mode 100644 index 9181de5983..0000000000 --- a/src/Models/Guild/DefaultMessageNotificationLevel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the default message notification level. - /// - public enum DefaultMessageNotificationLevel - { - /// - /// Members will receive notifications for all messages by default. - /// - AllMessages = 0, - - /// - /// Members will receive notifications only for messages that @mention them by default. - /// - OnlyMentions = 1, - } -} diff --git a/src/Models/Guild/ExplicitContentFilterLevel.cs b/src/Models/Guild/ExplicitContentFilterLevel.cs deleted file mode 100644 index 6bed9d43e6..0000000000 --- a/src/Models/Guild/ExplicitContentFilterLevel.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the explicit content filter level. - /// - public enum ExplicitContentFilterLevel - { - /// - /// Media content will not be scanned. - /// - Disabled = 0, - - /// - /// Media content sent by members without roles will be scanned. - /// - MembersWithoutRoles = 1, - - /// - /// Media content sent by all members will be scanned. - /// - AllMembers = 2, - } -} diff --git a/src/Models/Guild/Guild.cs b/src/Models/Guild/Guild.cs deleted file mode 100644 index 5c7c93c969..0000000000 --- a/src/Models/Guild/Guild.cs +++ /dev/null @@ -1,411 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a guild object. - /// - public record Guild - { - /// - /// Creates a with the provided parameters. - /// - /// Guild id. - /// Guild name (2-100 characters, excluding trailing and leading whitespace). - /// Icon hash. - /// Icon hash, returned when in the template object. - /// Splash hash. - /// Discovery splash hash; only present for guilds with the "DISCOVERABLE" feature. - /// True if the user is the owner of the guild. - /// Id of owner. - /// Total permissions for the user in the guild (excludes overwrites). - /// Voice region id for the guild. - /// Id of afk channel. - /// Afk timeout in seconds. - /// True if the server widget is enabled. - /// The channel id that the widget will generate an invite to, or null if set to no invite. - /// Verification level required for the guild. - /// Default message notifications level. - /// Explicit content filter level. - /// Roles in the guild. - /// Custom guild emojis. - /// Enabled guild features. - /// Required MFA level for the guild. - /// Application id of the guild creator if it is bot-created. - /// The id of the channel where guild notices such as welcome messages and boost events are posted. - /// System channel flags. - /// The id of the channel where Community guilds can display rules and/or guidelines. - /// When this guild was joined at. - /// True if this is considered a large guild. - /// True if this guild is unavailable due to an outage. - /// Total number of members in this guild. - /// States of members currently in voice channels; lacks the guild_id key. - /// Users in the guild. - /// Channels in the guild. - /// All active threads in the guild that current user has permission to view. - /// Presences of the members in the guild, will only include non-offline members if the size is greater than large threshold. - /// The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned). - /// The maximum number of members for the guild. - /// The vanity url code for the guild. - /// The description of a Community guild. - /// Banner hash. - /// Premium tier (Server Boost level). - /// The number of boosts this guild currently has. - /// The preferred locale of a Community guild; used in server discovery and notices from Discord; defaults to "en-US". - /// The id of the channel where admins and moderators of Community guilds receive notices from Discord. - /// The maximum amount of users in a video channel. - /// Approximate number of members in this guild. - /// Approximate number of non-offline members in this guild. - /// The welcome screen of a Community guild, shown to new members, returned in an Invite's guild object. - /// Guild NSFW level. - /// Stage instances in the guild. - [JsonConstructor] - public Guild(Snowflake id, string name, string? icon, Optional iconHash, string? splash, string? discoverySplash, Optional owner, Snowflake ownerId, Optional permissions, string region, Snowflake? afkChannelId, int afkTimeout, Optional widgetEnabled, Optional widgetChannelId, int verificationLevel, int defaultMessageNotifications, int explicitContentFilter, Role[] roles, Emoji[] emojis, string[] features, int mfaLevel, Snowflake? applicationId, Snowflake? systemChannelId, int systemChannelFlags, Snowflake? rulesChannelId, Optional joinedAt, Optional large, Optional unavailable, Optional memberCount, Optional voiceStates, Optional members, Optional channels, Optional threads, Optional presences, Optional maxPresences, Optional maxMembers, string? vanityUrlCode, string? description, string? banner, int premiumTier, Optional premiumSubscriptionCount, string preferredLocale, Snowflake? publicUpdatesChannelId, Optional maxVideoChannelUsers, Optional approximateMemberCount, Optional approximatePresenceCount, Optional welcomeScreen, int nsfwLevel, Optional stageInstances) - { - Id = id; - Name = name; - Icon = icon; - IconHash = iconHash; - Splash = splash; - DiscoverySplash = discoverySplash; - Owner = owner; - OwnerId = ownerId; - Permissions = permissions; - Region = region; - AfkChannelId = afkChannelId; - AfkTimeout = afkTimeout; - WidgetEnabled = widgetEnabled; - WidgetChannelId = widgetChannelId; - VerificationLevel = verificationLevel; - DefaultMessageNotifications = defaultMessageNotifications; - ExplicitContentFilter = explicitContentFilter; - Roles = roles; - Emojis = emojis; - Features = features; - MfaLevel = mfaLevel; - ApplicationId = applicationId; - SystemChannelId = systemChannelId; - SystemChannelFlags = systemChannelFlags; - RulesChannelId = rulesChannelId; - JoinedAt = joinedAt; - Large = large; - Unavailable = unavailable; - MemberCount = memberCount; - VoiceStates = voiceStates; - Members = members; - Channels = channels; - Threads = threads; - Presences = presences; - MaxPresences = maxPresences; - MaxMembers = maxMembers; - VanityUrlCode = vanityUrlCode; - Description = description; - Banner = banner; - PremiumTier = premiumTier; - PremiumSubscriptionCount = premiumSubscriptionCount; - PreferredLocale = preferredLocale; - PublicUpdatesChannelId = publicUpdatesChannelId; - MaxVideoChannelUsers = maxVideoChannelUsers; - ApproximateMemberCount = approximateMemberCount; - ApproximatePresenceCount = approximatePresenceCount; - WelcomeScreen = welcomeScreen; - NsfwLevel = nsfwLevel; - StageInstances = stageInstances; - } - - /// - /// Guild id. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Guild name. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// Icon hash. - /// - [JsonPropertyName("icon")] - public string? Icon { get; } - - /// - /// Icon hash, returned when in the template object. - /// - [JsonPropertyName("icon_hash")] - public Optional IconHash { get; } - - /// - /// Splash hash. - /// - [JsonPropertyName("splash")] - public string? Splash { get; } - - /// - /// Discovery splash hash; only present for guilds with the "DISCOVERABLE" feature. - /// - [JsonPropertyName("discovery_splash")] - public string? DiscoverySplash { get; } - - /// - /// True if the user is the owner of the guild. - /// - [JsonPropertyName("owner")] - public Optional Owner { get; } - - /// - /// Id of owner. - /// - [JsonPropertyName("owner_id")] - public Snowflake OwnerId { get; } - - /// - /// Total permissions for the user in the guild (excludes overwrites). - /// - [JsonPropertyName("permissions")] - public Optional Permissions { get; } - - /// - /// Voice region id for the guild. - /// - [JsonPropertyName("region")] - public string Region { get; } - - /// - /// Id of afk channel. - /// - [JsonPropertyName("afk_channel_id")] - public Snowflake? AfkChannelId { get; } - - /// - /// Afk timeout in seconds. - /// - [JsonPropertyName("afk_timeout")] - public int AfkTimeout { get; } - - /// - /// True if the server widget is enabled. - /// - [JsonPropertyName("widget_enabled")] - public Optional WidgetEnabled { get; } - - /// - /// The channel id that the widget will generate an invite to, or null if set to no invite. - /// - [JsonPropertyName("widget_channel_id")] - public Optional WidgetChannelId { get; } - - /// - /// Verification level required for the guild. - /// - [JsonPropertyName("verification_level")] - public int VerificationLevel { get; } - - /// - /// Default message notifications level. - /// - [JsonPropertyName("default_message_notifications")] - public int DefaultMessageNotifications { get; } - - /// - /// Explicit content filter level. - /// - [JsonPropertyName("explicit_content_filter")] - public int ExplicitContentFilter { get; } - - /// - /// Roles in the guild. - /// - [JsonPropertyName("roles")] - public Role[] Roles { get; } - - /// - /// Custom guild emojis. - /// - [JsonPropertyName("emojis")] - public Emoji[] Emojis { get; } - - /// - /// Enabled guild features. - /// - [JsonPropertyName("features")] - public string[] Features { get; } - - /// - /// Required MFA level for the guild. - /// - [JsonPropertyName("mfa_level")] - public int MfaLevel { get; } - - /// - /// Application id of the guild creator if it is bot-created. - /// - [JsonPropertyName("application_id")] - public Snowflake? ApplicationId { get; } - - /// - /// The id of the channel where guild notices such as welcome messages and boost events are posted. - /// - [JsonPropertyName("system_channel_id")] - public Snowflake? SystemChannelId { get; } - - /// - /// System channel flags. - /// - [JsonPropertyName("system_channel_flags")] - public int SystemChannelFlags { get; } - - /// - /// The id of the channel where Community guilds can display rules and/or guidelines. - /// - [JsonPropertyName("rules_channel_id")] - public Snowflake? RulesChannelId { get; } - - /// - /// When this guild was joined at. - /// - [JsonPropertyName("joined_at")] - public Optional JoinedAt { get; } - - /// - /// True if this is considered a large guild. - /// - [JsonPropertyName("large")] - public Optional Large { get; } - - /// - /// True if this guild is unavailable due to an outage. - /// - [JsonPropertyName("unavailable")] - public Optional Unavailable { get; } - - /// - /// Total number of members in this guild. - /// - [JsonPropertyName("member_count")] - public Optional MemberCount { get; } - - /// - /// States of members currently in voice channels; lacks the guild_id key. - /// - [JsonPropertyName("voice_states")] - public Optional VoiceStates { get; } - - /// - /// Users in the guild. - /// - [JsonPropertyName("members")] - public Optional Members { get; } - - /// - /// Channels in the guild. - /// - [JsonPropertyName("channels")] - public Optional Channels { get; } - - /// - /// All active threads in the guild that current user has permission to view. - /// - [JsonPropertyName("threads")] - public Optional Threads { get; } - - /// - /// Presences of the members in the guild, will only include non-offline members if the size is greater than large threshold. - /// - [JsonPropertyName("presences")] - public Optional Presences { get; } - - /// - /// The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned). - /// - [JsonPropertyName("max_presences")] - public Optional MaxPresences { get; } - - /// - /// The maximum number of members for the guild. - /// - [JsonPropertyName("max_members")] - public Optional MaxMembers { get; } - - /// - /// The vanity url code for the guild. - /// - [JsonPropertyName("vanity_url_code")] - public string? VanityUrlCode { get; } - - /// - /// The description of a Community guild. - /// - [JsonPropertyName("description")] - public string? Description { get; } - - /// - /// Banner hash. - /// - [JsonPropertyName("banner")] - public string? Banner { get; } - - /// - /// Premium tier (Server Boost level). - /// - [JsonPropertyName("premium_tier")] - public int PremiumTier { get; } - - /// - /// The number of boosts this guild currently has. - /// - [JsonPropertyName("premium_subscription_count")] - public Optional PremiumSubscriptionCount { get; } - - /// - /// The preferred locale of a Community guild; used in server discovery and notices from Discord; defaults to "en-US". - /// - [JsonPropertyName("preferred_locale")] - public string PreferredLocale { get; } - - /// - /// The id of the channel where admins and moderators of Community guilds receive notices from Discord. - /// - [JsonPropertyName("public_updates_channel_id")] - public Snowflake? PublicUpdatesChannelId { get; } - - /// - /// The maximum amount of users in a video channel. - /// - [JsonPropertyName("max_video_channel_users")] - public Optional MaxVideoChannelUsers { get; } - - /// - /// Approximate number of members in this guild. - /// - [JsonPropertyName("approximate_member_count")] - public Optional ApproximateMemberCount { get; } - - /// - /// Approximate number of non-offline members in this guild. - /// - [JsonPropertyName("approximate_presence_count")] - public Optional ApproximatePresenceCount { get; } - - /// - /// The welcome screen of a Community guild, shown to new members, returned in an Invite's guild object. - /// - [JsonPropertyName("welcome_screen")] - public Optional WelcomeScreen { get; } - - /// - /// Guild NSFW level. - /// - [JsonPropertyName("nsfw_level")] - public int NsfwLevel { get; } - - /// - /// Stage instances in the guild. - /// - [JsonPropertyName("stage_instances")] - public Optional StageInstances { get; } - } -} diff --git a/src/Models/Guild/GuildMember.cs b/src/Models/Guild/GuildMember.cs deleted file mode 100644 index e384912789..0000000000 --- a/src/Models/Guild/GuildMember.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a guild member object. - /// - public record GuildMember - { - /// - /// Creates a with the provided parameters. - /// - /// The user this guild member represents. - /// This users guild nickname. - /// Array of role object ids. - /// When the user joined the guild. - /// When the user started boosting the guild. - /// Whether the user is deafened in voice channels. - /// Whether the user is muted in voice channels. - /// Whether the user has not yet passed the guild's Membership Screening requirements. - /// Total permissions of the member in the channel, including overwrites, returned when in the interaction object. - [JsonConstructor] - public GuildMember(Optional user, Optional nick, Snowflake[] roles, DateTimeOffset joinedAt, Optional premiumSince, bool deaf, bool mute, Optional pending, Optional permissions) - { - User = user; - Nick = nick; - Roles = roles; - JoinedAt = joinedAt; - PremiumSince = premiumSince; - Deaf = deaf; - Mute = mute; - Pending = pending; - Permissions = permissions; - } - - /// - /// The user this guild member represents. - /// - [JsonPropertyName("user")] - public Optional User { get; } - - /// - /// This users guild nickname. - /// - [JsonPropertyName("nick")] - public Optional Nick { get; } - - /// - /// Array of role object ids. - /// - [JsonPropertyName("roles")] - public Snowflake[] Roles { get; } - - /// - /// When the user joined the guild. - /// - [JsonPropertyName("joined_at")] - public DateTimeOffset JoinedAt { get; } - - /// - /// When the user started boosting the guild. - /// - [JsonPropertyName("premium_since")] - public Optional PremiumSince { get; } - - /// - /// Whether the user is deafened in voice channels. - /// - [JsonPropertyName("deaf")] - public bool Deaf { get; } - - /// - /// Whether the user is muted in voice channels. - /// - [JsonPropertyName("mute")] - public bool Mute { get; } - - /// - /// Whether the user has not yet passed the guild's Membership Screening requirements. - /// - [JsonPropertyName("pending")] - public Optional Pending { get; } - - /// - /// Total permissions of the member in the channel, including overwrites, returned when in the interaction object. - /// - [JsonPropertyName("permissions")] - public Optional Permissions { get; } - } -} diff --git a/src/Models/Guild/GuildNSFWLevel.cs b/src/Models/Guild/GuildNSFWLevel.cs deleted file mode 100644 index d04740df11..0000000000 --- a/src/Models/Guild/GuildNSFWLevel.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the guild NSFW level. - /// - public enum GuildNsfwLevel - { - /// - /// Default level. - /// - Default = 0, - - /// - /// Guild contains explicit content. - /// - Explicit = 1, - - /// - /// Guild is safe for work. - /// - Safe = 2, - - /// - /// Guild has an age restriction. - /// - AgeRestricted = 3, - } -} diff --git a/src/Models/Guild/GuildPreview.cs b/src/Models/Guild/GuildPreview.cs deleted file mode 100644 index 570bf3a026..0000000000 --- a/src/Models/Guild/GuildPreview.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a guild preview object. - /// - public record GuildPreview - { - /// - /// Creates a with the provided parameters. - /// - /// Guild id. - /// Guild name (2-100 characters). - /// Icon hash. - /// Splash hash. - /// Discovery splash hash. - /// Custom guild emojis. - /// Enabled guild features. - /// Approximate number of members in this guild. - /// Approximate number of online members in this guild. - /// The description for the guild, if the guild is discoverable. - [JsonConstructor] - public GuildPreview(Snowflake id, string name, string? icon, string? splash, string? discoverySplash, Emoji[] emojis, string[] features, int approximateMemberCount, int approximatePresenceCount, string? description) - { - Id = id; - Name = name; - Icon = icon; - Splash = splash; - DiscoverySplash = discoverySplash; - Emojis = emojis; - Features = features; - ApproximateMemberCount = approximateMemberCount; - ApproximatePresenceCount = approximatePresenceCount; - Description = description; - } - - /// - /// Guild id. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Guild name (2-100 characters). - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// Icon hash. - /// - [JsonPropertyName("icon")] - public string? Icon { get; } - - /// - /// Splash hash. - /// - [JsonPropertyName("splash")] - public string? Splash { get; } - - /// - /// Discovery splash hash. - /// - [JsonPropertyName("discovery_splash")] - public string? DiscoverySplash { get; } - - /// - /// Custom guild emojis. - /// - [JsonPropertyName("emojis")] - public Emoji[] Emojis { get; } - - /// - /// Enabled guild features. - /// - [JsonPropertyName("features")] - public string[] Features { get; } - - /// - /// Approximate number of members in this guild. - /// - [JsonPropertyName("approximate_member_count")] - public int ApproximateMemberCount { get; } - - /// - /// Approximate number of online members in this guild. - /// - [JsonPropertyName("approximate_presence_count")] - public int ApproximatePresenceCount { get; } - - /// - /// The description for the guild, if the guild is discoverable. - /// - [JsonPropertyName("description")] - public string? Description { get; } - } -} diff --git a/src/Models/Guild/GuildWidget.cs b/src/Models/Guild/GuildWidget.cs deleted file mode 100644 index 1fec9a51cc..0000000000 --- a/src/Models/Guild/GuildWidget.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a guild widget object. - /// - public record GuildWidget - { - /// - /// Creates a with the provided parameters. - /// - /// Whether the widget is enabled. - /// The widget channel id. - [JsonConstructor] - public GuildWidget(bool enabled, Snowflake? channelId) - { - Enabled = enabled; - ChannelId = channelId; - } - - /// - /// Whether the widget is enabled. - /// - [JsonPropertyName("enabled")] - public bool Enabled { get; } - - /// - /// The widget channel id. - /// - [JsonPropertyName("channel_id")] - public Snowflake? ChannelId { get; } - } -} diff --git a/src/Models/Guild/Integration.cs b/src/Models/Guild/Integration.cs deleted file mode 100644 index 3dbf7a7532..0000000000 --- a/src/Models/Guild/Integration.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a integration object. - /// - public record Integration - { - /// - /// Creates a with the provided parameters. - /// - /// Integration id. - /// Integration name. - /// Integration type (twitch, youtube, or discord). - /// Is this integration enabled. - /// Is this integration syncing. - /// Id that this integration uses for "subscribers". - /// Whether emoticons should be synced for this integration (twitch only currently). - /// The behavior of expiring subscribers. - /// The grace period (in days) before expiring subscribers. - /// User for this integration. - /// Integration account information. - /// When this integration was last synced. - /// How many subscribers this integration has. - /// Has this integration been revoked. - /// The bot/OAuth2 application for discord integrations. - [JsonConstructor] - public Integration(Snowflake id, string name, string type, bool enabled, Optional syncing, Optional roleId, Optional enableEmoticons, Optional expireBehavior, Optional expireGracePeriod, Optional user, IntegrationAccount account, Optional syncedAt, Optional subscriberCount, Optional revoked, Optional application) - { - Id = id; - Name = name; - Type = type; - Enabled = enabled; - Syncing = syncing; - RoleId = roleId; - EnableEmoticons = enableEmoticons; - ExpireBehavior = expireBehavior; - ExpireGracePeriod = expireGracePeriod; - User = user; - Account = account; - SyncedAt = syncedAt; - SubscriberCount = subscriberCount; - Revoked = revoked; - Application = application; - } - - /// - /// Integration id. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Integration name. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// Integration type (twitch, youtube, or discord). - /// - [JsonPropertyName("type")] - public string Type { get; } - - /// - /// Is this integration enabled. - /// - [JsonPropertyName("enabled")] - public bool Enabled { get; } - - /// - /// Is this integration syncing. - /// - [JsonPropertyName("syncing")] - public Optional Syncing { get; } - - /// - /// Id that this integration uses for "subscribers". - /// - [JsonPropertyName("role_id")] - public Optional RoleId { get; } - - /// - /// Whether emoticons should be synced for this integration (twitch only currently). - /// - [JsonPropertyName("enable_emoticons")] - public Optional EnableEmoticons { get; } - - /// - /// The behavior of expiring subscribers. - /// - [JsonPropertyName("expire_behavior")] - public Optional ExpireBehavior { get; } - - /// - /// The grace period (in days) before expiring subscribers. - /// - [JsonPropertyName("expire_grace_period")] - public Optional ExpireGracePeriod { get; } - - /// - /// User for this integration. - /// - [JsonPropertyName("user")] - public Optional User { get; } - - /// - /// Integration account information. - /// - [JsonPropertyName("account")] - public IntegrationAccount Account { get; } - - /// - /// When this integration was last synced. - /// - [JsonPropertyName("synced_at")] - public Optional SyncedAt { get; } - - /// - /// How many subscribers this integration has. - /// - [JsonPropertyName("subscriber_count")] - public Optional SubscriberCount { get; } - - /// - /// Has this integration been revoked. - /// - [JsonPropertyName("revoked")] - public Optional Revoked { get; } - - /// - /// The bot/OAuth2 application for discord integrations. - /// - [JsonPropertyName("application")] - public Optional Application { get; } - } -} diff --git a/src/Models/Guild/IntegrationAccount.cs b/src/Models/Guild/IntegrationAccount.cs deleted file mode 100644 index 2f16117e8b..0000000000 --- a/src/Models/Guild/IntegrationAccount.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a integration account object. - /// - public record IntegrationAccount - { - /// - /// Creates a with the provided parameters. - /// - /// Id of the account. - /// Name of the account. - [JsonConstructor] - public IntegrationAccount(string id, string name) - { - Id = id; - Name = name; - } - - /// - /// Id of the account. - /// - [JsonPropertyName("id")] - public string Id { get; } - - /// - /// Name of the account. - /// - [JsonPropertyName("name")] - public string Name { get; } - } -} diff --git a/src/Models/Guild/IntegrationApplication.cs b/src/Models/Guild/IntegrationApplication.cs deleted file mode 100644 index 50e8c4ab7b..0000000000 --- a/src/Models/Guild/IntegrationApplication.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a integration application object. - /// - public record IntegrationApplication - { - /// - /// Creates a with the provided parameters. - /// - /// The id of the app. - /// The name of the app. - /// The icon hash of the app. - /// The description of the app. - /// The description of the app. - /// The bot associated with this application. - [JsonConstructor] - public IntegrationApplication(Snowflake id, string name, string? icon, string description, string summary, Optional bot) - { - Id = id; - Name = name; - Icon = icon; - Description = description; - Summary = summary; - Bot = bot; - } - - /// - /// The id of the app. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The name of the app. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// The icon hash of the app. - /// - [JsonPropertyName("icon")] - public string? Icon { get; } - - /// - /// The description of the app. - /// - [JsonPropertyName("description")] - public string Description { get; } - - /// - /// The description of the app. - /// - [JsonPropertyName("summary")] - public string Summary { get; } - - /// - /// The bot associated with this application. - /// - [JsonPropertyName("bot")] - public Optional Bot { get; } - } -} diff --git a/src/Models/Guild/IntegrationExpireBehavior.cs b/src/Models/Guild/IntegrationExpireBehavior.cs deleted file mode 100644 index 1f121cfc12..0000000000 --- a/src/Models/Guild/IntegrationExpireBehavior.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the integration expire behavior. - /// - public enum IntegrationExpireBehavior - { - /// - /// It will remove the role. - /// - RemoveRole = 0, - - /// - /// It will kick the member. - /// - Kick = 1, - } -} diff --git a/src/Models/Guild/MFALevel.cs b/src/Models/Guild/MFALevel.cs deleted file mode 100644 index 4b0a2628c4..0000000000 --- a/src/Models/Guild/MFALevel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the m f a level. - /// - public enum MfaLevel - { - /// - /// Guild has no MFA/2FA requirement for moderation actions. - /// - None = 0, - - /// - /// Guild has a 2FA requirement for moderation actions. - /// - Elevated = 1, - } -} diff --git a/src/Models/Guild/PremiumTier.cs b/src/Models/Guild/PremiumTier.cs deleted file mode 100644 index 18264b093b..0000000000 --- a/src/Models/Guild/PremiumTier.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the premium tier. - /// - public enum PremiumTier - { - /// - /// Guild has not unlocked any Server Boost perks. - /// - None = 0, - - /// - /// Guild has unlocked Server Boost level 1 perks. - /// - Tier1 = 1, - - /// - /// Guild has unlocked Server Boost level 2 perks. - /// - Tier2 = 2, - - /// - /// Guild has unlocked Server Boost level 3 perks. - /// - Tier3 = 3, - } -} diff --git a/src/Models/Guild/SystemChannelFlags.cs b/src/Models/Guild/SystemChannelFlags.cs deleted file mode 100644 index c5c040ac8e..0000000000 --- a/src/Models/Guild/SystemChannelFlags.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the system channel flags. - /// - [Flags] - public enum SystemChannelFlags - { - /// - /// Suppress member join notifications. - /// - SuppressJoinNotifications = 1 << 0, - - /// - /// Suppress server boost notifications. - /// - SuppressPremiumSubscriptions = 1 << 1, - - /// - /// Suppress server setup tips. - /// - SuppressGuildReminderNotifications = 1 << 2, - } -} diff --git a/src/Models/Guild/VerificationLevel.cs b/src/Models/Guild/VerificationLevel.cs deleted file mode 100644 index 4e16e1ba89..0000000000 --- a/src/Models/Guild/VerificationLevel.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the verification level. - /// - public enum VerificationLevel - { - /// - /// Unrestricted. - /// - None = 0, - - /// - /// Must have verified email on account. - /// - Low = 1, - - /// - /// Must be registered on Discord for longer than 5 minutes. - /// - Medium = 2, - - /// - /// Must be a member of the server for longer than 10 minutes. - /// - High = 3, - - /// - /// Must have a verified phone number. - /// - VeryHigh = 4, - } -} diff --git a/src/Models/Guild/WelcomeScreen.cs b/src/Models/Guild/WelcomeScreen.cs deleted file mode 100644 index eaddf1ae37..0000000000 --- a/src/Models/Guild/WelcomeScreen.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a welcome screen object. - /// - public record WelcomeScreen - { - /// - /// Creates a with the provided parameters. - /// - /// The server description shown in the welcome screen. - /// The channels shown in the welcome screen, up to 5. - [JsonConstructor] - public WelcomeScreen(string? description, WelcomeScreenChannel[] welcomeChannels) - { - Description = description; - WelcomeChannels = welcomeChannels; - } - - /// - /// The server description shown in the welcome screen. - /// - [JsonPropertyName("description")] - public string? Description { get; } - - /// - /// The channels shown in the welcome screen, up to 5. - /// - [JsonPropertyName("welcome_channels")] - public WelcomeScreenChannel[] WelcomeChannels { get; } - } -} diff --git a/src/Models/Guild/WelcomeScreenChannel.cs b/src/Models/Guild/WelcomeScreenChannel.cs deleted file mode 100644 index e77bde5d8f..0000000000 --- a/src/Models/Guild/WelcomeScreenChannel.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a welcome screen channel object. - /// - public record WelcomeScreenChannel - { - /// - /// Creates a with the provided parameters. - /// - /// The channel's id. - /// The description shown for the channel. - /// The emoji id, if the emoji is custom. - /// The emoji name if custom, the unicode character if standard, or null if no emoji is set. - [JsonConstructor] - public WelcomeScreenChannel(Snowflake channelId, string description, Snowflake? emojiId, string? emojiName) - { - ChannelId = channelId; - Description = description; - EmojiId = emojiId; - EmojiName = emojiName; - } - - /// - /// The channel's id. - /// - [JsonPropertyName("channel_id")] - public Snowflake ChannelId { get; } - - /// - /// The description shown for the channel. - /// - [JsonPropertyName("description")] - public string Description { get; } - - /// - /// The emoji id, if the emoji is custom. - /// - [JsonPropertyName("emoji_id")] - public Snowflake? EmojiId { get; } - - /// - /// The emoji name if custom, the unicode character if standard, or null if no emoji is set. - /// - [JsonPropertyName("emoji_name")] - public string? EmojiName { get; } - } -} diff --git a/src/Models/GuildTemplate/GuildTemplate.cs b/src/Models/GuildTemplate/GuildTemplate.cs deleted file mode 100644 index fbbb96fe72..0000000000 --- a/src/Models/GuildTemplate/GuildTemplate.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a guild template object. - /// - public record GuildTemplate - { - /// - /// Creates a with the provided parameters. - /// - /// The template code (unique ID). - /// Template name. - /// The description for the template. - /// Number of times this template has been used. - /// The ID of the user who created the template. - /// The user who created the template. - /// When this template was created. - /// When this template was last synced to the source guild. - /// The ID of the guild this template is based on. - /// The guild snapshot this template contains. - /// Whether the template has unsynced changes. - [JsonConstructor] - public GuildTemplate(string code, string name, string? description, int usageCount, Snowflake creatorId, User creator, DateTimeOffset createdAt, DateTimeOffset updatedAt, Snowflake sourceGuildId, Guild serializedSourceGuild, bool? isDirty) - { - Code = code; - Name = name; - Description = description; - UsageCount = usageCount; - CreatorId = creatorId; - Creator = creator; - CreatedAt = createdAt; - UpdatedAt = updatedAt; - SourceGuildId = sourceGuildId; - SerializedSourceGuild = serializedSourceGuild; - IsDirty = isDirty; - } - - /// - /// The template code (unique ID). - /// - [JsonPropertyName("code")] - public string Code { get; } - - /// - /// Template name. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// The description for the template. - /// - [JsonPropertyName("description")] - public string? Description { get; } - - /// - /// Number of times this template has been used. - /// - [JsonPropertyName("usage_count")] - public int UsageCount { get; } - - /// - /// The ID of the user who created the template. - /// - [JsonPropertyName("creator_id")] - public Snowflake CreatorId { get; } - - /// - /// The user who created the template. - /// - [JsonPropertyName("creator")] - public User Creator { get; } - - /// - /// When this template was created. - /// - [JsonPropertyName("created_at")] - public DateTimeOffset CreatedAt { get; } - - /// - /// When this template was last synced to the source guild. - /// - [JsonPropertyName("updated_at")] - public DateTimeOffset UpdatedAt { get; } - - /// - /// The ID of the guild this template is based on. - /// - [JsonPropertyName("source_guild_id")] - public Snowflake SourceGuildId { get; } - - /// - /// The guild snapshot this template contains. - /// - [JsonPropertyName("serialized_source_guild")] - public Guild SerializedSourceGuild { get; } - - /// - /// Whether the template has unsynced changes. - /// - [JsonPropertyName("is_dirty")] - public bool? IsDirty { get; } - } -} diff --git a/src/Models/Invite/Invite.cs b/src/Models/Invite/Invite.cs deleted file mode 100644 index ba926000d1..0000000000 --- a/src/Models/Invite/Invite.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a invite object. - /// - public record Invite - { - /// - /// Creates a with the provided parameters. - /// - /// The invite code (unique ID). - /// The guild this invite is for. - /// The channel this invite is for. - /// The user who created the invite. - /// The type of target for this voice channel invite. - /// The user whose stream to display for this voice channel stream invite. - /// The embedded application to open for this voice channel embedded application invite. - /// Approximate count of online members. - /// Approximate count of total members. - /// The expiration date of this invite. - [JsonConstructor] - public Invite(string code, Optional guild, Channel channel, Optional inviter, Optional targetType, Optional targetUser, Optional targetApplication, Optional approximatePresenceCount, Optional approximateMemberCount, Optional expiresAt) - { - Code = code; - Guild = guild; - Channel = channel; - Inviter = inviter; - TargetType = targetType; - TargetUser = targetUser; - TargetApplication = targetApplication; - ApproximatePresenceCount = approximatePresenceCount; - ApproximateMemberCount = approximateMemberCount; - ExpiresAt = expiresAt; - } - - /// - /// The invite code (unique ID). - /// - [JsonPropertyName("code")] - public string Code { get; } - - /// - /// The guild this invite is for. - /// - [JsonPropertyName("guild")] - public Optional Guild { get; } - - /// - /// The channel this invite is for. - /// - [JsonPropertyName("channel")] - public Channel Channel { get; } - - /// - /// The user who created the invite. - /// - [JsonPropertyName("inviter")] - public Optional Inviter { get; } - - /// - /// The type of target for this voice channel invite. - /// - [JsonPropertyName("target_type")] - public Optional TargetType { get; } - - /// - /// The user whose stream to display for this voice channel stream invite. - /// - [JsonPropertyName("target_user")] - public Optional TargetUser { get; } - - /// - /// The embedded application to open for this voice channel embedded application invite. - /// - [JsonPropertyName("target_application")] - public Optional TargetApplication { get; } - - /// - /// Approximate count of online members. - /// - [JsonPropertyName("approximate_presence_count")] - public Optional ApproximatePresenceCount { get; } - - /// - /// Approximate count of total members. - /// - [JsonPropertyName("approximate_member_count")] - public Optional ApproximateMemberCount { get; } - - /// - /// The expiration date of this invite. - /// - [JsonPropertyName("expires_at")] - public Optional ExpiresAt { get; } - } -} diff --git a/src/Models/Invite/InviteMetadata.cs b/src/Models/Invite/InviteMetadata.cs deleted file mode 100644 index d39d6faee8..0000000000 --- a/src/Models/Invite/InviteMetadata.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a invite metadata object. - /// - public record InviteMetadata : Invite - { - /// - /// Creates a with the provided parameters. - /// - /// The invite code (unique ID). - /// The guild this invite is for. - /// The channel this invite is for. - /// The user who created the invite. - /// The type of target for this voice channel invite. - /// The user whose stream to display for this voice channel stream invite. - /// The embedded application to open for this voice channel embedded application invite. - /// Approximate count of online members. - /// Approximate count of total members. - /// The expiration date of this invite. - /// Number of times this invite has been used. - /// Max number of times this invite can be used. - /// Duration (in seconds) after which the invite expires. - /// Whether this invite only grants temporary membership. - /// When this invite was created. - [JsonConstructor] - public InviteMetadata(string code, Optional guild, Channel channel, Optional inviter, Optional targetType, Optional targetUser, Optional targetApplication, Optional approximatePresenceCount, Optional approximateMemberCount, Optional expiresAt, int uses, int maxUses, int maxAge, bool temporary, DateTimeOffset createdAt) - : base(code, guild, channel, inviter, targetType, targetUser, targetApplication, approximatePresenceCount, approximateMemberCount, expiresAt) - { - Uses = uses; - MaxUses = maxUses; - MaxAge = maxAge; - Temporary = temporary; - CreatedAt = createdAt; - } - - /// - /// Number of times this invite has been used. - /// - [JsonPropertyName("uses")] - public int Uses { get; } - - /// - /// Max number of times this invite can be used. - /// - [JsonPropertyName("max_uses")] - public int MaxUses { get; } - - /// - /// Duration (in seconds) after which the invite expires. - /// - [JsonPropertyName("max_age")] - public int MaxAge { get; } - - /// - /// Whether this invite only grants temporary membership. - /// - [JsonPropertyName("temporary")] - public bool Temporary { get; } - - /// - /// When this invite was created. - /// - [JsonPropertyName("created_at")] - public DateTimeOffset CreatedAt { get; } - } -} diff --git a/src/Models/Invite/InviteTargetType.cs b/src/Models/Invite/InviteTargetType.cs deleted file mode 100644 index 8e236920c0..0000000000 --- a/src/Models/Invite/InviteTargetType.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the invite target type. - /// - public enum InviteTargetType - { - /// - /// - /// - Stream = 1, - - /// - /// - /// - EmbeddedApplication = 2, - } -} diff --git a/src/Models/MessageComponents/ActionRowComponent.cs b/src/Models/MessageComponents/ActionRowComponent.cs deleted file mode 100644 index aca1df2dd8..0000000000 --- a/src/Models/MessageComponents/ActionRowComponent.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a component object. - /// - public record ActionRowComponent : Component - { - /// - /// Creates an with the provided parameters. - /// - /// Component type. - [JsonConstructor] - public ActionRowComponent(ComponentType type) - : base(type) - { - } - - /// - /// Components inside this action row, like buttons or other interactive components. - /// - [JsonPropertyName("components")] - public Optional Components { get; } - } -} diff --git a/src/Models/MessageComponents/ButtonComponent.cs b/src/Models/MessageComponents/ButtonComponent.cs deleted file mode 100644 index 406f151f76..0000000000 --- a/src/Models/MessageComponents/ButtonComponent.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a button component object. - /// - public record ButtonComponent : Component - { - /// - /// Creates a with the provided parameters. - /// - /// Component type. - /// One of button styles. - /// Text that appears on the button, max 80 characters. - /// Name, id, and animated. - /// A developer-defined identifier for the button, max 100 characters. - /// A url for link-style buttons. - /// Whether the button is disabled, default false. - [JsonConstructor] - public ButtonComponent(ComponentType type, Optional style, Optional label, Optional emoji, Optional customId, Optional url, Optional disabled) - : base(type) - { - Style = style; - Label = label; - Emoji = emoji; - CustomId = customId; - Url = url; - Disabled = disabled; - } - - /// - /// One of button styles. - /// - [JsonPropertyName("style")] - public Optional Style { get; } - - /// - /// Text that appears on the button, max 80 characters. - /// - [JsonPropertyName("label")] - public Optional Label { get; } - - /// - /// Name, id, and animated. - /// - [JsonPropertyName("emoji")] - public Optional Emoji { get; } - - /// - /// A developer-defined identifier for the button, max 100 characters. - /// - [JsonPropertyName("custom_id")] - public Optional CustomId { get; } - - /// - /// A url for link-style buttons. - /// - [JsonPropertyName("url")] - public Optional Url { get; } - - /// - /// Whether the button is disabled, default false. - /// - [JsonPropertyName("disabled")] - public Optional Disabled { get; } - } -} diff --git a/src/Models/MessageComponents/ButtonStyle.cs b/src/Models/MessageComponents/ButtonStyle.cs deleted file mode 100644 index 38a808c773..0000000000 --- a/src/Models/MessageComponents/ButtonStyle.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Represents the button style type. - /// - public enum ButtonStyle - { - /// - /// Blurple. - /// - Primary = 1, - - /// - /// Grey. - /// - Secondary = 2, - - /// - /// Green. - /// - Success = 3, - - /// - /// Red. - /// - Danger = 4, - - /// - /// Grey, navigates to a URL. - /// - Link = 5, - } -} diff --git a/src/Models/MessageComponents/Component.cs b/src/Models/MessageComponents/Component.cs deleted file mode 100644 index 7fe2ed9bde..0000000000 --- a/src/Models/MessageComponents/Component.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a component object. - /// - public record Component - { - /// - /// Creates a with the provided parameters. - /// - /// Component type. - [JsonConstructor] - public Component(ComponentType type) - { - Type = type; - } - - /// - /// Component type. - /// - [JsonPropertyName("type")] - public ComponentType Type { get; } - } -} diff --git a/src/Models/MessageComponents/ComponentType.cs b/src/Models/MessageComponents/ComponentType.cs deleted file mode 100644 index 76fcd08339..0000000000 --- a/src/Models/MessageComponents/ComponentType.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the component type. - /// - public enum ComponentType - { - /// - /// A container for other components. - /// - ActionRow = 1, - - /// - /// A clickable button. - /// - Button = 2, - } -} diff --git a/src/Models/Optional.cs b/src/Models/Optional.cs deleted file mode 100644 index ba31cb061e..0000000000 --- a/src/Models/Optional.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; - -namespace Discord.Net -{ - /// - /// Container to keep a type that might not be present. - /// - /// Inner type - public struct Optional - { - private readonly T _value; - - /// - /// Gets the inner value of this if present. - /// - /// The value inside this . - /// This has no inner value. - public T Value => !IsSpecified ? throw new InvalidOperationException("This property has no value set.") : _value; - - /// - /// Gets if this has an inner value. - /// - /// A boolean that determines if this has a . - public bool IsSpecified { get; } - - private Optional(T value) - { - _value = value; - IsSpecified = true; - } - - /// - /// Creates a new unspecified . - /// - /// An unspecified . - public static Optional Create() - => default; - - /// - /// Creates a new with the specified . - /// - /// Value that will be specified for this . - /// A specified with the provided value inside. - public static Optional Create(T value) - => new(value); - - /// - /// Gets the or their value. - /// - /// The value inside this or their value. - public T GetValueOrDefault() - => _value; - - /// - /// Gets the or the default value provided. - /// - /// The value inside this or default value provided. - public T GetValueOrDefault(T defaultValue) - => IsSpecified ? _value : defaultValue; - - /// - public override bool Equals(object? other) - { - if (!IsSpecified) - return other == null; - if (other == null || _value == null) - return false; - return _value.Equals(other); - } - - /// - public override int GetHashCode() - => IsSpecified ? _value?.GetHashCode() ?? default : default; - - /// - /// Returns the inner value ToString value or this type fully qualified name. - /// - /// The inner value string value or this type fully qualified name. - public override string? ToString() - => IsSpecified ? _value?.ToString() : default; - - /// - /// Creates a new with the specified . - /// - /// Value to convert - /// A new with the specified - public static implicit operator Optional(T value) - => new(value); - - /// - /// Gets the inner value. - /// - /// Value to convert - /// The inner value - public static explicit operator T(Optional value) - => value.Value; - } -} diff --git a/src/Models/Permissions/Permissions.cs b/src/Models/Permissions/Permissions.cs deleted file mode 100644 index 46313fcaa9..0000000000 --- a/src/Models/Permissions/Permissions.cs +++ /dev/null @@ -1,191 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the permissions flags. - /// - [Flags] - public enum Permissions - { - /// - /// Allows creation of instant invites. - /// - CreateInstantInvite = 1 << 0, - - /// - /// Allows kicking members. - /// - KickMembers = 1 << 1, - - /// - /// Allows banning members. - /// - BanMembers = 1 << 2, - - /// - /// Allows all permissions and bypasses channel permission overwrites. - /// - Administrator = 1 << 3, - - /// - /// Allows management and editing of channels. - /// - ManageChannels = 1 << 4, - - /// - /// Allows management and editing of the guild. - /// - ManageGuild = 1 << 5, - - /// - /// Allows for the addition of reactions to messages. - /// - AddReactions = 1 << 6, - - /// - /// Allows for viewing of audit logs. - /// - ViewAuditLog = 1 << 7, - - /// - /// Allows for using priority speaker in a voice channel. - /// - PrioritySpeaker = 1 << 8, - - /// - /// Allows the user to go live. - /// - Stream = 1 << 9, - - /// - /// Allows guild members to view a channel, which includes reading messages in text channels. - /// - ViewChannel = 1 << 10, - - /// - /// Allows for sending messages in a channel. - /// - SendMessages = 1 << 11, - - /// - /// Allows for sending of /tts messages. - /// - SendTtsMessages = 1 << 12, - - /// - /// Allows for deletion of other users messages. - /// - ManageMessages = 1 << 13, - - /// - /// Links sent by users with this permission will be auto-embedded. - /// - EmbedLinks = 1 << 14, - - /// - /// Allows for uploading images and files. - /// - AttachFiles = 1 << 15, - - /// - /// Allows for reading of message history. - /// - ReadMessageHistory = 1 << 16, - - /// - /// Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all online users in a channel. - /// - MentionEveryone = 1 << 17, - - /// - /// Allows the usage of custom emojis from other servers. - /// - UseExternalEmojis = 1 << 18, - - /// - /// Allows for viewing guild insights. - /// - ViewGuildInsights = 1 << 19, - - /// - /// Allows for joining of a voice channel. - /// - Connect = 1 << 20, - - /// - /// Allows for speaking in a voice channel. - /// - Speak = 1 << 21, - - /// - /// Allows for muting members in a voice channel. - /// - MuteMembers = 1 << 22, - - /// - /// Allows for deafening of members in a voice channel. - /// - DeafenMembers = 1 << 23, - - /// - /// Allows for moving of members between voice channels. - /// - MoveMembers = 1 << 24, - - /// - /// Allows for using voice-activity-detection in a voice channel. - /// - UseVad = 1 << 25, - - /// - /// Allows for modification of own nickname. - /// - ChangeNickname = 1 << 26, - - /// - /// Allows for modification of other users nicknames. - /// - ManageNicknames = 1 << 27, - - /// - /// Allows management and editing of roles. - /// - ManageRoles = 1 << 28, - - /// - /// Allows management and editing of webhooks. - /// - ManageWebhooks = 1 << 29, - - /// - /// Allows management and editing of emojis. - /// - ManageEmojis = 1 << 30, - - /// - /// Allows members to use slash commands in text channels. - /// - UseSlashCommands = 1 << 31, - - /// - /// Allows for requesting to speak in stage channels. (This permission is under active development and may be changed or removed.). - /// - RequestToSpeak = 1 << 32, - - /// - /// Allows for deleting and archiving threads, and viewing all private threads. - /// - ManageThreads = 1 << 34, - - /// - /// Allows for creating and participating in threads. - /// - UsePublicThreads = 1 << 35, - - /// - /// Allows for creating and participating in private threads. - /// - UsePrivateThreads = 1 << 36, - } -} diff --git a/src/Models/Permissions/Role.cs b/src/Models/Permissions/Role.cs deleted file mode 100644 index f51d3ddc6c..0000000000 --- a/src/Models/Permissions/Role.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a role object. - /// - public record Role - { - /// - /// Creates a with the provided parameters. - /// - /// Role id. - /// Role name. - /// Integer representation of hexadecimal color code. - /// If this role is pinned in the user listing. - /// Position of this role. - /// Permission bit set. - /// Whether this role is managed by an integration. - /// Whether this role is mentionable. - /// The tags this role has. - [JsonConstructor] - public Role(Snowflake id, string name, int color, bool hoist, int position, Permissions permissions, bool managed, bool mentionable, Optional tags) - { - Id = id; - Name = name; - Color = color; - Hoist = hoist; - Position = position; - Permissions = permissions; - Managed = managed; - Mentionable = mentionable; - Tags = tags; - } - - /// - /// Role id. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// Role name. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// Integer representation of hexadecimal color code. - /// - [JsonPropertyName("color")] - public int Color { get; } - - /// - /// If this role is pinned in the user listing. - /// - [JsonPropertyName("hoist")] - public bool Hoist { get; } - - /// - /// Position of this role. - /// - [JsonPropertyName("position")] - public int Position { get; } - - /// - /// Permission bit set. - /// - [JsonPropertyName("permissions")] - public Permissions Permissions { get; } - - /// - /// Whether this role is managed by an integration. - /// - [JsonPropertyName("managed")] - public bool Managed { get; } - - /// - /// Whether this role is mentionable. - /// - [JsonPropertyName("mentionable")] - public bool Mentionable { get; } - - /// - /// The tags this role has. - /// - [JsonPropertyName("tags")] - public Optional Tags { get; } - } -} diff --git a/src/Models/Permissions/RoleTags.cs b/src/Models/Permissions/RoleTags.cs deleted file mode 100644 index c12f220581..0000000000 --- a/src/Models/Permissions/RoleTags.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a role tags object. - /// - public record RoleTags - { - /// - /// Creates a with the provided parameters. - /// - /// The id of the bot this role belongs to. - /// The id of the integration this role belongs to. - /// Whether this is the guild's premium subscriber role. - [JsonConstructor] - public RoleTags(Optional botId, Optional integrationId, Optional premiumSubscriber) - { - BotId = botId; - IntegrationId = integrationId; - PremiumSubscriber = premiumSubscriber; - } - - /// - /// The id of the bot this role belongs to. - /// - [JsonPropertyName("bot_id")] - public Optional BotId { get; } - - /// - /// The id of the integration this role belongs to. - /// - [JsonPropertyName("integration_id")] - public Optional IntegrationId { get; } - - /// - /// Whether this is the guild's premium subscriber role. - /// - [JsonPropertyName("premium_subscriber")] - public Optional PremiumSubscriber { get; } - } -} diff --git a/src/Models/SlashCommands/InteractionType.cs b/src/Models/SlashCommands/InteractionType.cs deleted file mode 100644 index ec6a431af6..0000000000 --- a/src/Models/SlashCommands/InteractionType.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Represents the interaction type. - /// - public enum InteractionType - { - /// - /// Received when registering an interaction, replied with a pong. - /// - Ping = 1, - - /// - /// This interaction is from a slash command. - /// - ApplicationCommand = 2, - - /// - /// This interaction is from a component. - /// - MessageComponent = 3, - } -} diff --git a/src/Models/SlashCommands/MessageInteraction.cs b/src/Models/SlashCommands/MessageInteraction.cs deleted file mode 100644 index c341270684..0000000000 --- a/src/Models/SlashCommands/MessageInteraction.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a message interaction object. - /// - public record MessageInteraction - { - /// - /// Creates a with the provided parameters. - /// - /// Id of the interaction. - /// The type of interaction. - /// The name of the ApplicationCommand. - /// The user who invoked the interaction. - [JsonConstructor] - public MessageInteraction(Snowflake id, InteractionType type, string name, User user) - { - Id = id; - Type = type; - Name = name; - User = user; - } - - /// - /// Id of the interaction. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The type of interaction. - /// - [JsonPropertyName("type")] - public InteractionType Type { get; } - - /// - /// The name of the ApplicationCommand. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// The user who invoked the interaction. - /// - [JsonPropertyName("user")] - public User User { get; } - } -} diff --git a/src/Models/StageInstance/PrivacyLevel.cs b/src/Models/StageInstance/PrivacyLevel.cs deleted file mode 100644 index 45e539318b..0000000000 --- a/src/Models/StageInstance/PrivacyLevel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the privacy level. - /// - public enum PrivacyLevel - { - /// - /// The Stage instance is visible publicly, such as on Stage discovery. - /// - Public = 1, - - /// - /// The Stage instance is visible to only guild members. - /// - GuildOnly = 2, - } -} diff --git a/src/Models/StageInstance/StageInstance.cs b/src/Models/StageInstance/StageInstance.cs deleted file mode 100644 index cf63c8337a..0000000000 --- a/src/Models/StageInstance/StageInstance.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a stage instance object. - /// - public record StageInstance - { - /// - /// Creates a with the provided parameters. - /// - /// The id of this Stage instance. - /// The guild id of the associated Stage channel. - /// The id of the associated Stage channel. - /// The topic of the Stage instance (1-120 characters). - /// The privacy level of the Stage instance. - /// Whether or not Stage discovery is disabled. - [JsonConstructor] - public StageInstance(Snowflake id, Snowflake guildId, Snowflake channelId, string topic, PrivacyLevel privacyLevel, bool discoverableDisabled) - { - Id = id; - GuildId = guildId; - ChannelId = channelId; - Topic = topic; - PrivacyLevel = privacyLevel; - DiscoverableDisabled = discoverableDisabled; - } - - /// - /// The id of this Stage instance. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The guild id of the associated Stage channel. - /// - [JsonPropertyName("guild_id")] - public Snowflake GuildId { get; } - - /// - /// The id of the associated Stage channel. - /// - [JsonPropertyName("channel_id")] - public Snowflake ChannelId { get; } - - /// - /// The topic of the Stage instance (1-120 characters). - /// - [JsonPropertyName("topic")] - public string Topic { get; } - - /// - /// The privacy level of the Stage instance. - /// - [JsonPropertyName("privacy_level")] - public PrivacyLevel PrivacyLevel { get; } - - /// - /// Whether or not Stage discovery is disabled. - /// - [JsonPropertyName("discoverable_disabled")] - public bool DiscoverableDisabled { get; } - } -} diff --git a/src/Models/Teams/MembershipState.cs b/src/Models/Teams/MembershipState.cs deleted file mode 100644 index e8d41b8b80..0000000000 --- a/src/Models/Teams/MembershipState.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the membership state type. - /// - public enum MembershipState - { - /// - /// This member has been invited, but did not accept yet. - /// - Invited = 1, - - /// - /// This member accepted the invite. - /// - Accepted = 2, - } -} diff --git a/src/Models/Teams/Team.cs b/src/Models/Teams/Team.cs deleted file mode 100644 index 9fa8fb4723..0000000000 --- a/src/Models/Teams/Team.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a team object. - /// - public record Team - { - /// - /// Creates a with the provided parameters. - /// - /// A hash of the image of the team's icon. - /// The unique id of the team. - /// The members of the team. - /// The name of the team. - /// The user id of the current team owner. - [JsonConstructor] - public Team(string? icon, Snowflake id, TeamMember[] members, string name, Snowflake ownerUserId) - { - Icon = icon; - Id = id; - Members = members; - Name = name; - OwnerUserId = ownerUserId; - } - - /// - /// A hash of the image of the team's icon. - /// - [JsonPropertyName("icon")] - public string? Icon { get; } - - /// - /// The unique id of the team. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The members of the team. - /// - [JsonPropertyName("members")] - public TeamMember[] Members { get; } - - /// - /// The name of the team. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// The user id of the current team owner. - /// - [JsonPropertyName("owner_user_id")] - public Snowflake OwnerUserId { get; } - } -} diff --git a/src/Models/Teams/TeamMember.cs b/src/Models/Teams/TeamMember.cs deleted file mode 100644 index 5e31223e24..0000000000 --- a/src/Models/Teams/TeamMember.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a team member object. - /// - public record TeamMember - { - /// - /// Creates a with the provided parameters. - /// - /// The user's membership state on the team. - /// Will always be ["*"]. - /// The id of the parent team of which they are a member. - /// The avatar, discriminator, id, and username of the user. - [JsonConstructor] - public TeamMember(MembershipState membershipState, string[] permissions, Snowflake teamId, User user) - { - MembershipState = membershipState; - Permissions = permissions; - TeamId = teamId; - User = user; - } - - /// - /// The user's membership state on the team. - /// - [JsonPropertyName("membership_state")] - public MembershipState MembershipState { get; } - - /// - /// Will always be ["*"]. - /// - [JsonPropertyName("permissions")] - public string[] Permissions { get; } - - /// - /// The id of the parent team of which they are a member. - /// - [JsonPropertyName("team_id")] - public Snowflake TeamId { get; } - - /// - /// The avatar, discriminator, id, and username of the user. - /// - [JsonPropertyName("user")] - public User User { get; } - } -} diff --git a/src/Models/User/Connection.cs b/src/Models/User/Connection.cs deleted file mode 100644 index 6d77b84c54..0000000000 --- a/src/Models/User/Connection.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a connection object. - /// - public record Connection - { - /// - /// Creates a with the provided parameters. - /// - /// Id of the connection account. - /// The username of the connection account. - /// The service of the connection (twitch, youtube). - /// Whether the connection is revoked. - /// An array of partial server integrations. - /// Whether the connection is verified. - /// Whether friend sync is enabled for this connection. - /// Whether activities related to this connection will be shown in presence updates. - /// Visibility of this connection. - [JsonConstructor] - public Connection(string id, string name, string type, Optional revoked, Optional integrations, bool verified, bool friendSync, bool showActivity, VisibilityType visibility) - { - Id = id; - Name = name; - Type = type; - Revoked = revoked; - Integrations = integrations; - Verified = verified; - FriendSync = friendSync; - ShowActivity = showActivity; - Visibility = visibility; - } - - /// - /// Id of the connection account. - /// - [JsonPropertyName("id")] - public string Id { get; } - - /// - /// The username of the connection account. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// The service of the connection (twitch, youtube). - /// - [JsonPropertyName("type")] - public string Type { get; } - - /// - /// Whether the connection is revoked. - /// - [JsonPropertyName("revoked")] - public Optional Revoked { get; } - - /// - /// An array of partial server integrations. - /// - [JsonPropertyName("integrations")] - public Optional Integrations { get; } - - /// - /// Whether the connection is verified. - /// - [JsonPropertyName("verified")] - public bool Verified { get; } - - /// - /// Whether friend sync is enabled for this connection. - /// - [JsonPropertyName("friend_sync")] - public bool FriendSync { get; } - - /// - /// Whether activities related to this connection will be shown in presence updates. - /// - [JsonPropertyName("show_activity")] - public bool ShowActivity { get; } - - /// - /// Visibility of this connection. - /// - [JsonPropertyName("visibility")] - public VisibilityType Visibility { get; } - } -} diff --git a/src/Models/User/PremiumType.cs b/src/Models/User/PremiumType.cs deleted file mode 100644 index 7913adbf78..0000000000 --- a/src/Models/User/PremiumType.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the premium type. - /// - public enum PremiumType - { - /// - /// User does not have Nitro. - /// - None = 0, - - /// - /// User has Nitro Classic. - /// - NitroClassic = 1, - - /// - /// User has Nitro. - /// - Nitro = 2, - } -} diff --git a/src/Models/User/User.cs b/src/Models/User/User.cs deleted file mode 100644 index 857d99b403..0000000000 --- a/src/Models/User/User.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a user object. - /// - public record User - { - /// - /// Creates a with the provided parameters. - /// - /// The user's id. - /// The user's username, not unique across the platform. - /// The user's 4-digit discord-tag. - /// The user's avatar hash. - /// Whether the user belongs to an OAuth2 application. - /// Whether the user is an Official Discord System user (part of the urgent message system). - /// Whether the user has two factor enabled on their account. - /// The user's chosen language option. - /// Whether the email on this account has been verified. - /// The user's email. - /// The flags on a user's account. - /// The type of Nitro subscription on a user's account. - /// The public flags on a user's account. - [JsonConstructor] - public User(Snowflake id, string username, string discriminator, string? avatar, Optional bot, Optional system, Optional mfaEnabled, Optional locale, Optional verified, Optional email, Optional flags, Optional premiumType, Optional publicFlags) - { - Id = id; - Username = username; - Discriminator = discriminator; - Avatar = avatar; - Bot = bot; - System = system; - MfaEnabled = mfaEnabled; - Locale = locale; - Verified = verified; - Email = email; - Flags = flags; - PremiumType = premiumType; - PublicFlags = publicFlags; - } - - /// - /// The user's id. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The user's username, not unique across the platform. - /// - [JsonPropertyName("username")] - public string Username { get; } - - /// - /// The user's 4-digit discord-tag. - /// - [JsonPropertyName("discriminator")] - public string Discriminator { get; } - - /// - /// The user's avatar hash. - /// - [JsonPropertyName("avatar")] - public string? Avatar { get; } - - /// - /// Whether the user belongs to an OAuth2 application. - /// - [JsonPropertyName("bot")] - public Optional Bot { get; } - - /// - /// Whether the user is an Official Discord System user (part of the urgent message system). - /// - [JsonPropertyName("system")] - public Optional System { get; } - - /// - /// Whether the user has two factor enabled on their account. - /// - [JsonPropertyName("mfa_enabled")] - public Optional MfaEnabled { get; } - - /// - /// The user's chosen language option. - /// - [JsonPropertyName("locale")] - public Optional Locale { get; } - - /// - /// Whether the email on this account has been verified. - /// - [JsonPropertyName("verified")] - public Optional Verified { get; } - - /// - /// The user's email. - /// - [JsonPropertyName("email")] - public Optional Email { get; } - - /// - /// The flags on a user's account. - /// - [JsonPropertyName("flags")] - public Optional Flags { get; } - - /// - /// The type of Nitro subscription on a user's account. - /// - [JsonPropertyName("premium_type")] - public Optional PremiumType { get; } - - /// - /// The public flags on a user's account. - /// - [JsonPropertyName("public_flags")] - public Optional PublicFlags { get; } - } -} diff --git a/src/Models/User/UserFlags.cs b/src/Models/User/UserFlags.cs deleted file mode 100644 index f021b54595..0000000000 --- a/src/Models/User/UserFlags.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; - -namespace Discord.Net.Models -{ - /// - /// Represents the user flags. - /// - [Flags] - public enum UserFlags - { - /// - /// Default flag. - /// - None = 0, - - /// - /// User is a Discord Employee. - /// - DiscordEmployee = 1 << 0, - - /// - /// User is the owner of a partnered server. - /// - PartneredServerOwner = 1 << 1, - - /// - /// User participated in HypeSquad events. - /// - HypeSquadEvents = 1 << 2, - - /// - /// User is a level 1 Bug Hunter. - /// - BugHunterLevel1 = 1 << 3, - - /// - /// User is part of House Bravery. - /// - HouseBravery = 1 << 6, - - /// - /// User is part of House Brilliance. - /// - HouseBrilliance = 1 << 7, - - /// - /// User is part of House Balance. - /// - HouseBalance = 1 << 8, - - /// - /// User is an early supporter. - /// - EarlySupporter = 1 << 9, - - /// - /// User is part of a team. - /// - TeamUser = 1 << 10, - - /// - /// User is a level 2 Bug Hunter. - /// - BugHunterLevel2 = 1 << 14, - - /// - /// User is a verified bot. - /// - VerifiedBot = 1 << 16, - - /// - /// User is an early verified bot developer. - /// - EarlyVerifiedBotDeveloper = 1 << 17, - - /// - /// User is a Discord certified moderator. - /// - DiscordCertifiedModerator = 1 << 18, - } -} diff --git a/src/Models/User/VisibilityType.cs b/src/Models/User/VisibilityType.cs deleted file mode 100644 index 77cb5a44b8..0000000000 --- a/src/Models/User/VisibilityType.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Represents the visibility type. - /// - public enum VisibilityType - { - /// - /// Invisible to everyone except the user themselves. - /// - None = 0, - - /// - /// Visible to everyone. - /// - Everyone = 1, - } -} diff --git a/src/Models/Voice/VoiceRegion.cs b/src/Models/Voice/VoiceRegion.cs deleted file mode 100644 index bd01a62c87..0000000000 --- a/src/Models/Voice/VoiceRegion.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a voice region object. - /// - public record VoiceRegion - { - /// - /// Creates a with the provided parameters. - /// - /// Unique ID for the region. - /// Name of the region. - /// True if this is a vip-only server. - /// True for a single server that is closest to the current user's client. - /// Whether this is a deprecated voice region (avoid switching to these). - /// Whether this is a custom voice region (used for events/etc). - [JsonConstructor] - public VoiceRegion(string id, string name, bool vip, bool optimal, bool deprecated, bool custom) - { - Id = id; - Name = name; - Vip = vip; - Optimal = optimal; - Deprecated = deprecated; - Custom = custom; - } - - /// - /// Unique ID for the region. - /// - [JsonPropertyName("id")] - public string Id { get; } - - /// - /// Name of the region. - /// - [JsonPropertyName("name")] - public string Name { get; } - - /// - /// True if this is a vip-only server. - /// - [JsonPropertyName("vip")] - public bool Vip { get; } - - /// - /// True for a single server that is closest to the current user's client. - /// - [JsonPropertyName("optimal")] - public bool Optimal { get; } - - /// - /// Whether this is a deprecated voice region (avoid switching to these). - /// - [JsonPropertyName("deprecated")] - public bool Deprecated { get; } - - /// - /// Whether this is a custom voice region (used for events/etc). - /// - [JsonPropertyName("custom")] - public bool Custom { get; } - } -} diff --git a/src/Models/Voice/VoiceState.cs b/src/Models/Voice/VoiceState.cs deleted file mode 100644 index fbea6637a8..0000000000 --- a/src/Models/Voice/VoiceState.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a voice state object. - /// - public record VoiceState - { - /// - /// Creates a with the provided parameters. - /// - /// The guild id this voice state is for. - /// The channel id this user is connected to. - /// The user id this voice state is for. - /// The guild member this voice state is for. - /// The session id for this voice state. - /// Whether this user is deafened by the server. - /// Whether this user is muted by the server. - /// Whether this user is locally deafened. - /// Whether this user is locally muted. - /// Whether this user is streaming using "Go Live". - /// Whether this user's camera is enabled. - /// Whether this user is muted by the current user. - /// The time at which the user requested to speak. - [JsonConstructor] - public VoiceState(Optional guildId, Snowflake? channelId, Snowflake userId, Optional member, string sessionId, bool deaf, bool mute, bool selfDeaf, bool selfMute, Optional selfStream, bool selfVideo, bool suppress, DateTimeOffset? requestToSpeakTimestamp) - { - GuildId = guildId; - ChannelId = channelId; - UserId = userId; - Member = member; - SessionId = sessionId; - Deaf = deaf; - Mute = mute; - SelfDeaf = selfDeaf; - SelfMute = selfMute; - SelfStream = selfStream; - SelfVideo = selfVideo; - Suppress = suppress; - RequestToSpeakTimestamp = requestToSpeakTimestamp; - } - - /// - /// The guild id this voice state is for. - /// - [JsonPropertyName("guild_id")] - public Optional GuildId { get; } - - /// - /// The channel id this user is connected to. - /// - [JsonPropertyName("channel_id")] - public Snowflake? ChannelId { get; } - - /// - /// The user id this voice state is for. - /// - [JsonPropertyName("user_id")] - public Snowflake UserId { get; } - - /// - /// The guild member this voice state is for. - /// - [JsonPropertyName("member")] - public Optional Member { get; } - - /// - /// The session id for this voice state. - /// - [JsonPropertyName("session_id")] - public string SessionId { get; } - - /// - /// Whether this user is deafened by the server. - /// - [JsonPropertyName("deaf")] - public bool Deaf { get; } - - /// - /// Whether this user is muted by the server. - /// - [JsonPropertyName("mute")] - public bool Mute { get; } - - /// - /// Whether this user is locally deafened. - /// - [JsonPropertyName("self_deaf")] - public bool SelfDeaf { get; } - - /// - /// Whether this user is locally muted. - /// - [JsonPropertyName("self_mute")] - public bool SelfMute { get; } - - /// - /// Whether this user is streaming using "Go Live". - /// - [JsonPropertyName("self_stream")] - public Optional SelfStream { get; } - - /// - /// Whether this user's camera is enabled. - /// - [JsonPropertyName("self_video")] - public bool SelfVideo { get; } - - /// - /// Whether this user is muted by the current user. - /// - [JsonPropertyName("suppress")] - public bool Suppress { get; } - - /// - /// The time at which the user requested to speak. - /// - [JsonPropertyName("request_to_speak_timestamp")] - public DateTimeOffset? RequestToSpeakTimestamp { get; } - } -} diff --git a/src/Models/Webhook/Webhook.cs b/src/Models/Webhook/Webhook.cs deleted file mode 100644 index b202bcdb59..0000000000 --- a/src/Models/Webhook/Webhook.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Discord.Net.Models -{ - /// - /// Represents a webhook object. - /// - public record Webhook - { - /// - /// Creates a with the provided parameters. - /// - /// The id of the webhook. - /// The type of the webhook. - /// The guild id this webhook is for, if any. - /// The channel id this webhook is for, if any. - /// The user this webhook was created by (not returned when getting a webhook with its token). - /// The default name of the webhook. - /// The default user avatar hash of the webhook. - /// The secure token of the webhook (returned for Incoming Webhooks). - /// The bot/OAuth2 application that created this webhook. - /// The guild of the channel that this webhook is following (returned for Channel Follower Webhooks). - /// The channel that this webhook is following (returned for Channel Follower Webhooks). - /// The url used for executing the webhook (returned by the webhooks OAuth2 flow). - [JsonConstructor] - public Webhook(Snowflake id, WebhookType type, Optional guildId, Snowflake? channelId, Optional user, string? name, string? avatar, Optional token, Snowflake? applicationId, Optional sourceGuild, Optional sourceChannel, Optional url) - { - Id = id; - Type = type; - GuildId = guildId; - ChannelId = channelId; - User = user; - Name = name; - Avatar = avatar; - Token = token; - ApplicationId = applicationId; - SourceGuild = sourceGuild; - SourceChannel = sourceChannel; - Url = url; - } - - /// - /// The id of the webhook. - /// - [JsonPropertyName("id")] - public Snowflake Id { get; } - - /// - /// The type of the webhook. - /// - [JsonPropertyName("type")] - public WebhookType Type { get; } - - /// - /// The guild id this webhook is for, if any. - /// - [JsonPropertyName("guild_id")] - public Optional GuildId { get; } - - /// - /// The channel id this webhook is for, if any. - /// - [JsonPropertyName("channel_id")] - public Snowflake? ChannelId { get; } - - /// - /// The user this webhook was created by (not returned when getting a webhook with its token). - /// - [JsonPropertyName("user")] - public Optional User { get; } - - /// - /// The default name of the webhook. - /// - [JsonPropertyName("name")] - public string? Name { get; } - - /// - /// The default user avatar hash of the webhook. - /// - [JsonPropertyName("avatar")] - public string? Avatar { get; } - - /// - /// The secure token of the webhook (returned for Incoming Webhooks). - /// - [JsonPropertyName("token")] - public Optional Token { get; } - - /// - /// The bot/OAuth2 application that created this webhook. - /// - [JsonPropertyName("application_id")] - public Snowflake? ApplicationId { get; } - - /// - /// The guild of the channel that this webhook is following (returned for Channel Follower Webhooks). - /// - [JsonPropertyName("source_guild")] - public Optional SourceGuild { get; } - - /// - /// The channel that this webhook is following (returned for Channel Follower Webhooks). - /// - [JsonPropertyName("source_channel")] - public Optional SourceChannel { get; } - - /// - /// The url used for executing the webhook (returned by the webhooks OAuth2 flow). - /// - [JsonPropertyName("url")] - public Optional Url { get; } - } -} diff --git a/src/Models/Webhook/WebhookType.cs b/src/Models/Webhook/WebhookType.cs deleted file mode 100644 index d66ed6af16..0000000000 --- a/src/Models/Webhook/WebhookType.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Discord.Net.Models -{ - /// - /// Represents the webhook type. - /// - public enum WebhookType - { - /// - /// Incoming Webhooks can post messages to channels with a generated token. - /// - Incoming = 1, - - /// - /// Channel Follower Webhooks are internal webhooks used with Channel Following to post new messages into channels. - /// - ChannelFollower = 2, - - /// - /// Application webhooks are webhooks used with Interactions. - /// - Application = 3, - } -} diff --git a/src/Serialization/Converters/OptionalConverter.cs b/src/Serialization/Converters/OptionalConverter.cs new file mode 100644 index 0000000000..78a90a850d --- /dev/null +++ b/src/Serialization/Converters/OptionalConverter.cs @@ -0,0 +1,45 @@ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace Discord.Net.Serialization.Converters +{ + /// + /// Defines a converter which can be used to convert instances of + /// . + /// + public sealed class OptionalConverter : JsonConverter + { + private readonly JsonConverter? _valueConverter; + + internal OptionalConverter( + JsonSerializerOptions options) + { + _valueConverter = options.GetConverter(typeof(T)) + as JsonConverter; + } + + /// + public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, + JsonSerializerOptions options) + { + return _valueConverter != null + ? _valueConverter.Read(ref reader, typeof(T), options) + : JsonSerializer.Deserialize(ref reader, options); + } + + /// + public override void Write(Utf8JsonWriter writer, T value, + JsonSerializerOptions options) + { + if (_valueConverter != null) + { + _valueConverter.Write(writer, value, options); + return; + } + + JsonSerializer.Serialize(writer, value, options); + } + } +} diff --git a/src/Serialization/Converters/OptionalConverterFactory.cs b/src/Serialization/Converters/OptionalConverterFactory.cs new file mode 100644 index 0000000000..463c0d61e3 --- /dev/null +++ b/src/Serialization/Converters/OptionalConverterFactory.cs @@ -0,0 +1,36 @@ +using System; +using System.Diagnostics; +using System.Linq; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Discord.Net.Serialization.Converters +{ + /// + /// Defines a converter factory which can be used to create instances of + /// . + /// + public sealed class OptionalConverterFactory : JsonConverterFactory + { + private static readonly Type OptionalType = typeof(Optional<>); + private static readonly Type OptionalConverterType = typeof(OptionalConverter<>); + + /// + public override bool CanConvert(Type typeToConvert) + => typeToConvert.IsGenericType + && typeToConvert.GetGenericTypeDefinition() == OptionalType; + + /// + public override JsonConverter? CreateConverter(Type typeToConvert, + JsonSerializerOptions options) + { + Debug.Assert(typeToConvert.IsGenericType); + + var underlyingType = typeToConvert.GenericTypeArguments[0]; + + return (JsonConverter)Activator.CreateInstance( + OptionalConverterType.MakeGenericType(underlyingType), + args: new[] { options })!; + } + } +} diff --git a/src/Serialization/Discord.Net.Serialization.csproj b/src/Serialization/Discord.Net.Serialization.csproj new file mode 100644 index 0000000000..f35880ec03 --- /dev/null +++ b/src/Serialization/Discord.Net.Serialization.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + $(Description) + Serialization primitives used by Discord.Net + + + + diff --git a/src/Serialization/DiscriminatedUnionAttribute.cs b/src/Serialization/DiscriminatedUnionAttribute.cs new file mode 100644 index 0000000000..1d2a00d484 --- /dev/null +++ b/src/Serialization/DiscriminatedUnionAttribute.cs @@ -0,0 +1,29 @@ +using System; + +namespace Discord.Net.Serialization +{ + /// + /// Defines an attribute used to mark discriminated unions. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, + AllowMultiple = false, + Inherited = false)] + public class DiscriminatedUnionAttribute : Attribute + { + /// + /// Gets the field or property used to discriminate between types. + /// + public string DiscriminatorField { get; } + + /// + /// Creates a new instance. + /// + /// + /// The field or property used to discriminate between types. + /// + public DiscriminatedUnionAttribute(string discriminatorField) + { + DiscriminatorField = discriminatorField; + } + } +} diff --git a/src/Serialization/DiscriminatedUnionMemberAttribute.cs b/src/Serialization/DiscriminatedUnionMemberAttribute.cs new file mode 100644 index 0000000000..4958d58649 --- /dev/null +++ b/src/Serialization/DiscriminatedUnionMemberAttribute.cs @@ -0,0 +1,30 @@ +using System; + +namespace Discord.Net.Serialization +{ + /// + /// Defines an attribute used to mark members of discriminated unions. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, + AllowMultiple = false, + Inherited = false)] + public class DiscriminatedUnionMemberAttribute : Attribute + { + /// + /// Gets the discriminator value used to identify this member type. + /// + public object Discriminator { get; } + + /// + /// Creates a new + /// instance. + /// + /// + /// The discriminator value used to identify this member type. + /// + public DiscriminatedUnionMemberAttribute(object discriminator) + { + Discriminator = discriminator; + } + } +} diff --git a/src/Serialization/GenerateSerializerAttribute.cs b/src/Serialization/GenerateSerializerAttribute.cs new file mode 100644 index 0000000000..1380958729 --- /dev/null +++ b/src/Serialization/GenerateSerializerAttribute.cs @@ -0,0 +1,16 @@ +using System; + +namespace Discord.Net.Serialization +{ + /// + /// Defines an attribute which informs the serializer generator to generate + /// a serializer for this type. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, + AllowMultiple = false, + Inherited = false)] + public class GenerateSerializerAttribute : Attribute + { + + } +} diff --git a/src/Serialization/Optional.cs b/src/Serialization/Optional.cs new file mode 100644 index 0000000000..fd6eb19ccd --- /dev/null +++ b/src/Serialization/Optional.cs @@ -0,0 +1,171 @@ +using System; +using Discord.Net.Serialization; + +namespace Discord.Net.Serialization +{ + /// + /// Defines a type which may be either undefined, null or an instance of a + /// value. + /// + /// + /// The type which is contained + /// + public struct Optional + { + private readonly T _value; + + /// + /// Gets the inner value of this if present. + /// + /// + /// The value inside this . + /// + /// + /// This has no inner value. + /// + public T Value + => !IsSpecified + ? throw new InvalidOperationException( + "This property has no value set.") + : _value; + + /// + /// Gets if this has an inner value. + /// + /// + /// A boolean that determines if this has a + /// . + /// + public bool IsSpecified { get; } + + private Optional(T value) + { + _value = value; + IsSpecified = true; + } + + /// + /// Creates a new unspecified . + /// + /// + /// An unspecified . + /// + public static Optional Create() + => default; + + /// + /// Creates a new with the specified + /// . + /// + /// + /// Value that will be specified for this . + /// + /// + /// A specified with the provided value + /// inside. + /// + public static Optional Create(T value) + => new(value); + + /// + /// Gets the or their + /// value. + /// + /// + /// The value inside this or their + /// value. + /// + public T GetValueOrDefault() + => _value; + + /// + /// Gets the or the default value provided. + /// + /// + /// The value inside this or default value + /// provided. + /// + public T GetValueOrDefault(T defaultValue) + => IsSpecified ? _value : defaultValue; + + /// + public override bool Equals(object? other) + { + if (!IsSpecified) + return other == null; + if (other == null || _value == null) + return false; + return _value.Equals(other); + } + + /// + public override int GetHashCode() + => IsSpecified ? _value?.GetHashCode() ?? default : default; + + /// + /// Returns the inner value ToString value or this type fully qualified + /// name. + /// + /// + /// The inner value string value or this type fully qualified name. + /// + public override string? ToString() + => IsSpecified ? _value?.ToString() : default; + + /// + /// Creates a new with the specified + /// . + /// + /// Value to convert + /// + /// A new with the specified + /// . + /// + public static implicit operator Optional(T value) + => new(value); + + /// + /// Gets the inner value. + /// + /// + /// Value to convert + /// + /// + /// The inner value. + /// + public static explicit operator T(Optional value) + => value.Value; + + /// + /// Compares two values for equality. + /// + /// + /// The first value to compare. + /// + /// + /// The second value to compare. + /// + /// + /// if the two values are equal, or + /// otherwise. + /// + public static bool operator ==(Optional left, Optional right) + => left.Equals(right); + + /// + /// Compares two values for inequality. + /// + /// + /// The first value to compare. + /// + /// + /// The second value to compare. + /// + /// + /// if the two values are unequal, or + /// otherwise. + /// + public static bool operator !=(Optional left, Optional right) + => !(left == right); + } +} diff --git a/tools/Directory.Build.props b/tools/Directory.Build.props new file mode 100644 index 0000000000..a035033802 --- /dev/null +++ b/tools/Directory.Build.props @@ -0,0 +1,32 @@ + + + + + + + + + true + $(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props + tools + + + + + + + + + + + + + + diff --git a/tools/Directory.Build.targets b/tools/Directory.Build.targets new file mode 100644 index 0000000000..1f014d179a --- /dev/null +++ b/tools/Directory.Build.targets @@ -0,0 +1,25 @@ + + + + + + + + + $(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.targets + + + + + + + + + diff --git a/tools/SourceGenerators/Directory.Build.props b/tools/SourceGenerators/Directory.Build.props new file mode 100644 index 0000000000..88a648206f --- /dev/null +++ b/tools/SourceGenerators/Directory.Build.props @@ -0,0 +1,41 @@ + + + + + + + + + $(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props + + + + + + false + true + false + + $(NoWarn);RS2000;RS2001;RS2002;RS2003;RS2004;RS2005;RS2006;RS2007;RS2008 + + + + + + + + + + + + + + + diff --git a/tools/SourceGenerators/IsExternalInit.cs b/tools/SourceGenerators/IsExternalInit.cs new file mode 100644 index 0000000000..5ead4123a7 --- /dev/null +++ b/tools/SourceGenerators/IsExternalInit.cs @@ -0,0 +1,4 @@ +namespace System.Runtime.CompilerServices +{ + internal static class IsExternalInit { } +} diff --git a/tools/SourceGenerators/Serialization/Discord.Net.SourceGenerators.Serialization.csproj b/tools/SourceGenerators/Serialization/Discord.Net.SourceGenerators.Serialization.csproj new file mode 100644 index 0000000000..864db75328 --- /dev/null +++ b/tools/SourceGenerators/Serialization/Discord.Net.SourceGenerators.Serialization.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/tools/SourceGenerators/Serialization/Discord.Net.SourceGenerators.Serialization.props b/tools/SourceGenerators/Serialization/Discord.Net.SourceGenerators.Serialization.props new file mode 100644 index 0000000000..4d8e9fb92a --- /dev/null +++ b/tools/SourceGenerators/Serialization/Discord.Net.SourceGenerators.Serialization.props @@ -0,0 +1,6 @@ + + + + + + diff --git a/tools/SourceGenerators/Serialization/SerializationSourceGenerator.OptionsSource.cs b/tools/SourceGenerators/Serialization/SerializationSourceGenerator.OptionsSource.cs new file mode 100644 index 0000000000..b01d3f9428 --- /dev/null +++ b/tools/SourceGenerators/Serialization/SerializationSourceGenerator.OptionsSource.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Discord.Net.SourceGenerators.Serialization +{ + public partial class SerializationSourceGenerator + { + private static string GenerateSerializerOptionsSourceCode( + string @namespace, + IEnumerable converters) + { + var snippets = string.Join("\n", + converters.Select( + x => $" options.Converters.Add(new {@namespace}.Internal.Converters.{x.ConverterTypeName}());")); + +return $@"using System; +using System.Text.Json; +using Discord.Net.Serialization.Converters; + +namespace {@namespace} +{{ + /// + /// Defines extension methods for adding Discord.Net JSON converters to a + /// instance. + /// + public static class JsonSerializerOptionsExtensions + {{ + /// + /// Adds Discord.Net JSON converters to the passed + /// . + /// + /// + /// The serializer options to add Discord.Net converters to. + /// + /// + /// The modified , so this method + /// can be chained. + /// + public static JsonSerializerOptions WithDiscordNetConverters( + this JsonSerializerOptions options) + {{ + options.Converters.Add(new OptionalConverterFactory()); +{snippets} + + return options; + }} + }} +}}"; + } + } +} diff --git a/tools/SourceGenerators/Serialization/SerializationSourceGenerator.cs b/tools/SourceGenerators/Serialization/SerializationSourceGenerator.cs new file mode 100644 index 0000000000..18297b0955 --- /dev/null +++ b/tools/SourceGenerators/Serialization/SerializationSourceGenerator.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Discord.Net.SourceGenerators.Serialization +{ + [Generator] + public partial class SerializationSourceGenerator : ISourceGenerator + { + public void Execute(GeneratorExecutionContext context) + { + if (!context.AnalyzerConfigOptions.GlobalOptions.TryGetValue( + "build_property.DiscordNet_SerializationGenerator_OptionsTypeNamespace", + out var serializerOptionsNamespace)) + throw new InvalidOperationException( + "Missing output namespace. Set DiscordNet_SerializationGenerator_OptionsTypeNamespace in your project file."); + + bool searchThroughReferencedAssemblies = + context.AnalyzerConfigOptions.GlobalOptions.TryGetValue( + "build_property.DiscordNet_SerializationGenerator_SearchThroughReferencedAssemblies", + out var _); + + var generateSerializerAttribute = context.Compilation + .GetTypeByMetadataName( + "Discord.Net.Serialization.GenerateSerializerAttribute"); + var discriminatedUnionSymbol = context.Compilation + .GetTypeByMetadataName( + "Discord.Net.Serialization.DiscriminatedUnionAttribute"); + var discriminatedUnionMemberSymbol = context.Compilation + .GetTypeByMetadataName( + "Discord.Net.Serialization.DiscriminatedUnionMemberAttribute"); + + Debug.Assert(generateSerializerAttribute != null); + Debug.Assert(discriminatedUnionSymbol != null); + Debug.Assert(discriminatedUnionMemberSymbol != null); + Debug.Assert(context.SyntaxContextReceiver != null); + + var receiver = (SyntaxReceiver)context.SyntaxContextReceiver!; + var symbolsToBuild = receiver.GetSerializedTypes( + context.Compilation); + + if (searchThroughReferencedAssemblies) + { + var visitor = new VisibleTypeVisitor(context.CancellationToken); + foreach (var module in context.Compilation.Assembly.Modules) + foreach (var reference in module.ReferencedAssemblySymbols) + visitor.Visit(reference); + + symbolsToBuild = symbolsToBuild + .Concat(visitor.GetVisibleTypes()); + } + + var types = SerializedTypeUtils.BuildTypeTrees( + generateSerializerAttribute: generateSerializerAttribute!, + discriminatedUnionSymbol: discriminatedUnionSymbol!, + discriminatedUnionMemberSymbol: discriminatedUnionMemberSymbol!, + symbolsToBuild: symbolsToBuild); + + foreach (var type in types) + { + context.AddSource($"Converters.{type.ConverterTypeName}", + type.GenerateSourceCode(serializerOptionsNamespace)); + + if (type is DiscriminatedUnionSerializedType duDeclaration) + foreach (var member in duDeclaration.Members) + context.AddSource( + $"Converters.{type.ConverterTypeName}.{member.ConverterTypeName}", + member.GenerateSourceCode(serializerOptionsNamespace)); + } + + context.AddSource("SerializerOptions", + GenerateSerializerOptionsSourceCode( + serializerOptionsNamespace, types)); + } + + public void Initialize(GeneratorInitializationContext context) + => context.RegisterForSyntaxNotifications( + () => new SyntaxReceiver()); + + private class SyntaxReceiver : ISyntaxContextReceiver + { + private readonly List _classes; + + public SyntaxReceiver() + { + _classes = new(); + } + + public IEnumerable GetSerializedTypes( + Compilation compilation) + { + foreach (var @class in _classes) + { + var semanticModel = compilation.GetSemanticModel( + @class.SyntaxTree); + + if (semanticModel.GetDeclaredSymbol(@class) is + INamedTypeSymbol classSymbol) + yield return classSymbol; + } + } + + private INamedTypeSymbol? _generateSerializerAttributeSymbol; + + public void OnVisitSyntaxNode(GeneratorSyntaxContext context) + { + _generateSerializerAttributeSymbol ??= + context.SemanticModel.Compilation.GetTypeByMetadataName( + "Discord.Net.Serialization.GenerateSerializerAttribute"); + + Debug.Assert(_generateSerializerAttributeSymbol != null); + + if (context.Node is ClassDeclarationSyntax classDeclaration + && classDeclaration.AttributeLists is + SyntaxList classAttributeLists + && classAttributeLists.Any( + list => list.Attributes.Any( + n => IsAttribute(n, context.SemanticModel, + _generateSerializerAttributeSymbol!)))) + { + _classes.Add(classDeclaration); + } + else if (context.Node is RecordDeclarationSyntax recordDeclaration + && recordDeclaration.AttributeLists is + SyntaxList recordAttributeLists + && recordAttributeLists.Any( + list => list.Attributes.Any( + n => IsAttribute(n, context.SemanticModel, + _generateSerializerAttributeSymbol!)))) + { + _classes.Add(recordDeclaration); + } + + static bool IsAttribute(AttributeSyntax attribute, + SemanticModel model, INamedTypeSymbol expected) + { + var typeInfo = model.GetTypeInfo(attribute.Name); + + return SymbolEqualityComparer.Default.Equals( + typeInfo.Type, expected); + } + } + } + } +} diff --git a/tools/SourceGenerators/Serialization/Structure/SerializedType.cs b/tools/SourceGenerators/Serialization/Structure/SerializedType.cs new file mode 100644 index 0000000000..d57c64f83e --- /dev/null +++ b/tools/SourceGenerators/Serialization/Structure/SerializedType.cs @@ -0,0 +1,253 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using static Discord.Net.SourceGenerators.Serialization.Utils; + +namespace Discord.Net.SourceGenerators.Serialization +{ + internal record SerializedType( + INamedTypeSymbol Declaration) + { + public virtual string ConverterTypeName + => $"{Declaration.Name}Converter"; + + protected virtual IEnumerable SymbolsToSerialize + => Declaration.GetProperties(includeInherited: true) + .Where(x => !x.IsReadOnly); + + public virtual string GenerateSourceCode(string outputNamespace) + { + var deserializers = SymbolsToSerialize + .Select(GenerateFieldReader); + + var bytes = string.Join("\n", + deserializers.Select(x => x.utf8)); + var fields = string.Join("\n", + deserializers.Select(x => x.field)); + var readers = string.Join("\n", + deserializers.Select(x => x.reader)); + + var fieldUnassigned = string.Join("\n || ", + deserializers + .Where(x => x.type.NullableAnnotation != NullableAnnotation.Annotated) + .Select( + x => $"{x.snakeCase}OrDefault is not {x.type} {x.snakeCase}")); + + var constructorParams = string.Join(",\n", + deserializers + .Select(x => $" {x.name}: {x.snakeCase}{(x.type.NullableAnnotation == NullableAnnotation.Annotated ? "OrDefault" : "")}")); + +return $@"using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace {outputNamespace}.Converters +{{ + internal class {ConverterTypeName} : JsonConverter<{Declaration.ToDisplayString()}> + {{ +{bytes} + + public override {Declaration.ToDisplayString()}? Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options) + {{ + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException(""Expected StartObject""); + +{fields} + + while (reader.Read()) + {{ + if (reader.TokenType == JsonTokenType.EndObject) + break; + + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException(""Expected PropertyName""); + +{readers} + else if (!reader.Read()) + throw new JsonException(); + + if (reader.TokenType == JsonTokenType.StartArray + || reader.TokenType == JsonTokenType.StartObject) + reader.Skip(); + }} + + if ({fieldUnassigned}) + throw new JsonException(""Missing field""); + + return new {Declaration.ToDisplayString()}( +{constructorParams} + ); + }} + + public override void Write( + Utf8JsonWriter writer, + {Declaration.ToDisplayString()} value, + JsonSerializerOptions options) + {{ + writer.WriteNullValue(); + }} + }} +}}"; + + static (string name, ITypeSymbol type, string snakeCase, string utf8, string field, string reader) + GenerateFieldReader(IPropertySymbol member, int position) + { + var needsNullableAnnotation = false; + if (member.Type.IsValueType + && member.Type.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T) + needsNullableAnnotation = true; + + var snakeCase = ConvertToSnakeCase(member.Name); + return (member.Name, member.Type, snakeCase, +$@" private static ReadOnlySpan {member.Name}Bytes => new byte[] + {{ + // {snakeCase} + {string.Join(", ", Encoding.UTF8.GetBytes(snakeCase))} + }};", +$" {member.Type.WithNullableAnnotation(NullableAnnotation.Annotated).ToDisplayString()}{(needsNullableAnnotation ? "?" : "")} {snakeCase}OrDefault = default;", +$@" {(position > 0 ? "else " : "")}if (reader.ValueTextEquals({member.Name}Bytes)) + {{ + if (!reader.Read()) + throw new JsonException(""Expected value""); + + var cvt = options.GetConverter( + typeof({member.Type.WithNullableAnnotation(NullableAnnotation.NotAnnotated).ToDisplayString()})); + + if (cvt is JsonConverter<{member.Type.WithNullableAnnotation(NullableAnnotation.NotAnnotated).ToDisplayString()}> converter) + {snakeCase}OrDefault = converter.Read(ref reader, + typeof({member.Type.WithNullableAnnotation(NullableAnnotation.NotAnnotated).ToDisplayString()}), + options); + else + {snakeCase}OrDefault = JsonSerializer.Deserialize<{member.Type.ToDisplayString()}>( + ref reader, options); + }}"); + } + } + } + + internal record DiscriminatedUnionSerializedType( + INamedTypeSymbol Declaration, + ISymbol Discriminator) + : SerializedType(Declaration) + { + public List Members { get; } + = new(); + + public override string GenerateSourceCode(string outputNamespace) + { + var discriminatorField = ConvertToSnakeCase(Discriminator.Name); + + var discriminatorType = Discriminator switch + { + IPropertySymbol prop => prop.Type, + IFieldSymbol field => field.Type, + _ => throw new InvalidOperationException( + "Unsupported discriminator member type") + }; + + var switchCaseMembers = string.Join(",\n", + Members.Select( + x => $@" {x.DiscriminatorValue.ToCSharpString()} + => JsonSerializer.Deserialize(ref copy, + typeof({x.Declaration.ToDisplayString()}), options)")); + + return $@"using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace {outputNamespace}.Internal.Converters +{{ + internal class {ConverterTypeName} : JsonConverter<{Declaration.ToDisplayString()}> + {{ + private static ReadOnlySpan DiscriminatorBytes => new byte[] + {{ + // {discriminatorField} + {string.Join(", ", Encoding.UTF8.GetBytes(discriminatorField))} + }}; + + public override {Declaration.ToDisplayString()}? Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options) + {{ + var copy = reader; + if (reader.TokenType != JsonTokenType.StartObject) + throw new JsonException(""Expected StartObject""); + + {discriminatorType.ToDisplayString()}? discriminator = null; + + while (reader.Read()) + {{ + if (reader.TokenType == JsonTokenType.EndObject) + break; + + if (reader.TokenType != JsonTokenType.PropertyName) + throw new JsonException(""Expected PropertyName""); + + if (reader.ValueTextEquals(DiscriminatorBytes)) + {{ + if (!reader.Read()) + throw new JsonException(""Expected value""); + + var cvt = options.GetConverter( + typeof({discriminatorType.ToDisplayString()})); + + if (cvt is JsonConverter<{discriminatorType.ToDisplayString()}> converter) + discriminator = converter.Read(ref reader, + typeof({discriminatorType.ToDisplayString()}), + options); + else + discriminator = JsonSerializer + .Deserialize<{discriminatorType.ToDisplayString()}>( + ref reader, options); + }} + else if (!reader.Read()) + throw new JsonException(""Expected value""); + + if (reader.TokenType == JsonTokenType.StartArray + || reader.TokenType == JsonTokenType.StartObject) + reader.Skip(); + }} + + var result = discriminator switch + {{ +{switchCaseMembers}, + _ => throw new JsonException(""Unknown discriminator value"") + }} as {Declaration.ToDisplayString()}; + + reader = copy; + return result; + }} + + public override void Write( + Utf8JsonWriter writer, + {Declaration.ToDisplayString()} value, + JsonSerializerOptions options) + {{ + writer.WriteNullValue(); + }} + }} +}}"; + } + } + + internal record DiscriminatedUnionMemberSerializedType( + INamedTypeSymbol Declaration, + TypedConstant DiscriminatorValue) + : SerializedType(Declaration) + { + public DiscriminatedUnionSerializedType? DiscriminatedUnionDeclaration + { get; init; } + + protected override IEnumerable SymbolsToSerialize + => base.SymbolsToSerialize + .Where(x => !SymbolEqualityComparer.Default.Equals(x, + DiscriminatedUnionDeclaration?.Discriminator)); + } +} diff --git a/tools/SourceGenerators/Serialization/Structure/SerializedTypeUtils.cs b/tools/SourceGenerators/Serialization/Structure/SerializedTypeUtils.cs new file mode 100644 index 0000000000..2b365bd3fe --- /dev/null +++ b/tools/SourceGenerators/Serialization/Structure/SerializedTypeUtils.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Microsoft.CodeAnalysis; + +namespace Discord.Net.SourceGenerators.Serialization +{ + internal static class SerializedTypeUtils + { + public static List BuildTypeTrees( + INamedTypeSymbol generateSerializerAttribute, + INamedTypeSymbol discriminatedUnionSymbol, + INamedTypeSymbol discriminatedUnionMemberSymbol, + IEnumerable symbolsToBuild) + { + var types = new List(); + + FindAllSerializedTypes(types, generateSerializerAttribute, + discriminatedUnionSymbol, discriminatedUnionMemberSymbol, + symbolsToBuild); + + // Now, move DU members into their relevant DU declaration. + int x = 0; + while (x < types.Count) + { + var type = types[x]; + if (type is DiscriminatedUnionMemberSerializedType duMember) + { + var declaration = types.FirstOrDefault( + x => SymbolEqualityComparer.Default.Equals( + x.Declaration, duMember.Declaration.BaseType)); + + if (declaration is not DiscriminatedUnionSerializedType duDeclaration) + throw new InvalidOperationException( + "Could not find DU declaration for DU " + + $"member {duMember.Declaration.ToDisplayString()}"); + + duDeclaration.Members.Add(duMember with + { + DiscriminatedUnionDeclaration = duDeclaration + }); + types.RemoveAt(x); + continue; + } + + x++; + } + + return types; + } + + private static void FindAllSerializedTypes( + List types, + INamedTypeSymbol generateSerializerAttribute, + INamedTypeSymbol discriminatedUnionSymbol, + INamedTypeSymbol discriminatedUnionMemberSymbol, + IEnumerable symbolsToBuild) + { + foreach (var type in symbolsToBuild) + { + var generateSerializer = type.GetAttributes() + .Any(x => SymbolEqualityComparer.Default + .Equals(x.AttributeClass, generateSerializerAttribute)); + + if (!generateSerializer) + continue; + + var duDeclaration = type.GetAttributes() + .FirstOrDefault(x => SymbolEqualityComparer.Default + .Equals(x.AttributeClass, discriminatedUnionSymbol)); + + if (duDeclaration != null) + { + if (duDeclaration + .ConstructorArguments + .FirstOrDefault() + .Value is not string memberName) + throw new InvalidOperationException( + "Failed to get DU discriminator member name"); + + var member = type.GetMembers(memberName) + .FirstOrDefault( + x => x is IPropertySymbol or IFieldSymbol); + + if (member is null) + throw new InvalidOperationException( + "Failed to get DU discriminator member symbol"); + + types.Add(new DiscriminatedUnionSerializedType( + type, member)); + + continue; + } + + var duMemberDeclaration = type + .GetAttributes() + .FirstOrDefault(x => SymbolEqualityComparer.Default + .Equals(x.AttributeClass, + discriminatedUnionMemberSymbol)); + + if (duMemberDeclaration != null) + { + if (duMemberDeclaration.ConstructorArguments.Length == 0 + || duMemberDeclaration.ConstructorArguments[0].IsNull) + throw new InvalidOperationException( + "Failed to get DU discriminator value"); + + types.Add(new DiscriminatedUnionMemberSerializedType( + type, duMemberDeclaration.ConstructorArguments[0])); + + continue; + } + + types.Add(new SerializedType(type)); + } + } + } +} diff --git a/tools/SourceGenerators/Serialization/SymbolExtensions.cs b/tools/SourceGenerators/Serialization/SymbolExtensions.cs new file mode 100644 index 0000000000..c3b866bead --- /dev/null +++ b/tools/SourceGenerators/Serialization/SymbolExtensions.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.SymbolStore; +using Microsoft.CodeAnalysis; + +namespace Discord.Net.SourceGenerators.Serialization +{ + internal static class SymbolExtensions + { + public static IEnumerable GetProperties( + this INamedTypeSymbol symbol, + bool includeInherited) + { + var s = symbol; + do + { + foreach (var member in s.GetMembers()) + if (member is IPropertySymbol property) + yield return property; + + s = s.BaseType; + } + while (includeInherited && s != null); + } + } +} diff --git a/tools/SourceGenerators/Serialization/Utils.cs b/tools/SourceGenerators/Serialization/Utils.cs new file mode 100644 index 0000000000..e26af19828 --- /dev/null +++ b/tools/SourceGenerators/Serialization/Utils.cs @@ -0,0 +1,25 @@ +using System.Text; + +namespace Discord.Net.SourceGenerators.Serialization +{ + internal static class Utils + { + private static readonly StringBuilder CaseChangeBuffer = new(); + + public static string ConvertToSnakeCase(string value) + { + foreach (var c in value) + { + if (char.IsUpper(c) && CaseChangeBuffer.Length > 0) + _ = CaseChangeBuffer.Append('_'); + + _ = CaseChangeBuffer.Append(char.ToLower(c)); + } + + var result = CaseChangeBuffer.ToString(); + _ = CaseChangeBuffer.Clear(); + + return result; + } + } +} diff --git a/tools/SourceGenerators/Serialization/VisibleTypeVisitor.cs b/tools/SourceGenerators/Serialization/VisibleTypeVisitor.cs new file mode 100644 index 0000000000..3adebe5750 --- /dev/null +++ b/tools/SourceGenerators/Serialization/VisibleTypeVisitor.cs @@ -0,0 +1,59 @@ +using System.Collections.Generic; +using System.Threading; +using Microsoft.CodeAnalysis; + +namespace Discord.Net.SourceGenerators.Serialization +{ + internal sealed class VisibleTypeVisitor + : SymbolVisitor + { + private readonly CancellationToken _cancellationToken; + private readonly HashSet _typeSymbols; + + public VisibleTypeVisitor(CancellationToken cancellationToken) + { + _cancellationToken = cancellationToken; + _typeSymbols = new(SymbolEqualityComparer.Default); + } + + public IEnumerable GetVisibleTypes() + => _typeSymbols; + + public override void VisitAssembly(IAssemblySymbol symbol) + { + _cancellationToken.ThrowIfCancellationRequested(); + symbol.GlobalNamespace.Accept(this); + } + + public override void VisitNamespace(INamespaceSymbol symbol) + { + foreach (var member in symbol.GetMembers()) + { + _cancellationToken.ThrowIfCancellationRequested(); + member.Accept(this); + } + } + + public override void VisitNamedType(INamedTypeSymbol symbol) + { + _cancellationToken.ThrowIfCancellationRequested(); + + var isVisible = symbol.DeclaredAccessibility switch + { + Accessibility.Protected => true, + Accessibility.ProtectedOrInternal => true, + Accessibility.Public => true, + _ => false, + }; + + if (!isVisible || !_typeSymbols.Add(symbol)) + return; + + foreach (var member in symbol.GetTypeMembers()) + { + _cancellationToken.ThrowIfCancellationRequested(); + member.Accept(this); + } + } + } +}