@pikokr/command.ts 5.0.0-dev.a0bc517 → 5.0.0-dev.d04bd18

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 (37) hide show
  1. package/dist/index.d.ts +114 -33
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/package.json +6 -2
  5. package/publish-version.js +10 -0
  6. package/scripts/docs.ts +8 -8
  7. package/src/applicationCommand/ApplicationCommand.ts +14 -18
  8. package/src/applicationCommand/ApplicationCommandExtension.ts +169 -0
  9. package/src/applicationCommand/ApplicationCommandOption.ts +9 -2
  10. package/src/applicationCommand/index.ts +8 -0
  11. package/src/core/components/BaseComponent.ts +36 -14
  12. package/src/core/components/ComponentArgument.ts +8 -0
  13. package/src/core/components/ComponentArgumentDecorator.ts +8 -0
  14. package/src/core/components/decoratorCreator.ts +17 -3
  15. package/src/core/components/index.ts +13 -3
  16. package/src/core/converter/index.ts +16 -0
  17. package/src/core/extensions/CTSExtension.ts +17 -0
  18. package/src/core/extensions/Extension.ts +62 -0
  19. package/src/core/extensions/index.ts +9 -0
  20. package/src/core/hooks/componentHook.ts +40 -0
  21. package/src/core/hooks/index.ts +11 -1
  22. package/src/core/hooks/moduleHook.ts +11 -3
  23. package/src/core/index.ts +13 -1
  24. package/src/core/listener/index.ts +22 -2
  25. package/src/core/structures/CommandClient.ts +61 -4
  26. package/src/core/structures/Registry.ts +29 -5
  27. package/src/core/structures/index.ts +8 -0
  28. package/src/core/symbols.ts +13 -4
  29. package/src/core/utils/checks.ts +27 -0
  30. package/src/core/utils/errors.ts +9 -0
  31. package/src/core/utils/index.ts +10 -0
  32. package/src/index.ts +11 -10
  33. package/src/textCommand/TextCommand.ts +11 -0
  34. package/src/textCommand/index.ts +1 -0
  35. package/test/index.ts +40 -26
  36. package/tsconfig.prod.json +1 -0
  37. package/tsup.config.ts +8 -8
package/src/index.ts CHANGED
@@ -1,10 +1,11 @@
1
- /*
2
- * File: index.ts
3
- *
4
- * Copyright (c) 2022-2022 pikokr
5
- *
6
- * Licensed under MIT License. Please see more defails in LICENSE file.
7
- */
8
-
9
- export * from './core'
10
- export * from './applicationCommand'
1
+ /*
2
+ * File: index.ts
3
+ *
4
+ * Copyright (c) 2022-2022 pikokr
5
+ *
6
+ * Licensed under MIT License. Please see more defails in LICENSE file.
7
+ */
8
+
9
+ export * from './core'
10
+ export * from './applicationCommand'
11
+ export * from './textCommand'
@@ -0,0 +1,11 @@
1
+ import { createComponentDecorator } from '../core/components/decoratorCreator'
2
+ import { BaseComponent } from '../core/components/BaseComponent'
3
+
4
+ type TextCommandOptions = {
5
+ name: string
6
+ description?: string
7
+ }
8
+
9
+ export class TextCommandComponent extends BaseComponent<TextCommandOptions> {}
10
+
11
+ export const command = createComponentDecorator(TextCommandComponent)
@@ -0,0 +1 @@
1
+ export * from './TextCommand'
package/test/index.ts CHANGED
@@ -1,23 +1,30 @@
1
- import { ApplicationCommandOptionType, Client } from 'discord.js'
2
- import { applicationCommand, ApplicationCommandComponent, CommandClient, moduleHook, option, Registry } from '../src'
3
- import { listener } from '../src/core/listener'
1
+ /*
2
+ * File: index.ts
3
+ *
4
+ * Copyright (c) 2022-2022 pikokr
5
+ *
6
+ * Licensed under MIT License. Please see more defails in LICENSE file.
7
+ */
4
8
 
5
- class Test {
9
+ import { ApplicationCommandOptionType, ApplicationCommandType, ChatInputCommandInteraction, Client } from 'discord.js'
10
+ import { applicationCommand, CommandClient, moduleHook, option, ownerOnly, listener, Extension } from '../dist'
11
+ import 'dotenv/config'
12
+ import { Logger } from 'tslog'
13
+ import chalk from 'chalk'
14
+
15
+ class Test extends Extension {
6
16
  @applicationCommand({
17
+ type: ApplicationCommandType.ChatInput,
7
18
  name: 'test',
8
19
  description: 'wow this is test',
9
20
  })
10
- async testCommand(
11
- @option({
12
- name: 'hello',
13
- description: '와아',
14
- type: ApplicationCommandOptionType.String,
15
- })
16
- hello: string,
17
- world: string,
18
- ) {}
21
+ async testCommand(i: ChatInputCommandInteraction) {
22
+ i.reply('Wow')
23
+ }
19
24
 
25
+ @ownerOnly
20
26
  @applicationCommand({
27
+ type: ApplicationCommandType.ChatInput,
21
28
  name: 'test2',
22
29
  description: 'wow this is test wow',
23
30
  })
@@ -26,23 +33,28 @@ class Test {
26
33
  name: 'sans',
27
34
  description: '와',
28
35
  type: ApplicationCommandOptionType.String,
36
+ required: true,
29
37
  })
30
38
  wa: string,
31
- ) {}
39
+ i: ChatInputCommandInteraction,
40
+ ) {
41
+ i.reply(wa)
42
+ }
32
43
 
33
44
  @moduleHook('load')
34
45
  load() {
35
- console.log('load')
46
+ this.logger.info('Load')
36
47
  }
37
48
 
38
49
  @moduleHook('unload')
39
50
  unload() {
40
- console.log('unload')
51
+ this.logger.info('Unload')
41
52
  }
42
53
 
43
- @listener({ event: 'test', emitter: 'discord' })
44
- testEvent() {
45
- console.log('test')
54
+ @listener({ event: 'ready' })
55
+ async testEvent() {
56
+ this.logger.info(`Login: ${chalk.green(client.user!.tag)}`)
57
+ await this.commandClient.fetchOwners()
46
58
  }
47
59
  }
48
60
 
@@ -50,20 +62,22 @@ const ext = new Test()
50
62
 
51
63
  const client = new Client({ intents: [] })
52
64
 
53
- const cc = new CommandClient(client)
65
+ const logger = new Logger({ dateTimeTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone })
66
+
67
+ const cc = new CommandClient(client, logger)
54
68
 
55
69
  const registry = cc.registry
56
70
 
57
71
  const run = async () => {
58
- await registry.registerModule(ext)
72
+ await cc.enableApplicationCommandsExtension({
73
+ guilds: ['832938554438844438'],
74
+ })
59
75
 
60
- // listener test
61
- client.emit('test')
76
+ await registry.registerModule(ext)
62
77
 
63
- await registry.unregisterModule(ext)
78
+ await client.login(process.env.TOKEN)
64
79
 
65
- // shold not work
66
- client.emit('test')
80
+ await cc.getApplicationCommandsExtension()!.sync()
67
81
  }
68
82
 
69
83
  run()
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
3
  "exclude": ["node_modules", "scripts", "test", "tsup.config.ts"],
4
+ "include": ["src"],
4
5
  "compilerOptions": {
5
6
  "rootDir": "./src",
6
7
  }
package/tsup.config.ts CHANGED
@@ -1,11 +1,11 @@
1
- /*
2
- * File: tsup.config.ts
3
- *
4
- * Copyright (c) 2022-2022 pikokr
5
- *
6
- * Licensed under MIT License. Please see more defails in LICENSE file.
7
- */
8
-
1
+ /*
2
+ * File: tsup.config.ts
3
+ *
4
+ * Copyright (c) 2022-2022 pikokr
5
+ *
6
+ * Licensed under MIT License. Please see more defails in LICENSE file.
7
+ */
8
+
9
9
  import { defineConfig } from 'tsup'
10
10
 
11
11
  export default defineConfig({