Interactions Command Localization (#2395)
* Request headers (#2394) * add support for per-request headers * remove unnecessary usings * Revert "remove unnecessary usings" This reverts commit 8d674fe4faf985b117f143fae3877a1698170ad2. * remove nullable strings from RequestOptions * Add Localization Support to Interaction Service (#2211) * add json and resx localization managers * add utils class for getting command paths * update json regex to make langage code optional * remove IServiceProvider from ILocalizationManager method params * replace the command path method in command map * add localization fields to rest and websocket application command entity implementations * move deconstruct extensions method to extensions folder * add withLocalizations parameter to rest methods * fix build error * add rest conversions to interaction service * add localization to the rest methods * add inline docs * fix implementation bugs * add missing inline docs * inline docs correction (Name/Description Localized properties) * add choice localization * fix conflicts * fix conflicts * add missing command props fields to ToApplicationCommandProps methods * add locale parameter to Get*ApplicationCommandsAsync methods for fetching localized command names/descriptions * Apply suggestions from code review Co-authored-by: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> * Update src/Discord.Net.Core/Entities/Guilds/IGuild.cs Co-authored-by: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> * add inline docs to LocalizationTarget * fix upstream merge errors * fix command parsing for context command names with space char * fix command parsing for context command names with space char * fix failed to generate buket id * fix get guild commands endpoint * update rexs localization manager to use single-file pattern * Upstream Merge Localization Branch (#2434) * fix ci/cd error (#2428) * Fix role icon & emoji assignment. (#2416) * Fix IGuild.GetBansAsync() (#2424) fix the problem of not being able to get more than 1000 bans * [DOCS] Add a note about `DontAutoRegisterAttribute` (#2430) * add a note about `DontAutoRegisterAttribute` * Remove "to to" and add punctuation Co-authored-by: MrCakeSlayer <13650699+MrCakeSlayer@users.noreply.github.com> * fix: Missing Fact attribute in ColorTests (#2425) * feat: Embed comparison (#2347) * Fix broken code snippet in dependency injection docs (#2420) * Fixed markdown formatting to show code snippet * Fixed constructor injection code snippet pointer * Added support for lottie stickers (#2359) Co-authored-by: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Co-authored-by: BokuNoPasya <49203428+1NieR@users.noreply.github.com> Co-authored-by: Misha133 <61027276+Misha-133@users.noreply.github.com> Co-authored-by: MrCakeSlayer <13650699+MrCakeSlayer@users.noreply.github.com> Co-authored-by: Ge <gehongyan1996@126.com> Co-authored-by: Charlie U <52503242+cpurules@users.noreply.github.com> Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com> * remove unnecassary fields from ResxLocalizationManager * update int framework guides * remove space character tokenization from ResxLocalizationManager Co-authored-by: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Co-authored-by: BokuNoPasya <49203428+1NieR@users.noreply.github.com> Co-authored-by: Misha133 <61027276+Misha-133@users.noreply.github.com> Co-authored-by: MrCakeSlayer <13650699+MrCakeSlayer@users.noreply.github.com> Co-authored-by: Ge <gehongyan1996@126.com> Co-authored-by: Charlie U <52503242+cpurules@users.noreply.github.com> Co-authored-by: Kuba_Z2 <77853483+KubaZ2@users.noreply.github.com>
This commit is contained in:
@@ -450,14 +450,16 @@ namespace Discord.WebSocket
|
||||
/// <summary>
|
||||
/// Gets a collection of all global commands.
|
||||
/// </summary>
|
||||
/// <param name="withLocalizations">Whether to include full localization dictionaries in the returned objects, instead of the name localized and description localized fields.</param>
|
||||
/// <param name="locale">The target locale of the localized name and description fields. Sets <c>X-Discord-Locale</c> header, which takes precedence over <c>Accept-Language</c>.</param>
|
||||
/// <param name="options">The options to be used when sending the request.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous get operation. The task result contains a read-only collection of global
|
||||
/// application commands.
|
||||
/// </returns>
|
||||
public async Task<IReadOnlyCollection<SocketApplicationCommand>> GetGlobalApplicationCommandsAsync(RequestOptions options = null)
|
||||
public async Task<IReadOnlyCollection<SocketApplicationCommand>> GetGlobalApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null)
|
||||
{
|
||||
var commands = (await ApiClient.GetGlobalApplicationCommandsAsync(options)).Select(x => SocketApplicationCommand.Create(this, x));
|
||||
var commands = (await ApiClient.GetGlobalApplicationCommandsAsync(withLocalizations, locale, options)).Select(x => SocketApplicationCommand.Create(this, x));
|
||||
|
||||
foreach(var command in commands)
|
||||
{
|
||||
@@ -3236,8 +3238,8 @@ namespace Discord.WebSocket
|
||||
async Task<IApplicationCommand> IDiscordClient.GetGlobalApplicationCommandAsync(ulong id, RequestOptions options)
|
||||
=> await GetGlobalApplicationCommandAsync(id, options);
|
||||
/// <inheritdoc />
|
||||
async Task<IReadOnlyCollection<IApplicationCommand>> IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions options)
|
||||
=> await GetGlobalApplicationCommandsAsync(options);
|
||||
async Task<IReadOnlyCollection<IApplicationCommand>> IDiscordClient.GetGlobalApplicationCommandsAsync(bool withLocalizations, string locale, RequestOptions options)
|
||||
=> await GetGlobalApplicationCommandsAsync(withLocalizations, locale, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task IDiscordClient.StartAsync()
|
||||
|
||||
@@ -874,14 +874,17 @@ namespace Discord.WebSocket
|
||||
/// <summary>
|
||||
/// Gets a collection of slash commands created by the current user in this guild.
|
||||
/// </summary>
|
||||
/// <param name="withLocalizations">Whether to include full localization dictionaries in the returned objects, instead of the name localized and description localized fields.</param>
|
||||
/// <param name="locale">The target locale of the localized name and description fields. Sets <c>X-Discord-Locale</c> header, which takes precedence over <c>Accept-Language</c>.</param>
|
||||
/// <param name="options">The options to be used when sending the request.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous get operation. The task result contains a read-only collection of
|
||||
/// slash commands created by the current user.
|
||||
/// </returns>
|
||||
public async Task<IReadOnlyCollection<SocketApplicationCommand>> GetApplicationCommandsAsync(RequestOptions options = null)
|
||||
public async Task<IReadOnlyCollection<SocketApplicationCommand>> GetApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null)
|
||||
{
|
||||
var commands = (await Discord.ApiClient.GetGuildApplicationCommandsAsync(Id, options)).Select(x => SocketApplicationCommand.Create(Discord, x, Id));
|
||||
var commands = (await Discord.ApiClient.GetGuildApplicationCommandsAsync(Id, withLocalizations, locale, options))
|
||||
.Select(x => SocketApplicationCommand.Create(Discord, x, Id));
|
||||
|
||||
foreach (var command in commands)
|
||||
{
|
||||
@@ -1977,8 +1980,8 @@ namespace Discord.WebSocket
|
||||
async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options)
|
||||
=> await GetWebhooksAsync(options).ConfigureAwait(false);
|
||||
/// <inheritdoc />
|
||||
async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.GetApplicationCommandsAsync (RequestOptions options)
|
||||
=> await GetApplicationCommandsAsync(options).ConfigureAwait(false);
|
||||
async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.GetApplicationCommandsAsync (bool withLocalizations, string locale, RequestOptions options)
|
||||
=> await GetApplicationCommandsAsync(withLocalizations, locale, options).ConfigureAwait(false);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Image image, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, description, tags, image, options);
|
||||
|
||||
@@ -50,6 +50,32 @@ namespace Discord.WebSocket
|
||||
/// </remarks>
|
||||
public IReadOnlyCollection<SocketApplicationCommandOption> Options { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localization dictionary for the name field of this command.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, string> NameLocalizations { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localization dictionary for the description field of this command.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, string> DescriptionLocalizations { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized name of this command.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only returned when the `withLocalizations` query parameter is set to <see langword="false"/> when requesting the command.
|
||||
/// </remarks>
|
||||
public string NameLocalized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized description of this command.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only returned when the `withLocalizations` query parameter is set to <see langword="false"/> when requesting the command.
|
||||
/// </remarks>
|
||||
public string DescriptionLocalized { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedAt
|
||||
=> SnowflakeUtils.FromSnowflake(Id);
|
||||
@@ -93,6 +119,15 @@ namespace Discord.WebSocket
|
||||
? model.Options.Value.Select(SocketApplicationCommandOption.Create).ToImmutableArray()
|
||||
: ImmutableArray.Create<SocketApplicationCommandOption>();
|
||||
|
||||
NameLocalizations = model.NameLocalizations.GetValueOrDefault(null)?.ToImmutableDictionary() ??
|
||||
ImmutableDictionary<string, string>.Empty;
|
||||
|
||||
DescriptionLocalizations = model.DescriptionLocalizations.GetValueOrDefault(null)?.ToImmutableDictionary() ??
|
||||
ImmutableDictionary<string, string>.Empty;
|
||||
|
||||
NameLocalized = model.NameLocalized.GetValueOrDefault();
|
||||
DescriptionLocalized = model.DescriptionLocalized.GetValueOrDefault();
|
||||
|
||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
||||
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using Model = Discord.API.ApplicationCommandOptionChoice;
|
||||
|
||||
namespace Discord.WebSocket
|
||||
@@ -13,6 +15,19 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc/>
|
||||
public object Value { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localization dictionary for the name field of this command option choice.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, string> NameLocalizations { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized name of this command option choice.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only returned when the `withLocalizations` query parameter is set to <see langword="false"/> when requesting the command.
|
||||
/// </remarks>
|
||||
public string NameLocalized { get; private set; }
|
||||
|
||||
internal SocketApplicationCommandChoice() { }
|
||||
internal static SocketApplicationCommandChoice Create(Model model)
|
||||
{
|
||||
@@ -24,6 +39,8 @@ namespace Discord.WebSocket
|
||||
{
|
||||
Name = model.Name;
|
||||
Value = model.Value;
|
||||
NameLocalizations = model.NameLocalizations.GetValueOrDefault(null)?.ToImmutableDictionary();
|
||||
NameLocalized = model.NameLocalized.GetValueOrDefault(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,32 @@ namespace Discord.WebSocket
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<ChannelType> ChannelTypes { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localization dictionary for the name field of this command option.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, string> NameLocalizations { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localization dictionary for the description field of this command option.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, string> DescriptionLocalizations { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized name of this command option.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only returned when the `withLocalizations` query parameter is set to <see langword="false"/> when requesting the command.
|
||||
/// </remarks>
|
||||
public string NameLocalized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the localized description of this command option.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Only returned when the `withLocalizations` query parameter is set to <see langword="false"/> when requesting the command.
|
||||
/// </remarks>
|
||||
public string DescriptionLocalized { get; private set; }
|
||||
|
||||
internal SocketApplicationCommandOption() { }
|
||||
internal static SocketApplicationCommandOption Create(Model model)
|
||||
{
|
||||
@@ -92,6 +118,15 @@ namespace Discord.WebSocket
|
||||
ChannelTypes = model.ChannelTypes.IsSpecified
|
||||
? model.ChannelTypes.Value.ToImmutableArray()
|
||||
: ImmutableArray.Create<ChannelType>();
|
||||
|
||||
NameLocalizations = model.NameLocalizations.GetValueOrDefault(null)?.ToImmutableDictionary() ??
|
||||
ImmutableDictionary<string, string>.Empty;
|
||||
|
||||
DescriptionLocalizations = model.DescriptionLocalizations.GetValueOrDefault(null)?.ToImmutableDictionary() ??
|
||||
ImmutableDictionary<string, string>.Empty;
|
||||
|
||||
NameLocalized = model.NameLocalized.GetValueOrDefault();
|
||||
DescriptionLocalized = model.DescriptionLocalized.GetValueOrDefault();
|
||||
}
|
||||
|
||||
IReadOnlyCollection<IApplicationCommandOptionChoice> IApplicationCommandOption.Choices => Choices;
|
||||
|
||||
Reference in New Issue
Block a user