From 453fd45ef7be41c4557a4d1bb61b4c5d406c321a Mon Sep 17 00:00:00 2001 From: LTS20050703 <87189679+lts20050703@users.noreply.github.com> Date: Fri, 13 May 2022 20:25:57 +0700 Subject: [PATCH] localization updates (#2206) * localization updates Upstream: https://github.com/discord/discord-api-docs/commit/2f854d3fd675a9953d1bb8d6858a03c8a9642337 Types: DiscordApplicationCommmand and DiscordApplicationCommandOption: Update documentation Types: DiscordActivityButton: Add documentation link Helper: upsertApplicationCommand: All fields are optional, but any fields provided will entirely overwrite the existing values of those fields. * revert unrelated changes * update SLASH_COMMANDS_NAME_REGEX * createApplicationCommand options: AtLeastOne instead of Partial Co-authored-by: ITOH Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> --- helpers/interactions/commands/createApplicationCommand.ts | 5 +++-- helpers/interactions/commands/upsertApplicationCommand.ts | 5 ++--- types/discord.ts | 4 ++-- util/constants.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/helpers/interactions/commands/createApplicationCommand.ts b/helpers/interactions/commands/createApplicationCommand.ts index 031b5725e..a08eaec28 100644 --- a/helpers/interactions/commands/createApplicationCommand.ts +++ b/helpers/interactions/commands/createApplicationCommand.ts @@ -1,6 +1,7 @@ import type { Bot } from "../../../bot.ts"; import { ApplicationCommandOption, ApplicationCommandTypes, Localization } from "../../../mod.ts"; import { DiscordApplicationCommand, DiscordApplicationCommandOption } from "../../../types/discord.ts"; +import { AtLeastOne } from "../../../types/shared.ts"; /** * There are two kinds of Application Commands: global commands and guild commands. Global commands are available for every guild that adds your app; guild commands are specific to the guild you specify when making them. Command names are unique per application within each scope (global and guild). That means: @@ -89,7 +90,7 @@ export interface CreateContextApplicationCommand { } export function isContextApplicationCommand( - cmd: CreateContextApplicationCommand | CreateApplicationCommand, -): cmd is CreateContextApplicationCommand { + cmd: AtLeastOne | AtLeastOne, +): cmd is AtLeastOne { return cmd.type === ApplicationCommandTypes.Message || cmd.type === ApplicationCommandTypes.User; } diff --git a/helpers/interactions/commands/upsertApplicationCommand.ts b/helpers/interactions/commands/upsertApplicationCommand.ts index 556f89056..c433448d3 100644 --- a/helpers/interactions/commands/upsertApplicationCommand.ts +++ b/helpers/interactions/commands/upsertApplicationCommand.ts @@ -6,8 +6,7 @@ import { makeOptionsForCommand, } from "./createApplicationCommand.ts"; import { DiscordApplicationCommand } from "../../../types/discord.ts"; -import { ApplicationCommandOption } from "../../../transformers/applicationCommandOption.ts"; -import { ApplicationCommandTypes } from "../../../types/shared.ts"; +import { AtLeastOne } from "../../../types/shared.ts"; /** * Edit an existing application command. If this command did not exist, it will create it. @@ -15,7 +14,7 @@ import { ApplicationCommandTypes } from "../../../types/shared.ts"; export async function upsertApplicationCommand( bot: Bot, commandId: bigint, - options: CreateApplicationCommand | CreateContextApplicationCommand, + options: AtLeastOne | AtLeastOne, guildId?: bigint, ) { const result = await bot.rest.runMethod( diff --git a/types/discord.ts b/types/discord.ts index c47ab31bf..a444be3f1 100644 --- a/types/discord.ts +++ b/types/discord.ts @@ -1649,7 +1649,7 @@ export interface DiscordApplicationCommand { application_id: string; /** Guild id of the command, if not global */ guild_id?: string; - /** 1-32 character name matching */ + /** `ApplicationCommandTypes.ChatInput` command names must match the following regex `^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$` with the unicode flag set. If there is a lowercase variant of any letters used, you must use those. Characters with no lowercase variants and/or uncased letters are still allowed. `ApplicationCommandTypes.User` and `ApplicationCommandTypes.Message` commands may be mixed case and can include spaces. */ name: string; /** Localization object for the `name` field. Values follow the same restrictions as `name` */ name_localizations?: Localization | null; @@ -1669,7 +1669,7 @@ export interface DiscordApplicationCommand { export interface DiscordApplicationCommandOption { /** Value of Application Command Option Type */ type: ApplicationCommandOptionTypes; - /** 1-32 character name matching lowercase `^[\w-]{1,32}$` */ + /** Command option name must match the following regex `^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$` with the unicode flag set. If there is a lowercase variant of any letters used, you must use those. Characters with no lowercase variants and/or uncased letters are still allowed. */ name: string; /** Localization object for the `name` field. Values follow the same restrictions as `name` */ name_localizations?: Localization | null; diff --git a/util/constants.ts b/util/constants.ts index 1d6c5660b..63aea20cf 100644 --- a/util/constants.ts +++ b/util/constants.ts @@ -174,7 +174,7 @@ export const endpoints = { NITRO_STICKER_PACKS: () => `${baseEndpoints.BASE_URL}/sticker-packs`, }; -export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/; +export const SLASH_COMMANDS_NAME_REGEX = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u; export const CONTEXT_MENU_COMMANDS_NAME_REGEX = /^[\w-\s]{1,32}$/; export const CHANNEL_MENTION_REGEX = /<#[0-9]+>/g; export const DISCORD_SNOWFLAKE_REGEX = /^(?\d{17,19})$/;