diff --git a/src/Discord.Net.Core/DiscordConfig.cs b/src/Discord.Net.Core/DiscordConfig.cs index 78acbd3e..3aacc30b 100644 --- a/src/Discord.Net.Core/DiscordConfig.cs +++ b/src/Discord.Net.Core/DiscordConfig.cs @@ -222,5 +222,15 @@ namespace Discord /// The maximum number of thread members that can be gotten per-batch. /// public const int MaxThreadMembersPerBatch = 100; + + /// + /// Returns the max length of an application tag. + /// + public const int MaxApplicationTagLength = 20; + + /// + /// Returns the max length of an application description. + /// + public const int MaxApplicationDescriptionLength = 400; } } diff --git a/src/Discord.Net.Core/Entities/ApplicationFlags.cs b/src/Discord.Net.Core/Entities/Applications/ApplicationFlags.cs similarity index 100% rename from src/Discord.Net.Core/Entities/ApplicationFlags.cs rename to src/Discord.Net.Core/Entities/Applications/ApplicationFlags.cs diff --git a/src/Discord.Net.Core/Entities/ApplicationInstallParams.cs b/src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs similarity index 100% rename from src/Discord.Net.Core/Entities/ApplicationInstallParams.cs rename to src/Discord.Net.Core/Entities/Applications/ApplicationInstallParams.cs diff --git a/src/Discord.Net.Core/Entities/IApplication.cs b/src/Discord.Net.Core/Entities/Applications/IApplication.cs similarity index 70% rename from src/Discord.Net.Core/Entities/IApplication.cs rename to src/Discord.Net.Core/Entities/Applications/IApplication.cs index 6aff992f..5e2aaf0d 100644 --- a/src/Discord.Net.Core/Entities/IApplication.cs +++ b/src/Discord.Net.Core/Entities/Applications/IApplication.cs @@ -36,13 +36,13 @@ namespace Discord /// string IconUrl { get; } /// - /// Gets if the bot is public. + /// Gets if the bot is public. if not set. /// - bool IsBotPublic { get; } + bool? IsBotPublic { get; } /// - /// Gets if the bot requires code grant. + /// Gets if the bot requires code grant. if not set. /// - bool BotRequiresCodeGrant { get; } + bool? BotRequiresCodeGrant { get; } /// /// Gets the team associated with this application if there is one. /// @@ -75,5 +75,24 @@ namespace Discord /// public string VerifyKey { get; } + /// + /// Gets the partial guild object of the application's developer's support server. if not set. + /// + public PartialGuild Guild { get; } + + /// + /// Gets the redirect uris configured for the application. + /// + public IReadOnlyCollection RedirectUris { get;} + + /// + /// Gets application's interactions endpoint url. if not set. + /// + public string InteractionsEndpointUrl { get; } + + /// + /// Gets the approximate count of the guild the application was added to. if not returned. + /// + public int? ApproximateGuildCount { get; } } } diff --git a/src/Discord.Net.Core/Entities/Applications/ModifyApplicationProperties.cs b/src/Discord.Net.Core/Entities/Applications/ModifyApplicationProperties.cs new file mode 100644 index 00000000..be6fdef0 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Applications/ModifyApplicationProperties.cs @@ -0,0 +1,32 @@ +namespace Discord; + +/// +/// Represents properties used to modify current application's bot. +/// +public class ModifyApplicationProperties +{ + /// + /// Gets or sets the http interactions endpoint configured for the application. + /// + public Optional InteractionsEndpointUrl { get; set; } + + /// + /// Gets or sets the role connections verification endpoint configured for the application. + /// + public Optional RoleConnectionsEndpointUrl { get; set; } + + /// + /// Gets or sets the description of the application. + /// + public Optional Description { get; set; } + + /// + /// Gets or sets application's tags + /// + public Optional Tags { get; set; } + + /// + /// Gets or sets the icon of the application. + /// + public Optional Icon { get; set; } +} diff --git a/src/Discord.Net.Core/Entities/Invites/InviteGuild.cs b/src/Discord.Net.Core/Entities/Guilds/PartialGuild.cs similarity index 67% rename from src/Discord.Net.Core/Entities/Invites/InviteGuild.cs rename to src/Discord.Net.Core/Entities/Guilds/PartialGuild.cs index 3377e1ed..668f5bd0 100644 --- a/src/Discord.Net.Core/Entities/Invites/InviteGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/PartialGuild.cs @@ -2,13 +2,19 @@ using System; namespace Discord; -public class InviteGuild : ISnowflakeEntity +/// +/// Represents a partial guild object. +/// +/// +/// Most of the fields can have value. +/// +public class PartialGuild : ISnowflakeEntity { /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); /// - public ulong Id { get; private set; } + public ulong Id { get; internal set; } /// /// Gets the name of this guild. @@ -16,7 +22,7 @@ public class InviteGuild : ISnowflakeEntity /// /// A string containing the name of this guild. /// - public string Name { get; private set; } + public string Name { get; internal set; } /// /// Gets the description for the guild. @@ -24,7 +30,7 @@ public class InviteGuild : ISnowflakeEntity /// /// The description for the guild; if none is set. /// - public string Description { get; private set; } + public string Description { get; internal set; } /// /// Gets the ID of this guild's splash image. @@ -32,7 +38,7 @@ public class InviteGuild : ISnowflakeEntity /// /// An identifier for the splash image; if none is set. /// - public string SplashId { get; private set; } + public string SplashId { get; internal set; } /// /// Gets the URL of this guild's splash image. @@ -48,7 +54,7 @@ public class InviteGuild : ISnowflakeEntity /// /// An identifier for the banner image; if none is set. /// - public string BannerId { get; private set; } + public string BannerId { get; internal set; } /// /// Gets the URL of this guild's banner image. @@ -64,7 +70,7 @@ public class InviteGuild : ISnowflakeEntity /// /// A flags enum containing all the features for the guild. /// - public GuildFeatures Features { get; private set; } + public GuildFeatures Features { get; internal set; } /// /// Gets the ID of this guild's icon. @@ -72,7 +78,7 @@ public class InviteGuild : ISnowflakeEntity /// /// An identifier for the splash image; if none is set. /// - public string IconId { get; private set; } + public string IconId { get; internal set; } /// /// Gets the URL of this guild's icon. @@ -87,9 +93,9 @@ public class InviteGuild : ISnowflakeEntity /// Gets the level of requirements a user must fulfill before being allowed to post messages in this guild. /// /// - /// The level of requirements. + /// The level of requirements. if none is was returned. /// - public VerificationLevel VerificationLevel { get; private set; } + public VerificationLevel? VerificationLevel { get; internal set; } /// /// Gets the code for this guild's vanity invite URL. @@ -97,7 +103,7 @@ public class InviteGuild : ISnowflakeEntity /// /// A string containing the vanity invite code for this guild; if none is set. /// - public string VanityURLCode { get; private set; } + public string VanityURLCode { get; internal set; } /// /// Gets the number of premium subscribers of this guild. @@ -106,17 +112,17 @@ public class InviteGuild : ISnowflakeEntity /// This is the number of users who have boosted this guild. /// /// - /// The number of premium subscribers of this guild; + /// The number of premium subscribers of this guild; if none was returned. /// - public int PremiumSubscriptionCount { get; private set; } + public int? PremiumSubscriptionCount { get; internal set; } /// /// Gets the NSFW level of this guild. /// /// - /// The NSFW level of this guild. + /// The NSFW level of this guild. if none was returned. /// - public NsfwLevel NsfwLevel { get; private set; } + public NsfwLevel? NsfwLevel { get; internal set; } /// /// Gets the Welcome Screen of this guild @@ -124,33 +130,18 @@ public class InviteGuild : ISnowflakeEntity /// /// The welcome screen of this guild. if none is set. /// - public WelcomeScreen WelcomeScreen { get; private set; } + public WelcomeScreen WelcomeScreen { get; internal set; } + + /// + /// Gets the approximate member count in the guild. if none was returned. + /// + public int? ApproximateMemberCount { get; internal set; } + + /// + /// Gets the approximate presence count in the guild. if none was returned. + /// + public int? ApproximatePresenceCount { get; internal set; } + + internal PartialGuild() { } - internal InviteGuild( - ulong id, - string name, - string description, - string splashId, - string bannerId, - GuildFeatures features, - string iconId, - VerificationLevel verificationLevel, - string vanityURLCode, - int premiumSubscriptionCount, - NsfwLevel nsfwLevel, - WelcomeScreen welcomeScreen) - { - Id = id; - Name = name; - Description = description; - SplashId = splashId; - BannerId = bannerId; - Features = features; - IconId = iconId; - VerificationLevel = verificationLevel; - VanityURLCode = vanityURLCode; - PremiumSubscriptionCount = premiumSubscriptionCount; - NsfwLevel = nsfwLevel; - WelcomeScreen = welcomeScreen; - } } diff --git a/src/Discord.Net.Rest/API/Common/Application.cs b/src/Discord.Net.Rest/API/Common/Application.cs index a6069310..8a297cfa 100644 --- a/src/Discord.Net.Rest/API/Common/Application.cs +++ b/src/Discord.Net.Rest/API/Common/Application.cs @@ -14,10 +14,12 @@ namespace Discord.API public ulong Id { get; set; } [JsonProperty("icon")] public string Icon { get; set; } + [JsonProperty("bot_public")] - public bool IsBotPublic { get; set; } + public Optional IsBotPublic { get; set; } [JsonProperty("bot_require_code_grant")] - public bool BotRequiresCodeGrant { get; set; } + public Optional BotRequiresCodeGrant { get; set; } + [JsonProperty("install_params")] public Optional InstallParams { get; set; } [JsonProperty("team")] @@ -28,8 +30,20 @@ namespace Discord.API public Optional Owner { get; set; } [JsonProperty("tags")] public Optional Tags { get; set; } + + [JsonProperty("verify_key")] + public string VerifyKey { get; set; } + + [JsonProperty("approximate_guild_count")] + public Optional ApproximateGuildCount { get; set; } + + [JsonProperty("guild")] + public Optional PartialGuild { get; set; } + + /// Urls [JsonProperty("terms_of_service_url")] public string TermsOfService { get; set; } + [JsonProperty("privacy_policy_url")] public string PrivacyPolicy { get; set; } @@ -39,7 +53,11 @@ namespace Discord.API [JsonProperty("role_connections_verification_url")] public Optional RoleConnectionsUrl { get; set; } - [JsonProperty("verify_key")] - public string VerifyKey { get; set; } + [JsonProperty("interactions_endpoint_url")] + public Optional InteractionsEndpointUrl { get; set; } + + [JsonProperty("redirect_uris")] + public Optional RedirectUris { get; set; } + } } diff --git a/src/Discord.Net.Rest/API/Common/Invite.cs b/src/Discord.Net.Rest/API/Common/Invite.cs index 9e2e6b86..5b425aae 100644 --- a/src/Discord.Net.Rest/API/Common/Invite.cs +++ b/src/Discord.Net.Rest/API/Common/Invite.cs @@ -9,7 +9,7 @@ namespace Discord.API public string Code { get; set; } [JsonProperty("guild")] - public Optional Guild { get; set; } + public Optional Guild { get; set; } [JsonProperty("channel")] public InviteChannel Channel { get; set; } diff --git a/src/Discord.Net.Rest/API/Common/InviteGuild.cs b/src/Discord.Net.Rest/API/Common/PartialGuild.cs similarity index 70% rename from src/Discord.Net.Rest/API/Common/InviteGuild.cs rename to src/Discord.Net.Rest/API/Common/PartialGuild.cs index 82a17d68..85c00c8b 100644 --- a/src/Discord.Net.Rest/API/Common/InviteGuild.cs +++ b/src/Discord.Net.Rest/API/Common/PartialGuild.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Discord.API { - internal class InviteGuild + internal class PartialGuild { [JsonProperty("id")] public ulong Id { get; set; } @@ -23,10 +23,10 @@ namespace Discord.API public Optional IconHash { get; set; } [JsonProperty("features")] - public GuildFeatures Features { get; set; } + public Optional Features { get; set; } [JsonProperty("verification_level")] - public VerificationLevel VerificationLevel { get; set; } + public Optional VerificationLevel { get; set; } [JsonProperty("vanity_url_code")] public Optional VanityUrlCode { get; set; } @@ -38,9 +38,16 @@ namespace Discord.API public Optional Nsfw { get; set; } [JsonProperty("nsfw_level")] - public NsfwLevel NsfwLevel { get; set; } + public Optional NsfwLevel { get; set; } [JsonProperty("welcome_screen")] public Optional WelcomeScreen { get; set; } + + [JsonProperty("approximate_member_count")] + public Optional ApproximateMemberCount { get; set; } + + [JsonProperty("approximate_presence_count")] + public Optional ApproximatePresenceCount { get; set; } + } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyCurrentApplicationBotParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyCurrentApplicationBotParams.cs new file mode 100644 index 00000000..fdd665b2 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyCurrentApplicationBotParams.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; + +namespace Discord.API.Rest; + +internal class ModifyCurrentApplicationBotParams +{ + [JsonProperty("interactions_endpoint_url")] + public Optional InteractionsEndpointUrl { get; set; } + + [JsonProperty("role_connections_verification_url")] + public Optional RoleConnectionsEndpointUrl { get; set; } + + [JsonProperty("description")] + public Optional Description { get; set; } + + [JsonProperty("tags")] + public Optional Tags { get; set; } + + [JsonProperty("icon")] + public Optional Icon { get; set; } +} diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index 38919224..1d95c2c1 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -17,6 +17,34 @@ namespace Discord.Rest return RestApplication.Create(client, model); } + public static async Task GetCurrentBotApplicationAsync(BaseDiscordClient client, RequestOptions options) + { + var model = await client.ApiClient.GetCurrentBotApplicationAsync(options).ConfigureAwait(false); + return RestApplication.Create(client, model); + } + + public static async Task ModifyCurrentBotApplicationAsync(BaseDiscordClient client, Action func, RequestOptions options) + { + var args = new ModifyApplicationProperties(); + func(args); + + if(args.Tags.IsSpecified) + foreach (var tag in args.Tags.Value) + Preconditions.AtMost(tag.Length, DiscordConfig.MaxApplicationTagLength, nameof(args.Tags), $"An application tag must have length less or equal to {DiscordConfig.MaxApplicationTagLength}"); + + if(args.Description.IsSpecified) + Preconditions.AtMost(args.Description.Value.Length, DiscordConfig.MaxApplicationDescriptionLength, nameof(args.Description), $"An application description tag mus have length less or equal to {DiscordConfig.MaxApplicationDescriptionLength}"); + + return await client.ApiClient.ModifyCurrentBotApplicationAsync(new() + { + Description = args.Description, + Tags = args.Tags, + Icon = args.Icon.IsSpecified ? args.Icon.Value?.ToModel() : Optional.Unspecified, + InteractionsEndpointUrl = args.InteractionsEndpointUrl, + RoleConnectionsEndpointUrl = args.RoleConnectionsEndpointUrl, + }, options); + } + public static async Task GetChannelAsync(BaseDiscordClient client, ulong id, RequestOptions options) { diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 6c011676..496d913c 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -2282,11 +2282,27 @@ namespace Discord.API return await SendAsync>("GET", () => $"users/@me/guilds?limit={limit}&after={afterGuildId}&with_counts=true", new BucketIds(), options: options).ConfigureAwait(false); } + public async Task GetMyApplicationAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); return await SendAsync("GET", () => "oauth2/applications/@me", new BucketIds(), options: options).ConfigureAwait(false); } + + public async Task GetCurrentBotApplicationAsync(RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + return await SendAsync("GET", () => "applications/@me", new BucketIds(), options: options).ConfigureAwait(false); + } + + public async Task ModifyCurrentBotApplicationAsync(ModifyCurrentApplicationBotParams args, RequestOptions options = null) + { + Preconditions.NotNull(args, nameof(args)); + options = RequestOptions.CreateOrClone(options); + + return await SendJsonAsync("PATCH", () => "applications/@me", args, new BucketIds(), options: options); + } + public async Task ModifySelfAsync(Rest.ModifyCurrentUserParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index e3860f07..0549fdcb 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -19,6 +19,8 @@ namespace Discord.Rest { #region DiscordRestClient private RestApplication _applicationInfo; + private RestApplication _currentBotApplication; + internal static JsonSerializer Serializer = new JsonSerializer() { ContractResolver = new DiscordContractResolver(), NullValueHandling = NullValueHandling.Include }; /// @@ -170,6 +172,22 @@ namespace Discord.Rest return _applicationInfo ??= await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false); } + public async Task GetCurrentBotInfoAsync(RequestOptions options = null) + { + return _currentBotApplication = await ClientHelper.GetCurrentBotApplicationAsync(this, options); + } + + public async Task ModifyCurrentBotApplicationAsync(Action args, RequestOptions options = null) + { + var model = await ClientHelper.ModifyCurrentBotApplicationAsync(this, args, options); + + if (_currentBotApplication is null) + _currentBotApplication = RestApplication.Create(this, model); + else + _currentBotApplication.Update(model); + return _currentBotApplication; + } + public Task GetChannelAsync(ulong id, RequestOptions options = null) => ClientHelper.GetChannelAsync(this, id, options); public Task> GetPrivateChannelsAsync(RequestOptions options = null) diff --git a/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs b/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs index 4f671937..cf2cb3cb 100644 --- a/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs +++ b/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs @@ -36,7 +36,7 @@ namespace Discord.Rest /// /// A partial guild object representing the guild that the invite points to. /// - public InviteGuild InviteGuild { get; private set; } + public PartialGuild PartialGuild { get; private set; } /// public RestApplication Application { get; private set; } @@ -85,28 +85,7 @@ namespace Discord.Rest if (model.Guild.IsSpecified) { - InviteGuild = new InviteGuild - (model.Guild.Value.Id, - model.Guild.Value.Name, - model.Guild.Value.Description.IsSpecified ? model.Guild.Value.Description.Value : null, - model.Guild.Value.Splash.IsSpecified ? model.Guild.Value.Splash.Value : null, - model.Guild.Value.BannerHash.IsSpecified ? model.Guild.Value.BannerHash.Value : null, - model.Guild.Value.Features, - model.Guild.Value.IconHash.IsSpecified ? model.Guild.Value.IconHash.Value : null, - model.Guild.Value.VerificationLevel, - model.Guild.Value.VanityUrlCode.IsSpecified ? model.Guild.Value.VanityUrlCode.Value : null, - model.Guild.Value.PremiumSubscriptionCount.GetValueOrDefault(0), - model.Guild.Value.NsfwLevel, - model.Guild.Value.WelcomeScreen.IsSpecified - ? new WelcomeScreen( - model.Guild.Value.WelcomeScreen.Value.Description.IsSpecified ? model.Guild.Value.WelcomeScreen.Value.Description.Value : null, - model.Guild.Value.WelcomeScreen.Value.WelcomeChannels.Select(ch => - new WelcomeScreenChannel( - ch.ChannelId, - ch.Description, - ch.EmojiName.IsSpecified ? ch.EmojiName.Value : null, - ch.EmojiId.IsSpecified ? ch.EmojiId.Value : null)).ToImmutableArray()) - : null); + PartialGuild = PartialGuildExtensions.Create(model.Guild.Value); } if(model.Application.IsSpecified) diff --git a/src/Discord.Net.Rest/Entities/RestApplication.cs b/src/Discord.Net.Rest/Entities/RestApplication.cs index eaaf8c27..4b50fafd 100644 --- a/src/Discord.Net.Rest/Entities/RestApplication.cs +++ b/src/Discord.Net.Rest/Entities/RestApplication.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; using System.Threading.Tasks; + using Model = Discord.API.Application; namespace Discord.Rest @@ -24,9 +25,9 @@ namespace Discord.Rest /// public ApplicationFlags Flags { get; private set; } /// - public bool IsBotPublic { get; private set; } + public bool? IsBotPublic { get; private set; } /// - public bool BotRequiresCodeGrant { get; private set; } + public bool? BotRequiresCodeGrant { get; private set; } /// public ITeam Team { get; private set; } /// @@ -48,6 +49,18 @@ namespace Discord.Rest /// public string IconUrl => CDN.GetApplicationIconUrl(Id, _iconId); + /// + public PartialGuild Guild { get; private set; } + + /// + public int? ApproximateGuildCount { get; private set; } + + /// + public IReadOnlyCollection RedirectUris { get; private set; } + + /// + public string InteractionsEndpointUrl { get; private set; } + public ApplicationInstallParams InstallParams { get; private set; } public IReadOnlyCollection Tags { get; private set; } @@ -68,13 +81,13 @@ namespace Discord.Rest RPCOrigins = model.RPCOrigins.IsSpecified ? model.RPCOrigins.Value.ToImmutableArray() : ImmutableArray.Empty; Name = model.Name; _iconId = model.Icon; - IsBotPublic = model.IsBotPublic; - BotRequiresCodeGrant = model.BotRequiresCodeGrant; + IsBotPublic = model.IsBotPublic.IsSpecified ? model.IsBotPublic.Value : null; + BotRequiresCodeGrant = model.BotRequiresCodeGrant.IsSpecified ? model.BotRequiresCodeGrant.Value : null; Tags = model.Tags.GetValueOrDefault(null)?.ToImmutableArray() ?? ImmutableArray.Empty; PrivacyPolicy = model.PrivacyPolicy; TermsOfService = model.TermsOfService; var installParams = model.InstallParams.GetValueOrDefault(null); - InstallParams = new ApplicationInstallParams(installParams?.Scopes ?? new string[0], (GuildPermission?)installParams?.Permission ?? null); + InstallParams = new ApplicationInstallParams(installParams?.Scopes ?? Array.Empty(), (GuildPermission?)installParams?.Permission); if (model.Flags.IsSpecified) Flags = model.Flags.Value; @@ -86,6 +99,16 @@ namespace Discord.Rest CustomInstallUrl = model.CustomInstallUrl.IsSpecified ? model.CustomInstallUrl.Value : null; RoleConnectionsVerificationUrl = model.RoleConnectionsUrl.IsSpecified ? model.RoleConnectionsUrl.Value : null; VerifyKey = model.VerifyKey; + + if (model.PartialGuild.IsSpecified) + Guild = PartialGuildExtensions.Create(model.PartialGuild.Value); + + InteractionsEndpointUrl = model.InteractionsEndpointUrl.IsSpecified ? model.InteractionsEndpointUrl.Value : null; + + if (model.RedirectUris.IsSpecified) + RedirectUris = model.RedirectUris.Value.ToImmutableArray(); + + ApproximateGuildCount = model.ApproximateGuildCount.IsSpecified ? model.ApproximateGuildCount.Value : null; } /// Unable to update this object from a different application token. diff --git a/src/Discord.Net.Rest/Extensions/PartialGuildExtensions.cs b/src/Discord.Net.Rest/Extensions/PartialGuildExtensions.cs new file mode 100644 index 00000000..b8caace3 --- /dev/null +++ b/src/Discord.Net.Rest/Extensions/PartialGuildExtensions.cs @@ -0,0 +1,35 @@ +using System.Collections.Immutable; +using System.Linq; + +namespace Discord.Rest; + +internal static class PartialGuildExtensions +{ + public static PartialGuild Create(API.PartialGuild model) + => new PartialGuild + { + Id = model.Id, + Name = model.Name, + Description = model.Description.IsSpecified ? model.Description.Value : null, + SplashId = model.Splash.IsSpecified ? model.Splash.Value : null, + BannerId = model.BannerHash.IsSpecified ? model.BannerHash.Value : null, + Features = model.Features.IsSpecified ? model.Features.Value : null, + IconId = model.IconHash.IsSpecified ? model.IconHash.Value : null, + VerificationLevel = model.VerificationLevel.IsSpecified ? model.VerificationLevel.Value : null, + VanityURLCode = model.VanityUrlCode.IsSpecified ? model.VanityUrlCode.Value : null, + PremiumSubscriptionCount = model.PremiumSubscriptionCount.IsSpecified ? model.PremiumSubscriptionCount.Value : null, + NsfwLevel = model.NsfwLevel.IsSpecified ? model.NsfwLevel.Value : null, + WelcomeScreen = model.WelcomeScreen.IsSpecified + ? new WelcomeScreen( + model.WelcomeScreen.Value.Description.IsSpecified ? model.WelcomeScreen.Value.Description.Value : null, + model.WelcomeScreen.Value.WelcomeChannels.Select(ch => + new WelcomeScreenChannel( + ch.ChannelId, + ch.Description, + ch.EmojiName.IsSpecified ? ch.EmojiName.Value : null, + ch.EmojiId.IsSpecified ? ch.EmojiId.Value : null)).ToImmutableArray()) + : null, + ApproximateMemberCount = model.ApproximateMemberCount.IsSpecified ? model.ApproximateMemberCount.Value : null, + ApproximatePresenceCount = model.ApproximatePresenceCount.IsSpecified ? model.ApproximatePresenceCount.Value : null + }; +}