diff --git a/DisCatSharp.ApplicationCommands/Context/BaseContext.cs b/DisCatSharp.ApplicationCommands/Context/BaseContext.cs index d63fac1474..cf173a171a 100644 --- a/DisCatSharp.ApplicationCommands/Context/BaseContext.cs +++ b/DisCatSharp.ApplicationCommands/Context/BaseContext.cs @@ -28,7 +28,7 @@ public class BaseContext /// /// Gets the guild this interaction was executed in. /// - public DiscordGuild Guild { get; internal init; } + public DiscordGuild? Guild { get; internal init; } /// /// Gets the channel this interaction was executed in. @@ -43,7 +43,7 @@ public class BaseContext /// /// Gets the member which executed this interaction, or null if the command is in a DM. /// - public DiscordMember Member + public DiscordMember? Member => this.User is DiscordMember member ? member : null; /// diff --git a/DisCatSharp.CommandsNext/EventArgs/CommandContext.cs b/DisCatSharp.CommandsNext/EventArgs/CommandContext.cs index 1d4fa6bb04..7a71858143 100644 --- a/DisCatSharp.CommandsNext/EventArgs/CommandContext.cs +++ b/DisCatSharp.CommandsNext/EventArgs/CommandContext.cs @@ -32,7 +32,7 @@ public DiscordChannel Channel /// /// Gets the guild in which the execution was triggered. This property is null for commands sent over direct messages. /// - public DiscordGuild Guild + public DiscordGuild? Guild => this.Message.GuildId.HasValue ? this.Message.Guild : null; /// @@ -99,7 +99,7 @@ public DiscordMember Member /// internal CommandContext() { - this._lazyMember = new(() => this.Guild != null && this.Guild.Members.TryGetValue(this.User.Id, out var member) ? member : this.Guild?.GetMemberAsync(this.User.Id).ConfigureAwait(false).GetAwaiter().GetResult()); + this._lazyMember = new(() => this.Guild is not null && this.Guild.Members.TryGetValue(this.User.Id, out var member) ? member : this.Guild?.GetMemberAsync(this.User.Id).ConfigureAwait(false).GetAwaiter().GetResult()); } /// @@ -182,6 +182,7 @@ public ServiceContext(IServiceProvider services, IServiceScope scope) /// /// Disposes the command context. /// - public void Dispose() => this.Scope?.Dispose(); + public void Dispose() + => this.Scope?.Dispose(); } } diff --git a/DisCatSharp/Entities/Application/DiscordApplicationCommand.cs b/DisCatSharp/Entities/Application/DiscordApplicationCommand.cs index a446297986..c71ad1f8ac 100644 --- a/DisCatSharp/Entities/Application/DiscordApplicationCommand.cs +++ b/DisCatSharp/Entities/Application/DiscordApplicationCommand.cs @@ -36,14 +36,14 @@ public class DiscordApplicationCommand : SnowflakeObject, IEquatable [JsonProperty("name_localizations", NullValueHandling = NullValueHandling.Ignore)] - internal Dictionary RawNameLocalizations { get; set; } + internal Dictionary? RawNameLocalizations { get; set; } /// /// Gets the name localizations. /// [JsonIgnore] - public DiscordApplicationCommandLocalization NameLocalizations - => new(this.RawNameLocalizations); + public DiscordApplicationCommandLocalization? NameLocalizations + => this.RawNameLocalizations != null ? new(this.RawNameLocalizations) : null; /// /// Gets the description of this command. @@ -55,14 +55,14 @@ public DiscordApplicationCommandLocalization NameLocalizations /// Sets the description localizations. /// [JsonProperty("description_localizations", NullValueHandling = NullValueHandling.Ignore)] - internal Dictionary RawDescriptionLocalizations { get; set; } + internal Dictionary? RawDescriptionLocalizations { get; set; } /// /// Gets the description localizations. /// [JsonIgnore] - public DiscordApplicationCommandLocalization DescriptionLocalizations - => new(this.RawDescriptionLocalizations); + public DiscordApplicationCommandLocalization? DescriptionLocalizations + => this.RawDescriptionLocalizations != null ? new(this.RawDescriptionLocalizations) : null; /// /// Gets the potential parameters for this command. @@ -145,7 +145,7 @@ public DiscordApplicationCommand( { if (!Utilities.IsValidSlashCommandName(name)) throw new ArgumentException("Invalid slash command name specified. It must be below 32 characters and not contain any whitespace.", nameof(name)); - if (name.Any(ch => char.IsUpper(ch))) + if (name.Any(char.IsUpper)) throw new ArgumentException("Slash command name cannot have any upper case characters.", nameof(name)); if (description.Length > 100) throw new ArgumentException("Slash command description cannot exceed 100 characters.", nameof(description)); diff --git a/DisCatSharp/Entities/Core/IDisCatSharpCommand.cs b/DisCatSharp/Entities/Core/IDisCatSharpCommand.cs new file mode 100644 index 0000000000..a7c6f01d54 --- /dev/null +++ b/DisCatSharp/Entities/Core/IDisCatSharpCommand.cs @@ -0,0 +1,49 @@ +using DisCatSharp.Enums.Core; + +namespace DisCatSharp.Entities.Core; + +/// +/// Interface for various command types like slash commands, user commands, message commands, text commands, etc. +/// +internal interface IDisCatSharpCommand +{ + /// + /// Gets the id of the user who executes this command. + /// + ulong UserId { get; internal set; } + + /// + /// Gets the id of the channel this command gets executed in. + /// + ulong ChannelId { get; internal set; } + + /// + /// Gets the id of the guild this command gets executed in. + /// + ulong? GuildId { get; internal set; } + + /// + /// Gets the id of the member who executes this command. + /// + ulong? MemberId { get; internal set; } + + /// + /// Gets the id of the command. + /// + ulong? CommandId { get; internal set; } + + /// + /// Gets the name of the command if is not available. + /// + string? CommandName { get; internal set; } + + /// + /// Gets the type of the command. + /// + DisCatSharpCommandType CommandType { get; internal set; } + + /// + /// Gets the command grouping type of the command. + /// + DisCatSharpCommandGroupingType CommandGroupingType { get; internal set; } +} diff --git a/DisCatSharp/Entities/DCS/DisCatSharpTeam.cs b/DisCatSharp/Entities/DCS/DisCatSharpTeam.cs deleted file mode 100644 index 094ec2173c..0000000000 --- a/DisCatSharp/Entities/DCS/DisCatSharpTeam.cs +++ /dev/null @@ -1,183 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; - -using DisCatSharp.Enums; -using DisCatSharp.Net; -using DisCatSharp.Net.Abstractions; - -using Microsoft.Extensions.Logging; - -using Newtonsoft.Json; - -namespace DisCatSharp.Entities; - -/// -/// The DisCatSharp team. -/// -public sealed class DisCatSharpTeam : SnowflakeObject -{ - /// - /// Gets the team's name. - /// - public string TeamName { get; internal set; } - - /// - /// Gets the overall owner. - /// - public string MainOwner - => "Lala Sabathil"; - - /// - /// Gets the team's icon. - /// - public string Icon - => !string.IsNullOrWhiteSpace(this.IconHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.TEAM_ICONS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.IconHash}.png?size=1024" : null; - - /// - /// Gets the team's icon's hash. - /// - public string IconHash { get; internal set; } - - /// - /// Gets the team's logo. - /// - public string Logo - => !string.IsNullOrWhiteSpace(this.LogoHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.ICONS}/{this.GuildId.ToString(CultureInfo.InvariantCulture)}/{this.LogoHash}.png?size=1024" : null; - - /// - /// Gets the team's logo's hash. - /// - public string LogoHash { get; internal set; } - - /// - /// Gets the team's banner. - /// - public string Banner - => !string.IsNullOrWhiteSpace(this.BannerHash) ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.BANNERS}/{this.GuildId.ToString(CultureInfo.InvariantCulture)}/{this.BannerHash}.png?size=1024" : null; - - /// - /// Gets the team's banner's hash. - /// - public string BannerHash { get; internal set; } - - /// - /// Gets the team's docs url. - /// - public string DocsUrl { get; internal set; } - - /// - /// Gets the team's repo url. - /// - public string RepoUrl { get; internal set; } - - /// - /// Gets the team's terms of service url. - /// - public string TermsOfServiceUrl { get; internal set; } - - /// - /// Gets the team's privacy policy url. - /// - public string PrivacyPolicyUrl { get; internal set; } - - /// - /// Get's the team's guild id - /// - public ulong GuildId { get; internal set; } - - /// - /// Gets the team's developers. - /// - public IReadOnlyList Developers { get; internal set; } - - /// - /// Gets the team's owner. - /// - public DisCatSharpTeamMember Owner { get; internal set; } - - /// - /// Gets the team's guild. - /// - public DiscordGuild Guild { get; internal set; } - - /// - /// Gets the team's support invite. - /// - public DiscordInvite SupportInvite { get; internal set; } - - /// - /// Initializes a new instance of the class. - /// - internal static async Task Get(HttpClient http, ILogger logger, DiscordApiClient apiClient) - { - try - { - var dcs = await http.GetStringAsync(new Uri("https://dcs.aitsys.dev/api/devs/")).ConfigureAwait(false); - var dcsGuild = await http.GetStringAsync(new Uri("https://dcs.aitsys.dev/api/guild/")).ConfigureAwait(false); - - var app = JsonConvert.DeserializeObject(dcs); - var guild = JsonConvert.DeserializeObject(dcsGuild); - - var dcst = new DisCatSharpTeam - { - IconHash = app.Team.IconHash, - TeamName = app.Team.Name, - PrivacyPolicyUrl = app.PrivacyPolicyUrl, - TermsOfServiceUrl = app.TermsOfServiceUrl, - RepoUrl = "https://github.com/Aiko-IT-Systems/DisCatSharp", - DocsUrl = "https://docs.dcs.aitsys.dev", - Id = app.Team.Id, - BannerHash = guild.BannerHash, - LogoHash = guild.IconHash, - GuildId = guild.Id, - Guild = guild, - SupportInvite = await apiClient.GetInviteAsync("GGYSywkxwN", true, true, null).ConfigureAwait(false) - }; - List team = []; - DisCatSharpTeamMember owner = new(); - foreach (var mb in app.Team.Members.OrderBy(m => m.User.Username)) - { - var tuser = await apiClient.GetUserAsync(mb.User.Id).ConfigureAwait(false); - var user = mb.User; - if (mb.User.Id == 856780995629154305) - { - owner.Id = user.Id; - owner.Username = user.Username; - owner.Discriminator = user.Discriminator; - owner.AvatarHash = user.AvatarHash; - owner.BannerHash = tuser.BannerHash; - owner.BannerColorInternal = tuser.BannerColorInternal; - team.Add(owner); - } - else - team.Add(new() - { - Id = user.Id, - Username = user.Username, - Discriminator = user.Discriminator, - AvatarHash = user.AvatarHash, - BannerHash = tuser.BannerHash, - BannerColorInternal = tuser.BannerColorInternal - }); - } - - dcst.Owner = owner; - dcst.Developers = team; - - return dcst; - } - catch (Exception ex) - { - logger.LogDebug(ex.Message); - logger.LogDebug(ex.StackTrace); - return null; - } - } - - private DisCatSharpTeam() - { } -} diff --git a/DisCatSharp/Entities/DCS/DisCatSharpTeamMember.cs b/DisCatSharp/Entities/DCS/DisCatSharpTeamMember.cs deleted file mode 100644 index 367e6a71f0..0000000000 --- a/DisCatSharp/Entities/DCS/DisCatSharpTeamMember.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Globalization; - -using DisCatSharp.Enums; -using DisCatSharp.Net; - -namespace DisCatSharp.Entities; - -/// -/// Represents a DisCatSharp team member. -/// -public sealed class DisCatSharpTeamMember : SnowflakeObject -{ - /// - /// Gets this user's username. - /// - public string Username { get; internal set; } - - /// - /// Gets the user's 4-digit discriminator. - /// - public string Discriminator { get; internal set; } - - /// - /// Gets the discriminator integer. - /// - internal int DiscriminatorInt - => int.Parse(this.Discriminator, NumberStyles.Integer, CultureInfo.InvariantCulture); - - /// - /// Gets the user's banner color, if set. Mutually exclusive with . - /// - public DiscordColor? BannerColor - => !this.BannerColorInternal.HasValue ? null : new DiscordColor(this.BannerColorInternal.Value); - - internal int? BannerColorInternal; - - /// - /// Gets the user's banner url - /// - public string BannerUrl - => string.IsNullOrWhiteSpace(this.BannerHash) ? null : $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.BANNERS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.BannerHash}.{(this.BannerHash.StartsWith("a_", StringComparison.Ordinal) ? "gif" : "png")}?size=4096"; - - /// - /// Gets the user's profile banner hash. Mutually exclusive with . - /// - public string BannerHash { get; internal set; } - - /// - /// Gets the user's avatar hash. - /// - public string AvatarHash { get; internal set; } - - /// - /// Gets the user's avatar URL. - /// - public string AvatarUrl - => string.IsNullOrWhiteSpace(this.AvatarHash) ? this.DefaultAvatarUrl : $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.AVATARS}/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.AvatarHash}.{(this.AvatarHash.StartsWith("a_", StringComparison.Ordinal) ? "gif" : "png")}?size=1024"; - - /// - /// Gets the URL of default avatar for this user. - /// - public string DefaultAvatarUrl - => $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.EMBED}{Endpoints.AVATARS}/{(this.DiscriminatorInt % 5).ToString(CultureInfo.InvariantCulture)}.png?size=1024"; - - /// - /// Initializes a new instance of the class. - /// - internal DisCatSharpTeamMember() - { } -} diff --git a/DisCatSharp/Entities/DCS/GitHubRelease.cs b/DisCatSharp/Entities/DCS/GitHubRelease.cs deleted file mode 100644 index ed54c37a73..0000000000 --- a/DisCatSharp/Entities/DCS/GitHubRelease.cs +++ /dev/null @@ -1,165 +0,0 @@ -using System; -using System.Collections.Generic; - -using Newtonsoft.Json; - -namespace DisCatSharp.Entities.DCS; - -internal class GitHubRelease -{ - [JsonProperty("url", NullValueHandling = NullValueHandling.Ignore)] - public Uri Url { get; set; } - - [JsonProperty("assets_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri AssetsUrl { get; set; } - - [JsonProperty("upload_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri UploadUrl { get; set; } - - [JsonProperty("html_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri HtmlUrl { get; set; } - - [JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)] - public int? Id { get; set; } - - [JsonProperty("author", NullValueHandling = NullValueHandling.Ignore)] - public GitHubUser Author { get; set; } - - [JsonProperty("node_id", NullValueHandling = NullValueHandling.Ignore)] - public string NodeId { get; set; } - - [JsonProperty("tag_name", NullValueHandling = NullValueHandling.Ignore)] - public string TagName { get; set; } - - [JsonProperty("target_commitish", NullValueHandling = NullValueHandling.Ignore)] - public string TargetCommitish { get; set; } - - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] - public string Name { get; set; } - - [JsonProperty("draft", NullValueHandling = NullValueHandling.Ignore)] - public bool? Draft { get; set; } - - [JsonProperty("prerelease", NullValueHandling = NullValueHandling.Ignore)] - public bool? Prerelease { get; set; } - - [JsonProperty("created_at", NullValueHandling = NullValueHandling.Ignore)] - public DateTime? CreatedAt { get; set; } - - [JsonProperty("published_at", NullValueHandling = NullValueHandling.Ignore)] - public DateTime? PublishedAt { get; set; } - - [JsonProperty("assets", NullValueHandling = NullValueHandling.Ignore)] - public List Assets { get; set; } - - [JsonProperty("tarball_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri TarballUrl { get; set; } - - [JsonProperty("zipball_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri ZipballUrl { get; set; } - - [JsonProperty("body", NullValueHandling = NullValueHandling.Ignore)] - public string Body { get; set; } - - [JsonProperty("mentions_count", NullValueHandling = NullValueHandling.Ignore)] - public int? MentionsCount { get; set; } - - public class Asset - { - [JsonProperty("url", NullValueHandling = NullValueHandling.Ignore)] - public Uri Url { get; set; } - - [JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)] - public int? Id { get; set; } - - [JsonProperty("node_id", NullValueHandling = NullValueHandling.Ignore)] - public string NodeId { get; set; } - - [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] - public string Name { get; set; } - - [JsonProperty("label", NullValueHandling = NullValueHandling.Ignore)] - public string? Label { get; set; } - - [JsonProperty("uploader", NullValueHandling = NullValueHandling.Ignore)] - public GitHubUser Uploader { get; set; } - - [JsonProperty("content_type", NullValueHandling = NullValueHandling.Ignore)] - public string ContentType { get; set; } - - [JsonProperty("state", NullValueHandling = NullValueHandling.Ignore)] - public string State { get; set; } - - [JsonProperty("size", NullValueHandling = NullValueHandling.Ignore)] - public int? Size { get; set; } - - [JsonProperty("download_count", NullValueHandling = NullValueHandling.Ignore)] - public int? DownloadCount { get; set; } - - [JsonProperty("created_at", NullValueHandling = NullValueHandling.Ignore)] - public DateTime? CreatedAt { get; set; } - - [JsonProperty("updated_at", NullValueHandling = NullValueHandling.Ignore)] - public DateTime? UpdatedAt { get; set; } - - [JsonProperty("browser_download_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri BrowserDownloadUrl { get; set; } - } - - public class GitHubUser - { - [JsonProperty("login", NullValueHandling = NullValueHandling.Ignore)] - public string Login { get; set; } - - [JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)] - public int? Id { get; set; } - - [JsonProperty("node_id", NullValueHandling = NullValueHandling.Ignore)] - public string NodeId { get; set; } - - [JsonProperty("avatar_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri AvatarUrl { get; set; } - - [JsonProperty("gravatar_id", NullValueHandling = NullValueHandling.Ignore)] - public string GravatarId { get; set; } - - [JsonProperty("url", NullValueHandling = NullValueHandling.Ignore)] - public Uri Url { get; set; } - - [JsonProperty("html_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri HtmlUrl { get; set; } - - [JsonProperty("followers_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri FollowersUrl { get; set; } - - [JsonProperty("following_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri FollowingUrl { get; set; } - - [JsonProperty("gists_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri GistsUrl { get; set; } - - [JsonProperty("starred_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri StarredUrl { get; set; } - - [JsonProperty("subscriptions_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri SubscriptionsUrl { get; set; } - - [JsonProperty("organizations_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri OrganizationsUrl { get; set; } - - [JsonProperty("repos_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri ReposUrl { get; set; } - - [JsonProperty("events_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri EventsUrl { get; set; } - - [JsonProperty("received_events_url", NullValueHandling = NullValueHandling.Ignore)] - public Uri ReceivedEventsUrl { get; set; } - - [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] - public string Type { get; set; } - - [JsonProperty("site_admin", NullValueHandling = NullValueHandling.Ignore)] - public bool? SiteAdmin { get; set; } - } -} diff --git a/DisCatSharp/Enums/Core/DisCatSharpCommandGroupingType.cs b/DisCatSharp/Enums/Core/DisCatSharpCommandGroupingType.cs new file mode 100644 index 0000000000..e48e2e2d86 --- /dev/null +++ b/DisCatSharp/Enums/Core/DisCatSharpCommandGroupingType.cs @@ -0,0 +1,27 @@ +namespace DisCatSharp.Enums.Core; + +/// +/// Represents the grouping type of a command. +/// +internal enum DisCatSharpCommandGroupingType +{ + /// + /// The command is not part of a group. + /// + None, + + /// + /// The command is a group. + /// + Group, + + /// + /// The command is a subgroup. + /// + SubGroup, + + /// + /// The command is a subcommand. + /// + SubCommand +} diff --git a/DisCatSharp/Enums/Core/DisCatSharpCommandType.cs b/DisCatSharp/Enums/Core/DisCatSharpCommandType.cs new file mode 100644 index 0000000000..b7394f1eca --- /dev/null +++ b/DisCatSharp/Enums/Core/DisCatSharpCommandType.cs @@ -0,0 +1,32 @@ +namespace DisCatSharp.Enums.Core; + +/// +/// Represents the type of a command. +/// +internal enum DisCatSharpCommandType +{ + /// + /// A text command. + /// + TextCommand, + + /// + /// A slash command. + /// + SlashCommand, + + /// + /// A user context menu command. + /// + UserCommand, + + /// + /// A message context menu command. + /// + MessageCommand, + + /// + /// A special component command. + /// + ComponentCommand +} diff --git a/DisCatSharp/Net/Abstractions/Rest/RestApplicationCommandPayloads.cs b/DisCatSharp/Net/Abstractions/Rest/RestApplicationCommandPayloads.cs index fae7e13eb7..2c5d079cc9 100644 --- a/DisCatSharp/Net/Abstractions/Rest/RestApplicationCommandPayloads.cs +++ b/DisCatSharp/Net/Abstractions/Rest/RestApplicationCommandPayloads.cs @@ -28,25 +28,25 @@ internal sealed class RestApplicationCommandCreatePayload : ObservableApiObject /// Gets the name localizations. /// [JsonProperty("name_localizations", NullValueHandling = NullValueHandling.Ignore)] - public Optional> NameLocalizations { get; set; } + public Optional?> NameLocalizations { get; set; } /// /// Gets the description. /// [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] - public string Description { get; set; } + public string? Description { get; set; } /// /// Gets the description localizations. /// [JsonProperty("description_localizations", NullValueHandling = NullValueHandling.Ignore)] - public Optional> DescriptionLocalizations { get; set; } + public Optional?> DescriptionLocalizations { get; set; } /// /// Gets the options. /// [JsonProperty("options", NullValueHandling = NullValueHandling.Ignore)] - public IEnumerable Options { get; set; } + public IEnumerable? Options { get; set; } /// /// Whether the command is allowed for everyone. @@ -99,26 +99,26 @@ internal sealed class RestApplicationCommandEditPayload : ObservableApiObject /// /// Gets the name localizations. /// - [JsonProperty("name_localizations")] - public Optional> NameLocalizations { get; set; } + [JsonProperty("name_localizations", NullValueHandling = NullValueHandling.Ignore)] + public Optional?> NameLocalizations { get; set; } /// /// Gets the description. /// [JsonProperty("description")] - public Optional Description { get; set; } + public Optional Description { get; set; } /// /// Gets the description localizations. /// - [JsonProperty("description_localizations")] - public Optional> DescriptionLocalizations { get; set; } + [JsonProperty("description_localizations", NullValueHandling = NullValueHandling.Ignore)] + public Optional?> DescriptionLocalizations { get; set; } /// /// Gets the options. /// [JsonProperty("options", NullValueHandling = NullValueHandling.Ignore)] - public Optional> Options { get; set; } + public Optional?> Options { get; set; } /// /// The command needed permissions. diff --git a/DisCatSharp/Net/Rest/DiscordApiClient.cs b/DisCatSharp/Net/Rest/DiscordApiClient.cs index 7f74ea06a2..ca6f72df9e 100644 --- a/DisCatSharp/Net/Rest/DiscordApiClient.cs +++ b/DisCatSharp/Net/Rest/DiscordApiClient.cs @@ -5946,21 +5946,20 @@ internal async Task> BulkOverwriteGloba { var pld = new List(); if (commands.Any()) - foreach (var command in commands) - pld.Add(new() - { - Type = command.Type, - Name = command.Name, - Description = command.Type == ApplicationCommandType.ChatInput ? command.Description : null, - Options = command.Options, - NameLocalizations = command.NameLocalizations?.GetKeyValuePairs(), - DescriptionLocalizations = command.DescriptionLocalizations?.GetKeyValuePairs(), - DefaultMemberPermission = command.DefaultMemberPermissions, - DmPermission = command.DmPermission, - Nsfw = command.IsNsfw, - AllowedContexts = command.AllowedContexts, - IntegrationTypes = command.IntegrationTypes - }); + pld.AddRange(commands.Select(command => new RestApplicationCommandCreatePayload() + { + Type = command.Type, + Name = command.Name, + Description = command.Type is ApplicationCommandType.ChatInput ? command.Description : null, + Options = command.Options, + NameLocalizations = command.NameLocalizations?.GetKeyValuePairs(), + DescriptionLocalizations = command.DescriptionLocalizations?.GetKeyValuePairs(), + DefaultMemberPermission = command.DefaultMemberPermissions, + DmPermission = command.DmPermission, + Nsfw = command.IsNsfw, + AllowedContexts = command.AllowedContexts, + IntegrationTypes = command.IntegrationTypes + })); var route = $"{Endpoints.APPLICATIONS}/:application_id{Endpoints.COMMANDS}"; var bucket = this.Rest.GetBucket(RestRequestMethod.PUT, route, new @@ -5986,10 +5985,10 @@ internal async Task CreateGlobalApplicationCommandAsy { Type = command.Type, Name = command.Name, - Description = command.Type == ApplicationCommandType.ChatInput ? command.Description : null, + Description = command.Type is ApplicationCommandType.ChatInput ? command.Description : null, Options = command.Options, - NameLocalizations = command.NameLocalizations.GetKeyValuePairs(), - DescriptionLocalizations = command.DescriptionLocalizations.GetKeyValuePairs(), + NameLocalizations = command.NameLocalizations?.GetKeyValuePairs(), + DescriptionLocalizations = command.DescriptionLocalizations?.GetKeyValuePairs(), DefaultMemberPermission = command.DefaultMemberPermissions, DmPermission = command.DmPermission, Nsfw = command.IsNsfw, @@ -6054,10 +6053,10 @@ internal async Task EditGlobalApplicationCommandAsync ulong applicationId, ulong commandId, Optional name, - Optional description, + Optional description, Optional?> options, - Optional nameLocalization, - Optional descriptionLocalization, + Optional nameLocalization, + Optional descriptionLocalization, Optional defaultMemberPermission, Optional dmPermission, Optional isNsfw, @@ -6149,20 +6148,19 @@ internal async Task> BulkOverwriteGuild { var pld = new List(); if (commands.Any()) - foreach (var command in commands) - pld.Add(new() - { - Type = command.Type, - Name = command.Name, - Description = command.Type == ApplicationCommandType.ChatInput ? command.Description : null, - Options = command.Options, - NameLocalizations = command.NameLocalizations?.GetKeyValuePairs(), - DescriptionLocalizations = command.DescriptionLocalizations?.GetKeyValuePairs(), - DefaultMemberPermission = command.DefaultMemberPermissions, - DmPermission = command.DmPermission, - Nsfw = command.IsNsfw, - AllowedContexts = command.AllowedContexts - }); + pld.AddRange(commands.Select(command => new RestApplicationCommandCreatePayload() + { + Type = command.Type, + Name = command.Name, + Description = command.Type is ApplicationCommandType.ChatInput ? command.Description : null, + Options = command.Options, + NameLocalizations = command.NameLocalizations?.GetKeyValuePairs(), + DescriptionLocalizations = command.DescriptionLocalizations?.GetKeyValuePairs(), + DefaultMemberPermission = command.DefaultMemberPermissions, + DmPermission = command.DmPermission, + Nsfw = command.IsNsfw, + AllowedContexts = command.AllowedContexts + })); var route = $"{Endpoints.APPLICATIONS}/:application_id{Endpoints.GUILDS}/:guild_id{Endpoints.COMMANDS}"; var bucket = this.Rest.GetBucket(RestRequestMethod.PUT, route, new @@ -6192,8 +6190,8 @@ internal async Task CreateGuildApplicationCommandAsyn Name = command.Name, Description = command.Type == ApplicationCommandType.ChatInput ? command.Description : null, Options = command.Options, - NameLocalizations = command.NameLocalizations.GetKeyValuePairs(), - DescriptionLocalizations = command.DescriptionLocalizations.GetKeyValuePairs(), + NameLocalizations = command.NameLocalizations?.GetKeyValuePairs(), + DescriptionLocalizations = command.DescriptionLocalizations?.GetKeyValuePairs(), DefaultMemberPermission = command.DefaultMemberPermissions, DmPermission = command.DmPermission, Nsfw = command.IsNsfw, @@ -6262,10 +6260,10 @@ internal async Task EditGuildApplicationCommandAsync( ulong guildId, ulong commandId, Optional name, - Optional description, + Optional description, Optional?> options, - Optional nameLocalization, - Optional descriptionLocalization, + Optional nameLocalization, + Optional descriptionLocalization, Optional defaultMemberPermission, Optional dmPermission, Optional isNsfw,