@pikokr/command.ts 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/index.d.ts +310 -10
  2. package/dist/index.js +1 -22
  3. package/dist/index.js.map +1 -1
  4. package/package.json +5 -2
  5. package/publish-version.js +7 -3
  6. package/src/applicationCommand/AppCommand.ts +4 -0
  7. package/src/applicationCommand/decorator.ts +4 -0
  8. package/src/applicationCommand/index.ts +4 -0
  9. package/src/builtinModules/BuiltInModule.ts +4 -0
  10. package/src/builtinModules/BuiltinApplicationCommandConverters.ts +4 -0
  11. package/src/builtinModules/BuiltinCommandConverters.ts +4 -0
  12. package/src/builtinModules/CommandHandler.ts +4 -0
  13. package/src/builtinModules/index.ts +4 -0
  14. package/src/command/ArgumentConverter.ts +4 -0
  15. package/src/command/Command.ts +4 -0
  16. package/src/command/cooldown/adapter.ts +4 -0
  17. package/src/command/cooldown/decorator.ts +4 -0
  18. package/src/command/cooldown/error.ts +4 -0
  19. package/src/command/cooldown/index.ts +4 -0
  20. package/src/command/cooldown/type.ts +4 -0
  21. package/src/command/decorator.ts +4 -0
  22. package/src/command/index.ts +4 -0
  23. package/src/command/utils.ts +4 -0
  24. package/src/constants.ts +4 -0
  25. package/src/error/ArgumentConverterNotFound.ts +4 -0
  26. package/src/error/ArgumentNotProvided.ts +4 -0
  27. package/src/error/CommandCheckFailed.ts +4 -0
  28. package/src/error/CommandNotFound.ts +4 -0
  29. package/src/error/InvalidTargetError.ts +4 -0
  30. package/src/error/ModuleError.ts +4 -0
  31. package/src/error/PermissionRequired.ts +4 -0
  32. package/src/error/checks/DMOnlyCommand.ts +4 -0
  33. package/src/error/checks/GuildOnlyCommand.ts +4 -0
  34. package/src/error/checks/OwnerOnlyCommand.ts +4 -0
  35. package/src/error/checks/SlashCommandGlobalCheckError.ts +4 -0
  36. package/src/error/checks/index.ts +4 -0
  37. package/src/error/index.ts +4 -0
  38. package/src/index.ts +4 -0
  39. package/src/interface/index.ts +4 -0
  40. package/src/listener/Listener.ts +4 -0
  41. package/src/listener/decorator.ts +4 -0
  42. package/src/listener/index.ts +4 -0
  43. package/src/messageComponents/base.ts +4 -0
  44. package/src/messageComponents/button.ts +4 -0
  45. package/src/messageComponents/index.ts +4 -0
  46. package/src/messageComponents/selectMenu.ts +4 -0
  47. package/src/structures/CommandClient.ts +4 -0
  48. package/src/structures/Module.ts +4 -0
  49. package/src/structures/Registry.ts +37 -12
  50. package/src/structures/index.ts +4 -0
  51. package/src/typings.ts +4 -0
  52. package/src/utils.ts +4 -0
  53. package/test/index.ts +4 -0
  54. package/test/modules/dev.ts +4 -0
  55. package/test/modules/test.ts +5 -1
  56. package/tsup.config.ts +14 -0
  57. package/dist/applicationCommand/AppCommand.d.ts +0 -18
  58. package/dist/applicationCommand/AppCommand.js +0 -22
  59. package/dist/applicationCommand/AppCommand.js.map +0 -1
  60. package/dist/applicationCommand/decorator.d.ts +0 -10
  61. package/dist/applicationCommand/decorator.js +0 -39
  62. package/dist/applicationCommand/decorator.js.map +0 -1
  63. package/dist/applicationCommand/index.d.ts +0 -2
  64. package/dist/applicationCommand/index.js +0 -15
  65. package/dist/applicationCommand/index.js.map +0 -1
  66. package/dist/builtinModules/BuiltInModule.d.ts +0 -4
  67. package/dist/builtinModules/BuiltInModule.js +0 -13
  68. package/dist/builtinModules/BuiltInModule.js.map +0 -1
  69. package/dist/builtinModules/BuiltinApplicationCommandConverters.d.ts +0 -8
  70. package/dist/builtinModules/BuiltinApplicationCommandConverters.js +0 -13
  71. package/dist/builtinModules/BuiltinApplicationCommandConverters.js.map +0 -1
  72. package/dist/builtinModules/BuiltinCommandConverters.d.ts +0 -16
  73. package/dist/builtinModules/BuiltinCommandConverters.js +0 -127
  74. package/dist/builtinModules/BuiltinCommandConverters.js.map +0 -1
  75. package/dist/builtinModules/BuiltinSlashCommandConverters.d.ts +0 -10
  76. package/dist/builtinModules/BuiltinSlashCommandConverters.js +0 -42
  77. package/dist/builtinModules/BuiltinSlashCommandConverters.js.map +0 -1
  78. package/dist/builtinModules/CommandHandler.d.ts +0 -14
  79. package/dist/builtinModules/CommandHandler.js +0 -357
  80. package/dist/builtinModules/CommandHandler.js.map +0 -1
  81. package/dist/builtinModules/index.d.ts +0 -3
  82. package/dist/builtinModules/index.js +0 -16
  83. package/dist/builtinModules/index.js.map +0 -1
  84. package/dist/command/ArgumentConverter.d.ts +0 -15
  85. package/dist/command/ArgumentConverter.js +0 -25
  86. package/dist/command/ArgumentConverter.js.map +0 -1
  87. package/dist/command/Command.d.ts +0 -20
  88. package/dist/command/Command.js +0 -22
  89. package/dist/command/Command.js.map +0 -1
  90. package/dist/command/cooldown/adapter.d.ts +0 -10
  91. package/dist/command/cooldown/adapter.js +0 -31
  92. package/dist/command/cooldown/adapter.js.map +0 -1
  93. package/dist/command/cooldown/decorator.d.ts +0 -2
  94. package/dist/command/cooldown/decorator.js +0 -73
  95. package/dist/command/cooldown/decorator.js.map +0 -1
  96. package/dist/command/cooldown/error.d.ts +0 -4
  97. package/dist/command/cooldown/error.js +0 -11
  98. package/dist/command/cooldown/error.js.map +0 -1
  99. package/dist/command/cooldown/index.d.ts +0 -5
  100. package/dist/command/cooldown/index.js +0 -18
  101. package/dist/command/cooldown/index.js.map +0 -1
  102. package/dist/command/cooldown/type.d.ts +0 -8
  103. package/dist/command/cooldown/type.js +0 -13
  104. package/dist/command/cooldown/type.js.map +0 -1
  105. package/dist/command/decorator.d.ts +0 -17
  106. package/dist/command/decorator.js +0 -138
  107. package/dist/command/decorator.js.map +0 -1
  108. package/dist/command/index.d.ts +0 -5
  109. package/dist/command/index.js +0 -18
  110. package/dist/command/index.js.map +0 -1
  111. package/dist/command/utils.d.ts +0 -2
  112. package/dist/command/utils.js +0 -30
  113. package/dist/command/utils.js.map +0 -1
  114. package/dist/constants.d.ts +0 -14
  115. package/dist/constants.js +0 -18
  116. package/dist/constants.js.map +0 -1
  117. package/dist/error/ArgumentConverterNotFound.d.ts +0 -13
  118. package/dist/error/ArgumentConverterNotFound.js +0 -20
  119. package/dist/error/ArgumentConverterNotFound.js.map +0 -1
  120. package/dist/error/ArgumentNotProvided.d.ts +0 -8
  121. package/dist/error/ArgumentNotProvided.js +0 -13
  122. package/dist/error/ArgumentNotProvided.js.map +0 -1
  123. package/dist/error/CommandCheckFailed.d.ts +0 -13
  124. package/dist/error/CommandCheckFailed.js +0 -20
  125. package/dist/error/CommandCheckFailed.js.map +0 -1
  126. package/dist/error/CommandNotFound.d.ts +0 -7
  127. package/dist/error/CommandNotFound.js +0 -13
  128. package/dist/error/CommandNotFound.js.map +0 -1
  129. package/dist/error/InvalidTargetError.d.ts +0 -3
  130. package/dist/error/InvalidTargetError.js +0 -10
  131. package/dist/error/InvalidTargetError.js.map +0 -1
  132. package/dist/error/ModuleError.d.ts +0 -6
  133. package/dist/error/ModuleError.js +0 -14
  134. package/dist/error/ModuleError.js.map +0 -1
  135. package/dist/error/PermissionRequired.d.ts +0 -10
  136. package/dist/error/PermissionRequired.js +0 -19
  137. package/dist/error/PermissionRequired.js.map +0 -1
  138. package/dist/error/checks/DMOnlyCommand.d.ts +0 -3
  139. package/dist/error/checks/DMOnlyCommand.js +0 -10
  140. package/dist/error/checks/DMOnlyCommand.js.map +0 -1
  141. package/dist/error/checks/GuildOnlyCommand.d.ts +0 -3
  142. package/dist/error/checks/GuildOnlyCommand.js +0 -10
  143. package/dist/error/checks/GuildOnlyCommand.js.map +0 -1
  144. package/dist/error/checks/OwnerOnlyCommand.d.ts +0 -3
  145. package/dist/error/checks/OwnerOnlyCommand.js +0 -10
  146. package/dist/error/checks/OwnerOnlyCommand.js.map +0 -1
  147. package/dist/error/checks/SlashCommandGlobalCheckError.d.ts +0 -5
  148. package/dist/error/checks/SlashCommandGlobalCheckError.js +0 -11
  149. package/dist/error/checks/SlashCommandGlobalCheckError.js.map +0 -1
  150. package/dist/error/checks/index.d.ts +0 -3
  151. package/dist/error/checks/index.js +0 -16
  152. package/dist/error/checks/index.js.map +0 -1
  153. package/dist/error/index.d.ts +0 -7
  154. package/dist/error/index.js +0 -20
  155. package/dist/error/index.js.map +0 -1
  156. package/dist/interface/index.d.ts +0 -1
  157. package/dist/interface/index.js +0 -4
  158. package/dist/interface/index.js.map +0 -1
  159. package/dist/listener/Listener.d.ts +0 -5
  160. package/dist/listener/Listener.js +0 -11
  161. package/dist/listener/Listener.js.map +0 -1
  162. package/dist/listener/decorator.d.ts +0 -2
  163. package/dist/listener/decorator.js +0 -22
  164. package/dist/listener/decorator.js.map +0 -1
  165. package/dist/listener/index.d.ts +0 -2
  166. package/dist/listener/index.js +0 -15
  167. package/dist/listener/index.js.map +0 -1
  168. package/dist/messageComponents/base.d.ts +0 -10
  169. package/dist/messageComponents/base.js +0 -15
  170. package/dist/messageComponents/base.js.map +0 -1
  171. package/dist/messageComponents/button.d.ts +0 -5
  172. package/dist/messageComponents/button.js +0 -28
  173. package/dist/messageComponents/button.js.map +0 -1
  174. package/dist/messageComponents/index.d.ts +0 -2
  175. package/dist/messageComponents/index.js +0 -15
  176. package/dist/messageComponents/index.js.map +0 -1
  177. package/dist/messageComponents/selectMenu.d.ts +0 -5
  178. package/dist/messageComponents/selectMenu.js +0 -28
  179. package/dist/messageComponents/selectMenu.js.map +0 -1
  180. package/dist/slashCommand/SlashCommand.d.ts +0 -19
  181. package/dist/slashCommand/SlashCommand.js +0 -22
  182. package/dist/slashCommand/SlashCommand.js.map +0 -1
  183. package/dist/slashCommand/decorator.d.ts +0 -11
  184. package/dist/slashCommand/decorator.js +0 -39
  185. package/dist/slashCommand/decorator.js.map +0 -1
  186. package/dist/slashCommand/index.d.ts +0 -2
  187. package/dist/slashCommand/index.js +0 -15
  188. package/dist/slashCommand/index.js.map +0 -1
  189. package/dist/structures/CommandClient.d.ts +0 -45
  190. package/dist/structures/CommandClient.js +0 -94
  191. package/dist/structures/CommandClient.js.map +0 -1
  192. package/dist/structures/Module.d.ts +0 -21
  193. package/dist/structures/Module.js +0 -38
  194. package/dist/structures/Module.js.map +0 -1
  195. package/dist/structures/Registry.d.ts +0 -30
  196. package/dist/structures/Registry.js +0 -226
  197. package/dist/structures/Registry.js.map +0 -1
  198. package/dist/structures/index.d.ts +0 -3
  199. package/dist/structures/index.js +0 -16
  200. package/dist/structures/index.js.map +0 -1
  201. package/dist/typings.d.ts +0 -30
  202. package/dist/typings.js +0 -3
  203. package/dist/typings.js.map +0 -1
  204. package/dist/utils.d.ts +0 -1
  205. package/dist/utils.js +0 -11
  206. package/dist/utils.js.map +0 -1
@@ -1,9 +1,13 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  // DO NOT RUN THIS ON DEV ENVIRONMENT
2
6
  // **CI ONLY**
3
7
 
4
- const package = require('./package.json')
8
+ const pkg = require('./package.json')
5
9
  const fs = require('fs')
6
10
 
7
- package.version = package.version + '-dev.' + process.env.COMMIT_ID
11
+ pkg.version = pkg.version + '-dev.' + process.env.COMMIT_ID
8
12
 
9
- fs.writeFileSync('package.json', JSON.stringify(package, null, 2))
13
+ fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2))
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Module } from '../structures'
2
6
  import { ApplicationCommandDataResolvable, Snowflake } from 'discord.js'
3
7
  import { KApplicationCommandChecks } from '../constants'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { ApplicationCommandDataResolvable, Collection, Snowflake } from 'discord.js'
2
6
  import { checkTarget } from '../utils'
3
7
  import { KSlashCommandOptions, KApplicationCommands } from '../constants'
@@ -1,2 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './decorator'
2
6
  export * from './AppCommand'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Module } from '../structures'
2
6
  import { KBuiltInModule } from '../constants'
3
7
 
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { BuiltInModule } from './BuiltInModule'
2
6
  import { Client } from 'discord.js'
3
7
  import { CommandClient } from '../structures'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { BuiltInModule } from './BuiltInModule'
2
6
  import { argumentConverter } from '../command'
3
7
  import { Client, GuildMember, Message, User, Role } from 'discord.js'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { BuiltInModule } from './BuiltInModule'
2
6
  import { Registry } from '../structures'
3
7
  import { listener } from '../listener'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './CommandHandler'
2
6
  export * from './BuiltinCommandConverters'
3
7
  export * from './BuiltinApplicationCommandConverters'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Module } from '../structures'
2
6
  import { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'
3
7
 
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Module } from '../structures'
2
6
  import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
3
7
  import { KCommandChecks } from '../constants'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Collection } from 'discord.js'
2
6
 
3
7
  export interface CoolDownAdapter {
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { createCheckDecorator } from '../utils'
2
6
  import { CoolDownType } from './type'
3
7
  import { DMChannel, GuildMember, TextChannel } from 'discord.js'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class CoolDownError extends Error {
2
6
  constructor(public endsAt: Date) {
3
7
  super()
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './decorator'
2
6
  export * from './adapter'
3
7
  export * from './decorator'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export enum CoolDownType {
2
6
  USER,
3
7
  CHANNEL,
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { KArgumentConverters, KCommands, KOptionals, KRest, KSlashArgumentConverters } from '../constants'
2
6
  import { Command } from './Command'
3
7
  import { checkTarget } from '../utils'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './Command'
2
6
  export * from './decorator'
3
7
  export * from './ArgumentConverter'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
2
6
  import type { CheckFunction, ApplicationCommandCheckFunction } from './Command'
3
7
  import { KCommandChecks, KApplicationCommandChecks } from '../constants'
package/src/constants.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export const KCommands = Symbol('Command.TS Commands')
2
6
 
3
7
  export const KApplicationCommands = Symbol('Command.TS Slash Commands')
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'
2
6
  import type { Argument } from '../command'
3
7
  import type { AppCommandArgument } from '../applicationCommand'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Message } from 'discord.js'
2
6
  import { Command } from '../command'
3
7
 
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { CommandInteraction, ContextMenuInteraction, Message, MessageComponentInteraction } from 'discord.js'
2
6
  import { Command } from '../command'
3
7
  import { AppCommand } from '../applicationCommand'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Message } from 'discord.js'
2
6
 
3
7
  export class CommandNotFound extends Error {
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class InvalidTargetError extends Error {
2
6
  constructor() {
3
7
  super('Class does not extend "Module" class.')
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class ModuleLoadError extends Error {
2
6
  constructor(file: string, public error: Error) {
3
7
  super('Failed to load module ' + file)
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { GuildMember, Permissions } from 'discord.js'
2
6
 
3
7
  export class UserPermissionRequired extends Error {
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class DMOnlyCommandError extends Error {
2
6
  constructor() {
3
7
  super()
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class GuildOnlyCommandError extends Error {
2
6
  constructor() {
3
7
  super()
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class OwnerOnlyCommandError extends Error {
2
6
  constructor() {
3
7
  super()
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { CommandInteraction } from 'discord.js'
2
6
 
3
7
  export class SlashCommandGlobalCheckError extends Error {
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './OwnerOnlyCommand'
2
6
  export * from './GuildOnlyCommand'
3
7
  export * from './DMOnlyCommand'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './InvalidTargetError'
2
6
  export * from './ModuleError'
3
7
  export * from './ArgumentNotProvided'
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import 'reflect-metadata'
2
6
  import './typings'
3
7
 
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  // export type { HandlerAdapter } from './HandlerAdapter'
2
6
 
3
7
  export {}
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export class Listener {
2
6
  constructor(public name: string, public execute: Function) {}
3
7
  }
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { checkTarget } from '../utils'
2
6
  import { KListeners } from '../constants'
3
7
  import { Listener } from './Listener'
@@ -1,2 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './Listener'
2
6
  export * from './decorator'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { MessageComponentInteraction, MessageComponentType } from 'discord.js'
2
6
  import { Module } from '../structures'
3
7
 
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { MessageComponentExecutor, MessageComponentHandler } from './base'
2
6
  import { checkTarget } from '../utils'
3
7
  import { KMessageComponentHandlers } from '../constants'
@@ -1,2 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './button'
2
6
  export * from './selectMenu'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { MessageComponentExecutor, MessageComponentHandler } from './base'
2
6
  import { checkTarget } from '../utils'
3
7
  import { KMessageComponentHandlers } from '../constants'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import _ from 'lodash'
2
6
  import { Registry } from './Registry'
3
7
  import { Client, CommandInteraction, Interaction, Message, Snowflake, User } from 'discord.js'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { KArgumentConverters, KCommands, KListeners, KMessageComponentHandlers, KModulePath, KSlashArgumentConverters, KApplicationCommands } from '../constants'
2
6
  import type { Command } from '../command'
3
7
  import { Listener } from '../listener'
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { CommandClient } from './CommandClient'
2
6
  import { Module } from './Module'
3
7
  import { Command, ApplicationCommandArgumentConverter } from '../command'
@@ -140,28 +144,49 @@ export class Registry {
140
144
  this.logger.debug(`Syncing commands...`)
141
145
  const commands = this.applicationCommands.filter((x) => !x.guild)
142
146
  const guild = this.client.options.applicationCommands.guild
147
+ const syncForGuild = async (g: Guild, commands: AppCommand[]) => {
148
+ this.logger.debug(`Syncing for guild ${g.name}(${g.id})`)
149
+ const commandsToRegister = [
150
+ ...commands.map((x) => x.command),
151
+ ...this.applicationCommands.filter((y) => y.guild === g.id || y.guild?.includes(g.id) || false).map((x) => x.command),
152
+ ]
153
+ this.logger.debug(`Command List: ${commandsToRegister.map((x) => x.name).join(', ')}`)
154
+ await g.commands.set(commandsToRegister)
155
+ }
143
156
  if (guild) {
144
- const syncForGuild = async (g: Guild) => {
145
- this.logger.debug(`Syncing for guild ${g.name}(${g.id})`)
146
- const commandsToRegister = [
147
- ...commands.map((x) => x.command),
148
- ...this.applicationCommands.filter((y) => y.guild === g.id || y.guild?.includes(g.id) || false).map((x) => x.command),
149
- ]
150
- this.logger.debug(`Command List: ${commandsToRegister.map((x) => x.name).join(', ')}`)
151
- await g.commands.set(commandsToRegister)
152
- }
153
-
154
157
  if (typeof guild === 'string') {
155
- await syncForGuild(await this.client.client.guilds.fetch(guild))
158
+ await syncForGuild(await this.client.client.guilds.fetch(guild), commands)
156
159
  } else {
157
160
  for (const g of guild) {
158
- await syncForGuild(await this.client.client.guilds.fetch(g))
161
+ await syncForGuild(await this.client.client.guilds.fetch(g), commands)
159
162
  }
160
163
  }
161
164
  } else {
162
165
  this.logger.debug('Syncing global...')
163
166
  await this.client.client.application?.commands.set(commands.map((x) => x.command))
164
167
  }
168
+ const commandsWithGuild = this.applicationCommands.filter((x) => x.guild)
169
+
170
+ const guilds = new Set<string>()
171
+
172
+ for (const command of commandsWithGuild) {
173
+ if (!command.guild) continue
174
+ if (typeof command.guild === 'string') {
175
+ guilds.add(command.guild)
176
+ } else {
177
+ for (const guild of command.guild) {
178
+ guilds.add(guild)
179
+ }
180
+ }
181
+ }
182
+
183
+ for (const guild of guilds) {
184
+ await syncForGuild(
185
+ await this.client.client.guilds.fetch(guild),
186
+ commandsWithGuild.filter((x) => x.guild && typeof (x.guild === 'string' ? guild === x.guild : x.guild.includes(guild))),
187
+ )
188
+ }
189
+
165
190
  this.logger.debug('Syncing ended.')
166
191
  }
167
192
 
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  export * from './Module'
2
6
  export * from './CommandClient'
3
7
  export * from './Registry'
package/src/typings.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import type { Command } from './command'
2
6
  import { CommandClient } from './structures'
3
7
  import { AppCommand } from './applicationCommand'
package/src/utils.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Module } from './structures'
2
6
  import { InvalidTargetError } from './error'
3
7
 
package/test/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { Client, Intents, IntentsString } from 'discord.js'
2
6
  import { CommandClient } from '../src'
3
7
 
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
1
5
  import { BuiltInModule, CommandClient, ownerOnly, applicationCommand, listener, ApplicationCommandCheckFailed } from '../../src'
2
6
  import { CommandInteraction } from 'discord.js'
3
7
 
@@ -1,4 +1,8 @@
1
- import { command, CommandClient, coolDown, CoolDownError, CoolDownType, listener, messageButton, messageSelectMenu, Module, option, rest, applicationCommand } from '../../src'
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ import { CommandClient, coolDown, CoolDownError, CoolDownType, listener, messageButton, messageSelectMenu, Module, option, applicationCommand } from '../../src'
2
6
  import {
3
7
  ButtonInteraction,
4
8
  CommandInteraction,
package/tsup.config.ts ADDED
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright (c) 2022 pikokr. Licensed under the MIT license
3
+ */
4
+
5
+ import { defineConfig } from 'tsup'
6
+
7
+ export default defineConfig({
8
+ entry: ['src/index.ts'],
9
+ sourcemap: true,
10
+ splitting: false,
11
+ clean: true,
12
+ dts: true,
13
+ minify: true,
14
+ })
@@ -1,18 +0,0 @@
1
- import { Module } from '../structures';
2
- import { ApplicationCommandDataResolvable, Snowflake } from 'discord.js';
3
- import { ApplicationCommandCheckFunction } from '../command';
4
- export declare type AppCommandArgument = {
5
- type: any;
6
- name?: string;
7
- };
8
- export declare class AppCommand {
9
- command: ApplicationCommandDataResolvable;
10
- private run;
11
- module: Module;
12
- params: AppCommandArgument[];
13
- guild: Snowflake | Snowflake[] | undefined;
14
- private key;
15
- get checks(): ApplicationCommandCheckFunction[];
16
- execute(module: Module, args: any[]): any;
17
- constructor(command: ApplicationCommandDataResolvable, run: Function, module: Module, params: AppCommandArgument[], guild: Snowflake | Snowflake[] | undefined, key: string | symbol);
18
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppCommand = void 0;
4
- const constants_1 = require("../constants");
5
- class AppCommand {
6
- constructor(command, run, module, params, guild, key) {
7
- this.command = command;
8
- this.run = run;
9
- this.module = module;
10
- this.params = params;
11
- this.guild = guild;
12
- this.key = key;
13
- }
14
- get checks() {
15
- return Reflect.getMetadata(constants_1.KApplicationCommandChecks, this.module, this.key) || [];
16
- }
17
- execute(module, args) {
18
- return this.run.apply(module, args);
19
- }
20
- }
21
- exports.AppCommand = AppCommand;
22
- //# sourceMappingURL=AppCommand.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AppCommand.js","sourceRoot":"","sources":["../../src/applicationCommand/AppCommand.ts"],"names":[],"mappings":";;;AAEA,4CAAwD;AAQxD,MAAa,UAAU;IASrB,YACS,OAAyC,EACxC,GAAa,EACd,MAAc,EACd,MAA4B,EAC5B,KAA0C,EACzC,GAAoB;QALrB,YAAO,GAAP,OAAO,CAAkC;QACxC,QAAG,GAAH,GAAG,CAAU;QACd,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAsB;QAC5B,UAAK,GAAL,KAAK,CAAqC;QACzC,QAAG,GAAH,GAAG,CAAiB;IAC3B,CAAC;IAfJ,IAAI,MAAM;QACR,OAAO,OAAO,CAAC,WAAW,CAAC,qCAAyB,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IACpF,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,IAAW;QACjC,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACrC,CAAC;CAUF;AAjBD,gCAiBC"}
@@ -1,10 +0,0 @@
1
- import { ApplicationCommandDataResolvable, Snowflake } from 'discord.js';
2
- declare type ApplicationCommandOptions = {
3
- guild: Snowflake | Snowflake[];
4
- optionTypes?: any[];
5
- };
6
- export declare const applicationCommand: (opt: Partial<ApplicationCommandOptions> & {
7
- command: ApplicationCommandDataResolvable;
8
- }) => (target: Object, propertyKey: string) => void;
9
- export declare const option: (key: string) => ParameterDecorator;
10
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.option = exports.applicationCommand = void 0;
4
- const discord_js_1 = require("discord.js");
5
- const utils_1 = require("../utils");
6
- const constants_1 = require("../constants");
7
- const AppCommand_1 = require("./AppCommand");
8
- const applicationCommand = (opt) => {
9
- return (target, propertyKey) => {
10
- var _a;
11
- utils_1.checkTarget(target);
12
- let properties = Reflect.getMetadata(constants_1.KApplicationCommands, target);
13
- const params = (_a = opt.optionTypes) !== null && _a !== void 0 ? _a : Reflect.getMetadata('design:paramtypes', target, propertyKey);
14
- const options = Reflect.getMetadata(constants_1.KSlashCommandOptions, target, propertyKey) || new discord_js_1.Collection();
15
- const command = new AppCommand_1.AppCommand(opt.command, Reflect.get(target, propertyKey), target, params.map((x, i) => ({
16
- type: x,
17
- name: options.get(i),
18
- })), opt.guild, propertyKey);
19
- if (properties) {
20
- properties.push(command);
21
- }
22
- else {
23
- properties = [command];
24
- Reflect.defineMetadata(constants_1.KApplicationCommands, properties, target);
25
- }
26
- };
27
- };
28
- exports.applicationCommand = applicationCommand;
29
- const option = (key) => (target, propertyKey, parameterIndex) => {
30
- utils_1.checkTarget(target);
31
- let properties = Reflect.getMetadata(constants_1.KSlashCommandOptions, target, propertyKey);
32
- if (!properties) {
33
- properties = new discord_js_1.Collection();
34
- Reflect.defineMetadata(constants_1.KSlashCommandOptions, properties, target, propertyKey);
35
- }
36
- properties.set(parameterIndex, key);
37
- };
38
- exports.option = option;
39
- //# sourceMappingURL=decorator.js.map