diff --git a/DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs b/DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs index 72d86d1683..0c8dc8f11e 100644 --- a/DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs +++ b/DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs @@ -675,20 +675,20 @@ private async Task RegisterCommands(List if (scg.Options is not null) foreach (var sc in scg.Options) if (sc.Options is null || sc.Options.Count is 0) - cs.Add(new(sc.Name, sc.Description, null, null)); + cs.Add(new(sc.Name, sc.Description, null, null, sc.RawNameLocalizations, sc.RawDescriptionLocalizations)); else - cs.Add(new(sc.Name, sc.Description, [.. sc.Options], null)); - cgs.Add(new(scg.Name, scg.Description, cs, null)); + cs.Add(new(sc.Name, sc.Description, [.. sc.Options], null, sc.RawNameLocalizations, sc.RawDescriptionLocalizations)); + cgs.Add(new(scg.Name, scg.Description, cs, null, scg.RawNameLocalizations, scg.RawDescriptionLocalizations)); } foreach (var sc2 in cmd.Options.Where(x => x.Type is ApplicationCommandOptionType.SubCommand)) if (sc2.Options == null || sc2.Options.Count == 0) - cs2.Add(new(sc2.Name, sc2.Description, null, null)); + cs2.Add(new(sc2.Name, sc2.Description, null, null, sc2.RawNameLocalizations, sc2.RawDescriptionLocalizations)); else - cs2.Add(new(sc2.Name, sc2.Description, [.. sc2.Options], null)); + cs2.Add(new(sc2.Name, sc2.Description, [.. sc2.Options], null, sc2.RawNameLocalizations, sc2.RawDescriptionLocalizations)); } - cgwsgs.Add(new(cmd.Name, cmd.Description, cgs, cs2, cmd.Type)); + cgwsgs.Add(new(cmd.Name, cmd.Description, cgs, cs2, cmd.Type, cmd.RawNameLocalizations, cmd.RawDescriptionLocalizations)); } if (cgwsgs.Count is not 0) @@ -732,12 +732,20 @@ private async Task RegisterCommands(List var cs = new List(); foreach (var cmd in slashCommands.applicationCommands.Where(cmd => cmd.Type is ApplicationCommandType.ChatInput && (cmd.Options is null || !cmd.Options.Any(x => x.Type is ApplicationCommandOptionType.SubCommand or ApplicationCommandOptionType.SubCommandGroup)))) if (cmd.Options == null || cmd.Options.Count == 0) - cs.Add(new(cmd.Name, cmd.Description, null, ApplicationCommandType.ChatInput)); + cs.Add(new(cmd.Name, cmd.Description, null, ApplicationCommandType.ChatInput, cmd.RawNameLocalizations, cmd.RawDescriptionLocalizations)); else - cs.Add(new(cmd.Name, cmd.Description, [.. cmd.Options], ApplicationCommandType.ChatInput)); + cs.Add(new(cmd.Name, cmd.Description, [.. cmd.Options], ApplicationCommandType.ChatInput, cmd.RawNameLocalizations, cmd.RawDescriptionLocalizations)); if (cs.Count is not 0) - translation.AddRange(cs.Select(c => JsonConvert.DeserializeObject(JsonConvert.SerializeObject(c))!)); + //translation.AddRange(cs.Select(c => JsonConvert.DeserializeObject(JsonConvert.SerializeObject(c))!)); + { + foreach (var c in cs) + { + var json = JsonConvert.SerializeObject(c); + var obj = JsonConvert.DeserializeObject(json); + translation.Add(obj!); + } + } } } @@ -910,7 +918,7 @@ private async Task RegisterCommands(List RegisteredCommands = GlobalCommandsInternal }).ConfigureAwait(false); - await this.CheckRegistrationStartup(translation, groupTranslation); + await this.CheckRegistrationStartup(translation, groupTranslation, guildId); } catch (NullReferenceException ex) { diff --git a/DisCatSharp.ApplicationCommands/Entities/ChoiceTranslator.cs b/DisCatSharp.ApplicationCommands/Entities/ChoiceTranslator.cs index faa879592b..14f99ad00f 100644 --- a/DisCatSharp.ApplicationCommands/Entities/ChoiceTranslator.cs +++ b/DisCatSharp.ApplicationCommands/Entities/ChoiceTranslator.cs @@ -21,9 +21,20 @@ internal sealed class ChoiceTranslator /// Gets the choice name translations. /// [JsonProperty("name_translations")] - internal Dictionary NameTranslationsDictionary { get; set; } + internal Dictionary? NameTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization NameTranslations - => new(this.NameTranslationsDictionary); + public DiscordApplicationCommandLocalization? NameTranslations + => this.NameTranslationsDictionary is not null ? new(this.NameTranslationsDictionary) : null; + + internal static ChoiceTranslator FromApplicationCommandChoice(DiscordApplicationCommandOptionChoice option) + { + var translator = new ChoiceTranslator + { + Name = option.Name, + NameTranslationsDictionary = option.RawNameLocalizations + }; + + return translator; + } } diff --git a/DisCatSharp.ApplicationCommands/Entities/CommandTranslator.cs b/DisCatSharp.ApplicationCommands/Entities/CommandTranslator.cs index 4093f63f72..93f73f0170 100644 --- a/DisCatSharp.ApplicationCommands/Entities/CommandTranslator.cs +++ b/DisCatSharp.ApplicationCommands/Entities/CommandTranslator.cs @@ -35,25 +35,25 @@ internal sealed class CommandTranslator /// Gets the command name translations. /// [JsonProperty("name_translations")] - internal Dictionary NameTranslationDictionary { get; set; } + internal Dictionary? NameTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization NameTranslations - => new(this.NameTranslationDictionary); + public DiscordApplicationCommandLocalization? NameTranslations + => this.NameTranslationsDictionary is not null ? new(this.NameTranslationsDictionary) : null; /// /// Gets the command description translations. /// [JsonProperty("description_translations")] - internal Dictionary DescriptionTranslationDictionary { get; set; } + internal Dictionary? DescriptionTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization DescriptionTranslations - => new(this.DescriptionTranslationDictionary); + public DiscordApplicationCommandLocalization? DescriptionTranslations + => this.DescriptionTranslationsDictionary is not null ? new(this.DescriptionTranslationsDictionary) : null; /// /// Gets the option translators, if applicable. /// [JsonProperty("options", NullValueHandling = NullValueHandling.Ignore)] - public List Options { get; set; } + public List? Options { get; set; } } diff --git a/DisCatSharp.ApplicationCommands/Entities/FakeApplicationCommandObjects.cs b/DisCatSharp.ApplicationCommands/Entities/FakeApplicationCommandObjects.cs index e6940dbb1f..41dd1d9488 100644 --- a/DisCatSharp.ApplicationCommands/Entities/FakeApplicationCommandObjects.cs +++ b/DisCatSharp.ApplicationCommands/Entities/FakeApplicationCommandObjects.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using DisCatSharp.Entities; using DisCatSharp.Enums; @@ -15,8 +16,8 @@ internal sealed class CommandGroupWithSubGroups : BaseCommand [JsonProperty("commands")] internal List Commands { get; set; } - internal CommandGroupWithSubGroups(string name, string description, List subGroups, List commands, ApplicationCommandType type) - : base(name, description, type) + internal CommandGroupWithSubGroups(string name, string description, List subGroups, List commands, ApplicationCommandType type, Dictionary? nameTranslations = null, Dictionary? descriptionTranslations = null) + : base(name, description, type, nameTranslations, descriptionTranslations) { this.SubGroups = subGroups; this.Commands = commands; @@ -28,8 +29,8 @@ internal sealed class CommandGroup : BaseCommand [JsonProperty("commands")] internal List Commands { get; set; } - internal CommandGroup(string name, string description, List commands, ApplicationCommandType? type = null) - : base(name, description, type) + internal CommandGroup(string name, string description, List commands, ApplicationCommandType? type = null, Dictionary? nameTranslations = null, Dictionary? descriptionTranslations = null) + : base(name, description, type, nameTranslations, descriptionTranslations) { this.Commands = commands; } @@ -38,12 +39,13 @@ internal CommandGroup(string name, string description, List commands, A internal sealed class Command : BaseCommand { [JsonProperty("options")] - internal List? Options { get; set; } + internal List? Options { get; set; } - internal Command(string name, string? description = null, List? options = null, ApplicationCommandType? type = null) - : base(name, description, type) + internal Command(string name, string? description = null, List? options = null, ApplicationCommandType? type = null, Dictionary? nameTranslations = null, Dictionary? descriptionTranslations = null) + : base(name, description, type, nameTranslations, descriptionTranslations) { - this.Options = options; + if (options is not null) + this.Options = options.Select(OptionTranslator.FromApplicationCommandOption).ToList(); } } @@ -52,16 +54,24 @@ internal class BaseCommand [JsonProperty("name")] internal string Name { get; set; } + [JsonProperty("name_translations")] + internal Dictionary? NameTranslations { get; set; } + [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] internal string? Description { get; set; } + [JsonProperty("description_translations", NullValueHandling = NullValueHandling.Ignore)] + internal Dictionary? DescriptionTranslations { get; set; } + [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] internal ApplicationCommandType? Type { get; set; } - internal BaseCommand(string name, string? description = null, ApplicationCommandType? type = null) + internal BaseCommand(string name, string? description = null, ApplicationCommandType? type = null, Dictionary? nameTranslations = null, Dictionary? descriptionTranslations = null) { this.Name = name; this.Type = type; this.Description = description; + this.NameTranslations = nameTranslations; + this.DescriptionTranslations = descriptionTranslations; } } diff --git a/DisCatSharp.ApplicationCommands/Entities/GroupTranslator.cs b/DisCatSharp.ApplicationCommands/Entities/GroupTranslator.cs index beaafa1934..de6b8a0fe5 100644 --- a/DisCatSharp.ApplicationCommands/Entities/GroupTranslator.cs +++ b/DisCatSharp.ApplicationCommands/Entities/GroupTranslator.cs @@ -35,21 +35,21 @@ internal sealed class GroupTranslator /// Gets the group name translations. /// [JsonProperty("name_translations")] - internal Dictionary NameTranslationsDictionary { get; set; } + internal Dictionary? NameTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization NameTranslations - => new(this.NameTranslationsDictionary); + public DiscordApplicationCommandLocalization? NameTranslations + => this.NameTranslationsDictionary is not null ? new(this.NameTranslationsDictionary) : null; /// /// Gets the group description translations. /// [JsonProperty("description_translations")] - internal Dictionary DescriptionTranslationsDictionary { get; set; } + internal Dictionary? DescriptionTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization DescriptionTranslations - => new(this.DescriptionTranslationsDictionary); + public DiscordApplicationCommandLocalization? DescriptionTranslations + => this.DescriptionTranslationsDictionary is not null ? new(this.DescriptionTranslationsDictionary) : null; /// /// Gets the sub group translators, if applicable. diff --git a/DisCatSharp.ApplicationCommands/Entities/OptionTranslator.cs b/DisCatSharp.ApplicationCommands/Entities/OptionTranslator.cs index 5380ed2050..0b786d0bc6 100644 --- a/DisCatSharp.ApplicationCommands/Entities/OptionTranslator.cs +++ b/DisCatSharp.ApplicationCommands/Entities/OptionTranslator.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using DisCatSharp.Entities; using DisCatSharp.Enums; @@ -28,31 +29,48 @@ internal sealed class OptionTranslator /// Gets the option type /// [JsonProperty("type")] - public ApplicationCommandOptionType? Type { get; set; } + public ApplicationCommandOptionType Type { get; set; } /// /// Gets the option name translations. /// [JsonProperty("name_translations")] - internal Dictionary NameTranslationsDictionary { get; set; } + internal Dictionary? NameTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization NameTranslations - => new(this.NameTranslationsDictionary); + public DiscordApplicationCommandLocalization? NameTranslations + => this.NameTranslationsDictionary is not null ? new(this.NameTranslationsDictionary) : null; /// /// Gets the option description translations. /// [JsonProperty("description_translations")] - internal Dictionary DescriptionTranslationsDictionary { get; set; } + internal Dictionary? DescriptionTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization DescriptionTranslations - => new(this.DescriptionTranslationsDictionary); + public DiscordApplicationCommandLocalization? DescriptionTranslations + => this.DescriptionTranslationsDictionary is not null ? new(this.DescriptionTranslationsDictionary) : null; /// /// Gets the choice translators, if applicable. /// [JsonProperty("choices", NullValueHandling = NullValueHandling.Ignore)] - public List Choices { get; set; } + public List? Choices { get; set; } + + internal static OptionTranslator FromApplicationCommandOption(DiscordApplicationCommandOption option) + { + var optionTranslator = new OptionTranslator + { + Name = option.Name, + Description = option.Description, + Type = option.Type, + NameTranslationsDictionary = option.RawNameLocalizations, + DescriptionTranslationsDictionary = option.RawDescriptionLocalizations + }; + + if (option.Choices is not null) + optionTranslator.Choices = option.Choices.Select(ChoiceTranslator.FromApplicationCommandChoice).ToList(); + + return optionTranslator; + } } diff --git a/DisCatSharp.ApplicationCommands/Entities/SubGroupTranslator.cs b/DisCatSharp.ApplicationCommands/Entities/SubGroupTranslator.cs index 48a108f0ea..70856841e0 100644 --- a/DisCatSharp.ApplicationCommands/Entities/SubGroupTranslator.cs +++ b/DisCatSharp.ApplicationCommands/Entities/SubGroupTranslator.cs @@ -27,21 +27,21 @@ internal sealed class SubGroupTranslator /// Gets the sub group name translations. /// [JsonProperty("name_translations")] - internal Dictionary NameTranslationsDictionary { get; set; } + internal Dictionary? NameTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization NameTranslations - => new(this.NameTranslationsDictionary); + public DiscordApplicationCommandLocalization? NameTranslations + => this.NameTranslationsDictionary is not null ? new(this.NameTranslationsDictionary) : null; /// /// Gets the sub group description translations. /// [JsonProperty("description_translations")] - internal Dictionary DescriptionTranslationsDictionary { get; set; } + internal Dictionary? DescriptionTranslationsDictionary { get; set; } [JsonIgnore] - public DiscordApplicationCommandLocalization DescriptionTranslations - => new(this.DescriptionTranslationsDictionary); + public DiscordApplicationCommandLocalization? DescriptionTranslations + => this.DescriptionTranslationsDictionary is not null ? new(this.DescriptionTranslationsDictionary) : null; /// /// Gets the command translators. diff --git a/DisCatSharp.Docs/articles/modules/application_commands/translations/reference.md b/DisCatSharp.Docs/articles/modules/application_commands/translations/reference.md index 91c08e74ed..3e3add5738 100644 --- a/DisCatSharp.Docs/articles/modules/application_commands/translations/reference.md +++ b/DisCatSharp.Docs/articles/modules/application_commands/translations/reference.md @@ -10,14 +10,14 @@ title: Translation Reference ## Command Object -| Key | Value | Description | -| ------------------------ | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | -| name | string | name of the application command | -| description? | string | description of the application command | -| type | int | [type](#application-command-type) of application command, used to map command types | -| name_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command name | -| description_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command description, only valid for slash commands | -| options | array of [Option Objects](#option-object) | array of option objects containing translations | +| Key | Value | Description | +| ------------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | +| name | string | name of the application command | +| description? | string | description of the application command | +| type | int | [type](#application-command-type) of application command, used to map command types, not valid for options | +| name_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command name | +| description_translations? | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command description, only valid for slash commands | +| options | array of [Option Objects](#option-object) | array of option objects containing translations | ### Application Command Type @@ -29,21 +29,22 @@ title: Translation Reference ## Command Group Object -| Key | Value | Description | -| ------------------------ | --------------------------------------------------------------- | ---------------------------------------------------------------------------------- | -| name | string | name of the application command group | -| description? | string | description of the application command group | -| name_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command group name | -| description_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command group description | -| commands | array of [Command Objects](#command-object) | array of command objects containing translations | -| groups | array of [Sub Command Group Objects](#sub-command-group-object) | array of sub command group objects containing translations | +| Key | Value | Description | +| ------------------------ | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | +| name | string | name of the application command group | +| description | string | description of the application command group | +| type | int | [type](#application-command-type) of application command, used to map command types, not valid for options | +| name_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command group name | +| description_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command group description | +| commands | array of [Command Objects](#command-object) | array of command objects containing translations | +| groups | array of [Sub Command Group Objects](#sub-command-group-object) | array of sub command group objects containing translations | ## Sub Command Group Object | Key | Value | Description | | ------------------------ | --------------------------------------------- | -------------------------------------------------------------------------------------- | | name | string | name of the application command sub group | -| description? | string | description of the application command group | +| description | string | description of the application command sub group | | name_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command sub group name | | description_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command sub group description | | commands | array of [Command Objects](#command-object) | array of command objects containing translations | @@ -53,7 +54,7 @@ title: Translation Reference | Key | Value | Description | | ------------------------ | ------------------------------------------------------- | ----------------------------------------------------------------------------------- | | name | string | name of the application command option | -| description? | string | description of the application command group | +| description | string | description of the application command group | | name_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command option name | | description_translations | array of [Translation KVPs](#translation-kvp) | array of translation key-value-pairs for the application command option description | | choices | array of [Option Choice Objects](#option-choice-object) | array of option choice objects containing translations | @@ -80,35 +81,37 @@ A translation object is a key-value-pair of `"locale": "value"`. ## Valid Locales -| Locale | Language | -| ------ | --------------------- | -| da | Danish | -| de | German | -| en-GB | English, UK | -| en-US | English, US | -| es-ES | Spanish | -| fr | French | -| hr | Croatian | -| it | Italian | -| lt | Lithuanian | -| hu | Hungarian | -| nl | Dutch | -| no | Norwegian | -| pl | Polish | -| pt-BR | Portuguese, Brazilian | -| ro | Romanian, Romania | -| fi | Finnish | -| sv-SE | Swedish | -| vi | Vietnamese | -| tr | Turkish | -| cs | Czech | -| el | Greek | -| bg | Bulgarian | -| ru | Russian | -| uk | Ukrainian | -| hi | Hindi | -| th | Thai | -| zh-CN | Chinese, China | -| ja | Japanese | -| zh-TW | Chinese, Taiwan | -| ko | Korean | +| Locale | Language | +| ------ | ---------------------- | +| id | Indonesian | +| da | Danish | +| de | German | +| en-GB | English, UK | +| en-US | English, US | +| es-ES | Spanish | +| es-419 | Spanish, Latin America | +| fr | French | +| hr | Croatian | +| it | Italian | +| lt | Lithuanian | +| hu | Hungarian | +| nl | Dutch | +| no | Norwegian | +| pl | Polish | +| pt-BR | Portuguese, Brazilian | +| ro | Romanian, Romania | +| fi | Finnish | +| sv-SE | Swedish | +| vi | Vietnamese | +| tr | Turkish | +| cs | Czech | +| el | Greek | +| bg | Bulgarian | +| ru | Russian | +| uk | Ukrainian | +| hi | Hindi | +| th | Thai | +| zh-CN | Chinese, China | +| ja | Japanese | +| zh-TW | Chinese, Taiwan | +| ko | Korean | diff --git a/DisCatSharp.Docs/articles/modules/application_commands/translations/using.md b/DisCatSharp.Docs/articles/modules/application_commands/translations/using.md index 08eae63f48..0c7bbfd1f6 100644 --- a/DisCatSharp.Docs/articles/modules/application_commands/translations/using.md +++ b/DisCatSharp.Docs/articles/modules/application_commands/translations/using.md @@ -79,6 +79,7 @@ A correct translation json for english and german would look like that: { "name": "my_command", "description": "This is description of the command group.", + "type": 1, "name_translations": { "en-US": "my_command", "de": "mein_befehl" @@ -87,11 +88,11 @@ A correct translation json for english and german would look like that: "en-US": "This is description of the command group.", "de": "Das ist die description der Befehl Gruppe." }, + "groups": [], "commands": [ { "name": "first", "description": "First", - "type": 1, // Type 1 for slash command "name_translations": { "en-US": "first", "de": "erste" @@ -104,7 +105,6 @@ A correct translation json for english and german would look like that: { "name": "second", "description": "Second", - "type": 1, // Type 1 for slash command "name_translations": { "en-US": "second", "de": "zweite" @@ -117,6 +117,7 @@ A correct translation json for english and german would look like that: { "name": "value", "description": "Some string value.", + "type": 3, "name_translations": { "en-US": "value", "de": "wert" @@ -182,7 +183,6 @@ A correct json for this example would look like that: }, { "name": "My Command", - "description": null, "type": 2, // Type 2 for user context menu command "name_translations": { "en-US": "My Command", diff --git a/DisCatSharp/Entities/Application/DiscordApplicationCommandLocalization.cs b/DisCatSharp/Entities/Application/DiscordApplicationCommandLocalization.cs index 3475fbba84..d5a5576724 100644 --- a/DisCatSharp/Entities/Application/DiscordApplicationCommandLocalization.cs +++ b/DisCatSharp/Entities/Application/DiscordApplicationCommandLocalization.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace DisCatSharp.Entities; @@ -16,7 +17,7 @@ public sealed class DiscordApplicationCommandLocalization /// /// Gets valid [locales](xref:modules_application_commands_translations_reference#valid-locales) for Discord. /// - internal List ValidLocales = ["ru", "fi", "hr", "de", "hu", "sv-SE", "cs", "fr", "it", "en-GB", "pt-BR", "ja", "tr", "en-US", "es-ES", "uk", "hi", "th", "el", "no", "ro", "ko", "zh-TW", "vi", "zh-CN", "pl", "bg", "da", "nl", "lt"]; + internal readonly List ValidLocales = ["ru", "fi", "hr", "de", "hu", "sv-SE", "cs", "fr", "it", "en-GB", "pt-BR", "ja", "tr", "en-US", "es-ES", "uk", "hi", "th", "el", "no", "ro", "ko", "zh-TW", "vi", "zh-CN", "pl", "bg", "da", "nl", "lt", "id", "es-419"]; /// /// Adds a localization. @@ -49,13 +50,14 @@ public DiscordApplicationCommandLocalization() /// Initializes a new instance of . /// /// Localizations. - public DiscordApplicationCommandLocalization(Dictionary localizations) + public DiscordApplicationCommandLocalization(Dictionary? localizations) { - if (localizations != null) - foreach (var locale in localizations.Keys) - if (!this.Validate(locale)) - throw new NotSupportedException($"The provided locale \"{locale}\" is not valid for Discord.\n" + - $"Valid locales: {string.Join(", ", this.ValidLocales)}"); + if (localizations == null) + return; + + foreach (var locale in localizations.Keys.Where(locale => !this.Validate(locale))) + throw new NotSupportedException($"The provided locale \"{locale}\" is not valid for Discord.\n" + + $"Valid locales: {string.Join(", ", this.ValidLocales)}"); this.Localizations = localizations; } diff --git a/DisCatSharp/Entities/Application/DiscordApplicationCommandOptionChoice.cs b/DisCatSharp/Entities/Application/DiscordApplicationCommandOptionChoice.cs index 3c5f41e5a0..852e7ff427 100644 --- a/DisCatSharp/Entities/Application/DiscordApplicationCommandOptionChoice.cs +++ b/DisCatSharp/Entities/Application/DiscordApplicationCommandOptionChoice.cs @@ -20,7 +20,7 @@ public sealed class DiscordApplicationCommandOptionChoice /// Sets the name localizations. /// [JsonProperty("name_localizations", NullValueHandling = NullValueHandling.Ignore)] - internal Dictionary RawNameLocalizations { get; set; } + internal Dictionary? RawNameLocalizations { get; set; } /// /// Gets the name localizations. @@ -43,7 +43,7 @@ public DiscordApplicationCommandLocalization NameLocalizations /// The localizations of the parameter choice name. public DiscordApplicationCommandOptionChoice(string name, object value, DiscordApplicationCommandLocalization nameLocalizations = null) { - if (!(value is string || value is long || value is int || value is double)) + if (value is not (string or long or int or double)) throw new InvalidOperationException($"Only {typeof(string)}, {typeof(long)}, {typeof(double)} or {typeof(int)} types may be passed to a command option choice."); if (name.Length > 100) diff --git a/DisCatSharp/Entities/Interaction/DiscordInteraction.cs b/DisCatSharp/Entities/Interaction/DiscordInteraction.cs index 1cb3822562..e5d3c1fb18 100644 --- a/DisCatSharp/Entities/Interaction/DiscordInteraction.cs +++ b/DisCatSharp/Entities/Interaction/DiscordInteraction.cs @@ -134,6 +134,12 @@ public DiscordChannel Channel [JsonProperty("authorizing_integration_owners", NullValueHandling = NullValueHandling.Ignore)] public AuthorizingIntegrationOwners? AuthorizingIntegrationOwners { get; internal set; } + /// + /// Gets the interaction's calling context. + /// + [JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)] + public ApplicationCommandContexts Context { get; internal set; } + /// /// Creates a response to this interaction. /// diff --git a/RELEASENOTES.md b/RELEASENOTES.md index b8f8f83e91..e0e77f8bae 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,105 +1,66 @@ DisCatSharp Release Notes Important fix: - - Apparently the built-in c# method for building uris broke. The gateway uri included never the gateway version, encoding and compression. This is fixed now! - - Breaking changes: - - Dropped support for .NET 6 - - Removed previously deprecated fields and methods + - Applying the proxy configuration to the sharded client startup (it was missing) Notable Changes - - Full support for onboarding - - Custom status support - - Full support for Application Subscriptions aka. Premium Apps - - DiscordOAuth2Client: Allows bots to request and use access tokens for the Discord API. - - Support for default select menu values (THANKS MAISY FOR ADDING IT TO DISCORD) - - DisCatSharp can now check for new releases on startup. Including support for extensions + - Added support for building and using cooldowns DisCatSharp.Attributes Release Notes - Breaking changes: - - Dropped support for .NET 6 - - Removed previously deprecated fields and methods - - Added new required feature enums to notate feature usage + None DisCatSharp.ApplicationCommands Release Notes - Important fix: - - Changed the timing when and how commands are registered to fix some issues - Breaking changes: - - Dropped support for .NET 6 - - Removed previously deprecated fields and methods + - Fixed problems with translation generation and usage - Contains a rework for command registration (Kinda wacky tho with translation-enabled commands) - Fixed a major issue with application commands. Upgrade mandatory + Notable changes + - Added cooldowns for application commands DisCatSharp.CommandsNext Release Notes - Breaking changes: - - Dropped support for .NET 6 - - Removed previously deprecated fields and methods + Notable changes: + - Fixed cooldowns DisCatSharp.Interactivity Release Notes - Breaking changes: - - Dropped support for .NET 6 - - Removed previously deprecated fields and methods - - Contains important bug fixes for interactions and pagination + None DisCatSharp.Common Release Notes - Breaking changes: - - Dropped support for .NET 6 - - Removed previously deprecated fields and methods - - We added all of our regexes to the Common package as GenereicRegexes + None DisCatSharp.Lavalink Release Notes - Breaking changes: - - Dropped support for .NET 6 - - Removed previously deprecated fields and methods - - Lavalink got a complete rework for V4. - - Visit the documentation for more information: https://docs.dcs.aitsys.dev/articles/modules/audio/lavalink_v4/intro + None DisCatSharp.VoiceNext Release Notes - Breaking changes: - - Dropped support for .NET 6 - - Removed previously deprecated fields and methods - Will be deprecated soon and replaced by DisCatSharp.Voice DisCatSharp.Experimental Release Notes - Breaking changes: - - Dropped support for .NET 6 + None DisCatSharp.Configuration Release Notes - Breaking changes: - - Dropped support for .NET 6 + None DisCatSharp.Hosting Release Notes - Breaking changes: - - Dropped support for .NET 6 + None DisCatSharp.Hosting.DependencyInjection Release Notes - Breaking changes: - - Dropped support for .NET 6 - + None