@pikokr/command.ts 5.0.0-dev.daaf714 → 5.0.1-dev.6c3e252

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 (47) hide show
  1. package/.github/workflows/codeql-analysis.yml +29 -29
  2. package/.github/workflows/docs.yml +6 -6
  3. package/.github/workflows/publish.stable.yml +2 -2
  4. package/.github/workflows/publish.yml +2 -2
  5. package/.vscode/settings.json +9 -9
  6. package/README.md +2 -0
  7. package/dist/index.d.ts +138 -27
  8. package/dist/index.js +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/docs/index.yml +1 -1
  11. package/package.json +19 -15
  12. package/publish-version.js +10 -0
  13. package/renovate.json +5 -0
  14. package/src/applicationCommand/ApplicationCommand.ts +14 -14
  15. package/src/applicationCommand/ApplicationCommandExtension.ts +169 -0
  16. package/src/applicationCommand/ApplicationCommandOption.ts +9 -2
  17. package/src/applicationCommand/index.ts +8 -0
  18. package/src/core/components/BaseComponent.ts +41 -11
  19. package/src/core/components/ComponentArgument.ts +8 -0
  20. package/src/core/components/ComponentArgumentDecorator.ts +9 -1
  21. package/src/core/components/decoratorCreator.ts +23 -10
  22. package/src/core/components/index.ts +13 -3
  23. package/src/core/converter/index.ts +16 -0
  24. package/src/core/extensions/CTSExtension.ts +17 -0
  25. package/src/core/extensions/Extension.ts +62 -0
  26. package/src/core/extensions/index.ts +9 -0
  27. package/src/core/hooks/componentHook.ts +40 -0
  28. package/src/core/hooks/index.ts +11 -1
  29. package/src/core/hooks/moduleHook.ts +11 -3
  30. package/src/core/index.ts +13 -1
  31. package/src/core/listener/index.ts +29 -0
  32. package/src/core/structures/CommandClient.ts +78 -0
  33. package/src/core/structures/Registry.ts +156 -6
  34. package/src/core/structures/index.ts +9 -0
  35. package/src/core/symbols.ts +14 -3
  36. package/src/core/utils/checks.ts +27 -0
  37. package/src/core/utils/errors.ts +9 -0
  38. package/src/core/utils/index.ts +10 -0
  39. package/src/index.ts +7 -6
  40. package/src/textCommand/TextCommand.ts +20 -0
  41. package/src/textCommand/TextCommandExtension.ts +128 -0
  42. package/src/textCommand/index.ts +11 -0
  43. package/src/textCommand/parameters.ts +14 -0
  44. package/test/index.ts +57 -17
  45. package/tsconfig.json +2 -3
  46. package/tsconfig.prod.json +6 -2
  47. package/tsup.config.ts +8 -8
package/test/index.ts CHANGED
@@ -1,22 +1,30 @@
1
- import { ApplicationCommandOptionType } from 'discord.js'
2
- import { applicationCommand, ApplicationCommandComponent, moduleHook, option, Registry } from '../src'
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
+ */
3
8
 
4
- class Test {
9
+ import { ApplicationCommandOptionType, ApplicationCommandType, ChatInputCommandInteraction, Client, Message } from 'discord.js'
10
+ import { applicationCommand, CommandClient, moduleHook, option, ownerOnly, listener, Extension, command, rest } from '../src'
11
+ import 'dotenv/config'
12
+ import { Logger } from 'tslog'
13
+ import chalk from 'chalk'
14
+
15
+ class Test extends Extension {
5
16
  @applicationCommand({
17
+ type: ApplicationCommandType.ChatInput,
6
18
  name: 'test',
7
19
  description: 'wow this is test',
8
20
  })
9
- async testCommand(
10
- @option({
11
- name: 'hello',
12
- description: '와아',
13
- type: ApplicationCommandOptionType.String,
14
- })
15
- hello: string,
16
- world: string,
17
- ) {}
21
+ async testCommand(i: ChatInputCommandInteraction) {
22
+ i.reply('Wow')
23
+ }
18
24
 
25
+ @ownerOnly
19
26
  @applicationCommand({
27
+ type: ApplicationCommandType.ChatInput,
20
28
  name: 'test2',
21
29
  description: 'wow this is test wow',
22
30
  })
@@ -25,29 +33,61 @@ class Test {
25
33
  name: 'sans',
26
34
  description: '와',
27
35
  type: ApplicationCommandOptionType.String,
36
+ required: true,
28
37
  })
29
38
  wa: string,
30
- ) {}
39
+ i: ChatInputCommandInteraction,
40
+ ) {
41
+ i.reply(wa)
42
+ }
31
43
 
32
44
  @moduleHook('load')
33
45
  load() {
34
- console.log('load')
46
+ this.logger.info('Load')
35
47
  }
36
48
 
37
49
  @moduleHook('unload')
38
50
  unload() {
39
- console.log('unload')
51
+ this.logger.info('Unload')
52
+ }
53
+
54
+ @listener({ event: 'ready' })
55
+ async testEvent() {
56
+ this.logger.info(`Login: ${chalk.green(client.user!.tag)}`)
57
+ await this.commandClient.fetchOwners()
58
+ }
59
+
60
+ @command({ name: 'test' })
61
+ async test(msg: Message, @rest() sans: string) {
62
+ console.log(sans)
63
+ await msg.reply('Wow')
40
64
  }
41
65
  }
42
66
 
43
67
  const ext = new Test()
44
68
 
45
- const registry = new Registry()
69
+ const client = new Client({ intents: ['GuildMessages', 'MessageContent', 'DirectMessages', 'Guilds'] })
70
+
71
+ const logger = new Logger({ dateTimeTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone })
72
+
73
+ const cc = new CommandClient(client, logger)
74
+
75
+ const registry = cc.registry
46
76
 
47
77
  const run = async () => {
78
+ await cc.enableApplicationCommandsExtension({
79
+ guilds: ['832938554438844438'],
80
+ })
81
+
82
+ await cc.enableTextCommandsExtension({
83
+ prefix: '.',
84
+ })
85
+
48
86
  await registry.registerModule(ext)
49
87
 
50
- await registry.unregisterModule(ext)
88
+ await client.login(process.env.TOKEN)
89
+
90
+ await cc.getApplicationCommandsExtension()!.sync()
51
91
  }
52
92
 
53
93
  run()
package/tsconfig.json CHANGED
@@ -15,11 +15,10 @@
15
15
  "declaration": true,
16
16
  /* Generates corresponding '.d.ts' file. */
17
17
  // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
18
- "sourceMap": true, /* Generates corresponding '.map' file. */
18
+ "sourceMap": true /* Generates corresponding '.map' file. */,
19
19
  // "outFile": "./", /* Concatenate and emit output to single file. */
20
20
  "outDir": "./dist",
21
21
  /* Redirect output structure to the directory. */
22
- "rootDir": "./src",
23
22
  /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
24
23
  // "composite": true, /* Enable project compilation */
25
24
  // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
@@ -31,7 +30,7 @@
31
30
 
32
31
  /* Strict Type-Checking Options */
33
32
  "strict": true,
34
-
33
+
35
34
  /* Enable all strict type-checking options. */
36
35
  // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
37
36
  // "strictNullChecks": true, /* Enable strict null checks. */
@@ -1,4 +1,8 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
- "exclude": ["node_modules", "scripts", "test", "tsup.config.ts"]
4
- }
3
+ "exclude": ["node_modules", "scripts", "test", "tsup.config.ts", "dist"],
4
+ "include": ["src"],
5
+ "compilerOptions": {
6
+ "rootDir": "./src",
7
+ }
8
+ }
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({