From 21d378965d17147bf2397984b0a39a379aebb6ac Mon Sep 17 00:00:00 2001 From: paring Date: Wed, 23 Aug 2023 14:14:04 +0900 Subject: [PATCH] fix: migrate to djs 14.13.0 --- package.json | 4 +- pnpm-lock.yaml | 107 ++++++++++-------- .../ApplicationCommandExtension.ts | 64 +++++++---- src/core/components/decoratorCreator.ts | 2 + 4 files changed, 106 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index b71c952..d345f37 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@typescript-eslint/eslint-plugin": "^6.4.1", "@typescript-eslint/parser": "^6.4.1", "all-contributors-cli": "6.26.1", + "discord-api-types": "^0.37.54", "discord.js": "14.13.0", "dotenv": "16.3.1", "eslint": "^8.47.0", @@ -25,7 +26,8 @@ "tslog": "^4.9.1", "tsup": "7.2.0", "typedoc": "^0.24.8", - "typescript": "^4.7.4" + "typescript": "^5.1.6", + "utility-types": "^3.10.0" }, "dependencies": { "@types/node": "^20.5.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a7f1567..6b9a896 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,7 +20,7 @@ dependencies: devDependencies: '@discordjs/ts-docgen': specifier: ^0.4.1 - version: 0.4.1(typescript@4.7.4) + version: 0.4.1(typescript@5.1.6) '@swc/core': specifier: 1.3.78 version: 1.3.78 @@ -29,13 +29,16 @@ devDependencies: version: 4.14.197 '@typescript-eslint/eslint-plugin': specifier: ^6.4.1 - version: 6.4.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0)(typescript@4.7.4) + version: 6.4.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0)(typescript@5.1.6) '@typescript-eslint/parser': specifier: ^6.4.1 - version: 6.4.1(eslint@8.47.0)(typescript@4.7.4) + version: 6.4.1(eslint@8.47.0)(typescript@5.1.6) all-contributors-cli: specifier: 6.26.1 version: 6.26.1 + discord-api-types: + specifier: ^0.37.54 + version: 0.37.54 discord.js: specifier: 14.13.0 version: 14.13.0 @@ -62,19 +65,22 @@ devDependencies: version: 21.0.9 ts-node: specifier: 10.9.1 - version: 10.9.1(@swc/core@1.3.78)(@types/node@20.5.3)(typescript@4.7.4) + version: 10.9.1(@swc/core@1.3.78)(@types/node@20.5.3)(typescript@5.1.6) tslog: specifier: ^4.9.1 version: 4.9.1 tsup: specifier: 7.2.0 - version: 7.2.0(@swc/core@1.3.78)(ts-node@10.9.1)(typescript@4.7.4) + version: 7.2.0(@swc/core@1.3.78)(ts-node@10.9.1)(typescript@5.1.6) typedoc: specifier: ^0.24.8 - version: 0.24.8(typescript@4.7.4) + version: 0.24.8(typescript@5.1.6) typescript: - specifier: ^4.7.4 - version: 4.7.4 + specifier: ^5.1.6 + version: 5.1.6 + utility-types: + specifier: ^3.10.0 + version: 3.10.0 packages: @@ -166,12 +172,12 @@ packages: undici: 5.22.1 dev: true - /@discordjs/ts-docgen@0.4.1(typescript@4.7.4): + /@discordjs/ts-docgen@0.4.1(typescript@5.1.6): resolution: {integrity: sha512-T+GMJaWvISrEi3Rjg2Tfn1EZeido+SEBv3+393uFLK71koJvwlexAwjzOc0yKz6uanK4mUQyCp35vOIvWsQ1IQ==} engines: {node: '>=16.0.0', npm: '>=7.0.0'} dependencies: js-yaml: 4.1.0 - typedoc: 0.22.18(typescript@4.7.4) + typedoc: 0.22.18(typescript@5.1.6) transitivePeerDependencies: - typescript dev: true @@ -935,7 +941,7 @@ packages: '@types/node': 20.5.3 dev: true - /@typescript-eslint/eslint-plugin@6.4.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0)(typescript@4.7.4): + /@typescript-eslint/eslint-plugin@6.4.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0)(typescript@5.1.6): resolution: {integrity: sha512-3F5PtBzUW0dYlq77Lcqo13fv+58KDwUib3BddilE8ajPJT+faGgxmI9Sw+I8ZS22BYwoir9ZhNXcLi+S+I2bkw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -947,10 +953,10 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.7.0 - '@typescript-eslint/parser': 6.4.1(eslint@8.47.0)(typescript@4.7.4) + '@typescript-eslint/parser': 6.4.1(eslint@8.47.0)(typescript@5.1.6) '@typescript-eslint/scope-manager': 6.4.1 - '@typescript-eslint/type-utils': 6.4.1(eslint@8.47.0)(typescript@4.7.4) - '@typescript-eslint/utils': 6.4.1(eslint@8.47.0)(typescript@4.7.4) + '@typescript-eslint/type-utils': 6.4.1(eslint@8.47.0)(typescript@5.1.6) + '@typescript-eslint/utils': 6.4.1(eslint@8.47.0)(typescript@5.1.6) '@typescript-eslint/visitor-keys': 6.4.1 debug: 4.3.4 eslint: 8.47.0 @@ -958,13 +964,13 @@ packages: ignore: 5.2.4 natural-compare: 1.4.0 semver: 7.5.4 - ts-api-utils: 1.0.2(typescript@4.7.4) - typescript: 4.7.4 + ts-api-utils: 1.0.2(typescript@5.1.6) + typescript: 5.1.6 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/parser@6.4.1(eslint@8.47.0)(typescript@4.7.4): + /@typescript-eslint/parser@6.4.1(eslint@8.47.0)(typescript@5.1.6): resolution: {integrity: sha512-610G6KHymg9V7EqOaNBMtD1GgpAmGROsmfHJPXNLCU9bfIuLrkdOygltK784F6Crboyd5tBFayPB7Sf0McrQwg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -976,11 +982,11 @@ packages: dependencies: '@typescript-eslint/scope-manager': 6.4.1 '@typescript-eslint/types': 6.4.1 - '@typescript-eslint/typescript-estree': 6.4.1(typescript@4.7.4) + '@typescript-eslint/typescript-estree': 6.4.1(typescript@5.1.6) '@typescript-eslint/visitor-keys': 6.4.1 debug: 4.3.4 eslint: 8.47.0 - typescript: 4.7.4 + typescript: 5.1.6 transitivePeerDependencies: - supports-color dev: true @@ -993,7 +999,7 @@ packages: '@typescript-eslint/visitor-keys': 6.4.1 dev: true - /@typescript-eslint/type-utils@6.4.1(eslint@8.47.0)(typescript@4.7.4): + /@typescript-eslint/type-utils@6.4.1(eslint@8.47.0)(typescript@5.1.6): resolution: {integrity: sha512-7ON8M8NXh73SGZ5XvIqWHjgX2f+vvaOarNliGhjrJnv1vdjG0LVIz+ToYfPirOoBi56jxAKLfsLm40+RvxVVXA==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -1003,12 +1009,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 6.4.1(typescript@4.7.4) - '@typescript-eslint/utils': 6.4.1(eslint@8.47.0)(typescript@4.7.4) + '@typescript-eslint/typescript-estree': 6.4.1(typescript@5.1.6) + '@typescript-eslint/utils': 6.4.1(eslint@8.47.0)(typescript@5.1.6) debug: 4.3.4 eslint: 8.47.0 - ts-api-utils: 1.0.2(typescript@4.7.4) - typescript: 4.7.4 + ts-api-utils: 1.0.2(typescript@5.1.6) + typescript: 5.1.6 transitivePeerDependencies: - supports-color dev: true @@ -1018,7 +1024,7 @@ packages: engines: {node: ^16.0.0 || >=18.0.0} dev: true - /@typescript-eslint/typescript-estree@6.4.1(typescript@4.7.4): + /@typescript-eslint/typescript-estree@6.4.1(typescript@5.1.6): resolution: {integrity: sha512-xF6Y7SatVE/OyV93h1xGgfOkHr2iXuo8ip0gbfzaKeGGuKiAnzS+HtVhSPx8Www243bwlW8IF7X0/B62SzFftg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -1033,13 +1039,13 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.5.4 - ts-api-utils: 1.0.2(typescript@4.7.4) - typescript: 4.7.4 + ts-api-utils: 1.0.2(typescript@5.1.6) + typescript: 5.1.6 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils@6.4.1(eslint@8.47.0)(typescript@4.7.4): + /@typescript-eslint/utils@6.4.1(eslint@8.47.0)(typescript@5.1.6): resolution: {integrity: sha512-F/6r2RieNeorU0zhqZNv89s9bDZSovv3bZQpUNOmmQK1L80/cV4KEu95YUJWi75u5PhboFoKUJBnZ4FQcoqhDw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -1050,7 +1056,7 @@ packages: '@types/semver': 7.5.0 '@typescript-eslint/scope-manager': 6.4.1 '@typescript-eslint/types': 6.4.1 - '@typescript-eslint/typescript-estree': 6.4.1(typescript@4.7.4) + '@typescript-eslint/typescript-estree': 6.4.1(typescript@5.1.6) eslint: 8.47.0 semver: 7.5.4 transitivePeerDependencies: @@ -1140,7 +1146,7 @@ packages: pify: 5.0.0 yargs: 15.4.1 optionalDependencies: - prettier: 2.7.1 + prettier: 2.8.8 transitivePeerDependencies: - encoding dev: true @@ -1628,6 +1634,10 @@ packages: resolution: {integrity: sha512-X4CDiMnDbA3s3RaUXWXmgAIbY1uxab3fqe3qwzg5XutR3wjqi7M3IkgQbsIBzpqBN2YWr/Qdv7JrFRqSgb4TFg==} dev: true + /discord-api-types@0.37.54: + resolution: {integrity: sha512-xNO6yzEMfpVSVUa6lOOzgLDy3Gyd8yuBAozGQdjpW9VjRq2Ccboz4FhTrd5v4Hw7pbkCKwnHvddjIYrX0INkUQ==} + dev: true + /discord.js@14.13.0: resolution: {integrity: sha512-Kufdvg7fpyTEwANGy9x7i4od4yu5c6gVddGi5CKm4Y5a6sF0VBODObI3o0Bh7TGCj0LfNT8Qp8z04wnLFzgnbA==} engines: {node: '>=16.11.0'} @@ -3347,7 +3357,7 @@ packages: optional: true dependencies: lilconfig: 2.1.0 - ts-node: 10.9.1(@swc/core@1.3.78)(@types/node@20.5.3)(typescript@4.7.4) + ts-node: 10.9.1(@swc/core@1.3.78)(@types/node@20.5.3)(typescript@5.1.6) yaml: 2.3.1 dev: true @@ -3363,8 +3373,8 @@ packages: fast-diff: 1.3.0 dev: true - /prettier@2.7.1: - resolution: {integrity: sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==} + /prettier@2.8.8: + resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} engines: {node: '>=10.13.0'} hasBin: true requiresBuild: true @@ -4012,13 +4022,13 @@ packages: engines: {node: '>=8'} dev: true - /ts-api-utils@1.0.2(typescript@4.7.4): + /ts-api-utils@1.0.2(typescript@5.1.6): resolution: {integrity: sha512-Cbu4nIqnEdd+THNEsBdkolnOXhg0I8XteoHaEKgvsxpsbWda4IsUut2c187HxywQCvveojow0Dgw/amxtSKVkQ==} engines: {node: '>=16.13.0'} peerDependencies: typescript: '>=4.2.0' dependencies: - typescript: 4.7.4 + typescript: 5.1.6 dev: true /ts-interface-checker@0.1.13: @@ -4029,7 +4039,7 @@ packages: resolution: {integrity: sha512-k43M7uCG1AkTyxgnmI5MPwKoUvS/bRvLvUb7+Pgpdlmok8AoqmUaZxUUw8zKM5B1lqZrt41GjYgnvAi0fppqgQ==} dev: true - /ts-node@10.9.1(@swc/core@1.3.78)(@types/node@20.5.3)(typescript@4.7.4): + /ts-node@10.9.1(@swc/core@1.3.78)(@types/node@20.5.3)(typescript@5.1.6): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -4056,7 +4066,7 @@ packages: create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 4.7.4 + typescript: 5.1.6 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 dev: true @@ -4074,7 +4084,7 @@ packages: engines: {node: '>=16'} dev: true - /tsup@7.2.0(@swc/core@1.3.78)(ts-node@10.9.1)(typescript@4.7.4): + /tsup@7.2.0(@swc/core@1.3.78)(ts-node@10.9.1)(typescript@5.1.6): resolution: {integrity: sha512-vDHlczXbgUvY3rWvqFEbSqmC1L7woozbzngMqTtL2PGBODTtWlRwGDDawhvWzr5c1QjKe4OAKqJGfE1xeXUvtQ==} engines: {node: '>=16.14'} hasBin: true @@ -4105,7 +4115,7 @@ packages: source-map: 0.8.0-beta.0 sucrase: 3.34.0 tree-kill: 1.2.2 - typescript: 4.7.4 + typescript: 5.1.6 transitivePeerDependencies: - supports-color - ts-node @@ -4163,7 +4173,7 @@ packages: engines: {node: '>=16'} dev: true - /typedoc@0.22.18(typescript@4.7.4): + /typedoc@0.22.18(typescript@5.1.6): resolution: {integrity: sha512-NK9RlLhRUGMvc6Rw5USEYgT4DVAUFk7IF7Q6MYfpJ88KnTZP7EneEa4RcP+tX1auAcz7QT1Iy0bUSZBYYHdoyA==} engines: {node: '>= 12.10.0'} hasBin: true @@ -4175,10 +4185,10 @@ packages: marked: 4.3.0 minimatch: 5.1.6 shiki: 0.10.1 - typescript: 4.7.4 + typescript: 5.1.6 dev: true - /typedoc@0.24.8(typescript@4.7.4): + /typedoc@0.24.8(typescript@5.1.6): resolution: {integrity: sha512-ahJ6Cpcvxwaxfu4KtjA8qZNqS43wYt6JL27wYiIgl1vd38WW/KWX11YuAeZhuz9v+ttrutSsgK+XO1CjL1kA3w==} engines: {node: '>= 14.14'} hasBin: true @@ -4189,12 +4199,12 @@ packages: marked: 4.3.0 minimatch: 9.0.3 shiki: 0.14.3 - typescript: 4.7.4 + typescript: 5.1.6 dev: true - /typescript@4.7.4: - resolution: {integrity: sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==} - engines: {node: '>=4.2.0'} + /typescript@5.1.6: + resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==} + engines: {node: '>=14.17'} hasBin: true dev: true @@ -4249,6 +4259,11 @@ packages: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} dev: true + /utility-types@3.10.0: + resolution: {integrity: sha512-O11mqxmi7wMKCo6HKFt5AhO4BwY3VV68YU07tgxfz8zJTIxr4BpsezN49Ffwy9j3ZpwwJp4fkRwjRzq3uWE6Rg==} + engines: {node: '>= 4'} + dev: true + /v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} dev: true diff --git a/src/applicationCommand/ApplicationCommandExtension.ts b/src/applicationCommand/ApplicationCommandExtension.ts index acc1325..5399467 100644 --- a/src/applicationCommand/ApplicationCommandExtension.ts +++ b/src/applicationCommand/ApplicationCommandExtension.ts @@ -1,21 +1,34 @@ import chalk from 'chalk' -import type { ApplicationCommandData, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, ChatInputApplicationCommandData, Interaction, Snowflake } from 'discord.js' -import { - ApplicationCommandOptionType, - ApplicationCommandType, - ChatInputCommandInteraction, - Collection, - CommandInteraction, - InteractionType, - MessageContextMenuCommandInteraction, - UserContextMenuCommandInteraction, +import type { Mutable } from 'utility-types' +import type { + ApplicationCommandData, + ApplicationCommandSubCommandData, + ApplicationCommandSubGroupData, + ChatInputApplicationCommandData, + Interaction, + Snowflake, + ApplicationCommandOptionData, } from 'discord.js' +import { ChatInputCommandInteraction, Collection, CommandInteraction, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction } from 'discord.js' +import { ApplicationCommandOptionType, ApplicationCommandType } from 'discord-api-types/v10' import { ApplicationCommandComponent } from './ApplicationCommand' import { ApplicationCommandOption } from './ApplicationCommandOption' -import { listener } from '../core/listener' -import { argConverter } from '../core/converter' +import { listener } from '../core' +import { argConverter } from '../core' import { CTSExtension } from '../core/extensions/CTSExtension' +type MutableGroup = ChatInputApplicationCommandData & { + options: Mutable +} + +type MutableSubGroup = ApplicationCommandSubGroupData & { + options: Mutable +} + +type MutableCommand = ChatInputApplicationCommandData & { + options: ApplicationCommandOptionData[] +} + export type ApplicationCommandExtensionConfig = { guilds?: Snowflake[] } @@ -27,6 +40,7 @@ export class ApplicationCommandExtension extends CTSExtension { unmanagedCommands: (ApplicationCommandData & { guilds?: Snowflake[] })[] = [] + // noinspection JSUnusedGlobalSymbols registerUnmanagedCommand(command: ApplicationCommandData & { guilds?: Snowflake[] }) { this.unmanagedCommands.push(command) } @@ -34,7 +48,7 @@ export class ApplicationCommandExtension extends CTSExtension { @listener({ event: 'interactionCreate' }) async interactionCreate(i: Interaction) { try { - if (i.type !== InteractionType.ApplicationCommand) return + if (!i.isCommand()) return let cmd: ApplicationCommandComponent | null = null let ext: object | null = null @@ -44,7 +58,7 @@ export class ApplicationCommandExtension extends CTSExtension { let subcommand: string | null = null let subcommandGroup: string | null = null - if (i.commandType === ApplicationCommandType.ChatInput) { + if (i.isChatInputCommand()) { subcommand = i.options.getSubcommand(false) subcommandGroup = i.options.getSubcommandGroup(false) } @@ -139,13 +153,13 @@ export class ApplicationCommandExtension extends CTSExtension { for (const command of client.registry.getComponentsWithTypeGlobal(ApplicationCommandComponent)) { if (command.subcommandGroup) { - let group = subcommandGroups.get(command.subcommandGroup.options.name) + let group = subcommandGroups.get(command.subcommandGroup.options.name) as MutableGroup if (!group) { group = { ...command.subcommandGroup.options, type: ApplicationCommandType.ChatInput, - } + } as MutableGroup if (command.subcommandGroup.guilds) { for (const guild of command.subcommandGroup.guilds) { @@ -174,18 +188,18 @@ export class ApplicationCommandExtension extends CTSExtension { } } - group.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand, options } as ApplicationCommandSubCommandData) + group.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand, options } as Mutable) continue } else if (command.subcommandGroupChild) { const parent = command.subcommandGroupChild.parent - let group = subcommandGroups.get(parent.options.name) + let group = subcommandGroups.get(parent.options.name) as MutableGroup if (!group) { group = { ...parent.options, type: ApplicationCommandType.ChatInput, - } + } as MutableGroup if (parent.guilds) { for (const guild of parent.guilds) { @@ -204,10 +218,13 @@ export class ApplicationCommandExtension extends CTSExtension { if (!group.options) group.options = [] - let child = group.options.find((x) => x.name === command.subcommandGroupChild?.options.name) as ApplicationCommandSubGroupData + let child = group.options.find((x) => x.name === command.subcommandGroupChild?.options.name) as MutableSubGroup if (!child) { - child = { ...(command.subcommandGroupChild.options as Omit), type: ApplicationCommandOptionType.SubcommandGroup } + child = { + ...(command.subcommandGroupChild.options as Omit), + type: ApplicationCommandOptionType.SubcommandGroup, + } as MutableSubGroup group.options.push(child) } @@ -223,12 +240,12 @@ export class ApplicationCommandExtension extends CTSExtension { } } - child.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand, options } as ApplicationCommandSubCommandData) + child.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand, options } as Mutable) continue } - const cmd: ApplicationCommandData = { ...command.options } + const cmd = { ...command.options } as MutableCommand if (cmd.type === ApplicationCommandType.ChatInput) { cmd.options = [] @@ -269,7 +286,6 @@ export class ApplicationCommandExtension extends CTSExtension { } commands.push(rest) } - continue } else { commands.push(rest) } diff --git a/src/core/components/decoratorCreator.ts b/src/core/components/decoratorCreator.ts index 7d255f6..0b25ace 100644 --- a/src/core/components/decoratorCreator.ts +++ b/src/core/components/decoratorCreator.ts @@ -61,6 +61,8 @@ export const getComponentArgumentStore = (target: object, key: string | symbol): export const createArgumentDecorator = (type: typeof ComponentArgumentDecorator) => { return (options: Options): ParameterDecorator => { return (target, key, idx) => { + if (!key) return + const arg: ComponentArgumentDecorator = new type(options) const store = getComponentArgumentStore(target, key)