@pikokr/command.ts 3.0.6-dev.f017886 → 3.0.8-dev.0b83b2b

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 파링
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Command framework for discord.js
4
4
 
5
- [Discord](https://discord.gg/EEhcPzsGHV) [가이드](https://pikokr.notion.site/a60262db37724fd38e4b7fc83be7e52d)
5
+ [Discord](https://discord.gg/EEhcPzsGHV)
6
+
7
+ [문서](https://v3.cts.pikokr.dev)
6
8
 
7
9
  [V2 문서](https://command-ts-docs-ezojnktwv-pikokr.vercel.app/)
@@ -1,5 +1,5 @@
1
1
  import { BuiltInModule } from './BuiltInModule';
2
- import { Client, GuildMember, Message, User } from 'discord.js';
2
+ import { Client, GuildMember, Message, User, Role } from 'discord.js';
3
3
  import { CommandClient } from '../structures';
4
4
  export declare class BuiltinCommandConverters extends BuiltInModule {
5
5
  private cts;
@@ -11,4 +11,6 @@ export declare class BuiltinCommandConverters extends BuiltInModule {
11
11
  user(msg: Message, value: string): User | null;
12
12
  member(msg: Message, value: string): GuildMember | undefined;
13
13
  number(msg: Message, value: string): number | undefined;
14
+ getRoleIDByMention(mention: string): `${bigint}` | undefined;
15
+ role(msg: Message, value: string): Role | undefined;
14
16
  }
@@ -55,6 +55,25 @@ class BuiltinCommandConverters extends BuiltInModule_1.BuiltInModule {
55
55
  const n = Number(value);
56
56
  return isNaN(n) ? undefined : n;
57
57
  }
58
+ getRoleIDByMention(mention) {
59
+ if (!mention)
60
+ return;
61
+ if (mention.startsWith('<@') && mention.endsWith('>')) {
62
+ mention = mention.slice(2, -1);
63
+ if (mention.startsWith('&')) {
64
+ mention = mention.slice(1);
65
+ }
66
+ return mention;
67
+ }
68
+ }
69
+ role(msg, value) {
70
+ var _a;
71
+ const id = this.getRoleIDByMention(value);
72
+ if (!id)
73
+ return;
74
+ const role = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.roles.cache.get(id);
75
+ return role || undefined;
76
+ }
58
77
  }
59
78
  __decorate([
60
79
  command_1.argumentConverter(discord_js_1.Message, false),
@@ -86,4 +105,10 @@ __decorate([
86
105
  __metadata("design:paramtypes", [discord_js_1.Message, String]),
87
106
  __metadata("design:returntype", void 0)
88
107
  ], BuiltinCommandConverters.prototype, "number", null);
108
+ __decorate([
109
+ command_1.argumentConverter(discord_js_1.Role),
110
+ __metadata("design:type", Function),
111
+ __metadata("design:paramtypes", [discord_js_1.Message, String]),
112
+ __metadata("design:returntype", Object)
113
+ ], BuiltinCommandConverters.prototype, "role", null);
89
114
  exports.BuiltinCommandConverters = BuiltinCommandConverters;
@@ -1,9 +1,10 @@
1
1
  import { BuiltInModule } from './BuiltInModule';
2
- import { Client, CommandInteraction } from 'discord.js';
2
+ import { Client, CommandInteraction, CommandInteractionOptionResolver } from 'discord.js';
3
3
  import { CommandClient } from '../structures';
4
4
  export declare class BuiltinSlashCommandConverters extends BuiltInModule {
5
5
  private cts;
6
6
  client: Client;
7
7
  constructor(cts: CommandClient);
8
8
  message(interaction: CommandInteraction): CommandInteraction;
9
+ optionResolver(interaction: CommandInteraction): CommandInteractionOptionResolver;
9
10
  }
@@ -22,6 +22,9 @@ class BuiltinSlashCommandConverters extends BuiltInModule_1.BuiltInModule {
22
22
  message(interaction) {
23
23
  return interaction;
24
24
  }
25
+ optionResolver(interaction) {
26
+ return interaction.options;
27
+ }
25
28
  }
26
29
  __decorate([
27
30
  command_1.slashArgumentConverter(discord_js_1.CommandInteraction),
@@ -29,4 +32,10 @@ __decorate([
29
32
  __metadata("design:paramtypes", [discord_js_1.CommandInteraction]),
30
33
  __metadata("design:returntype", void 0)
31
34
  ], BuiltinSlashCommandConverters.prototype, "message", null);
35
+ __decorate([
36
+ command_1.slashArgumentConverter(discord_js_1.CommandInteractionOptionResolver),
37
+ __metadata("design:type", Function),
38
+ __metadata("design:paramtypes", [discord_js_1.CommandInteraction]),
39
+ __metadata("design:returntype", discord_js_1.CommandInteractionOptionResolver)
40
+ ], BuiltinSlashCommandConverters.prototype, "optionResolver", null);
32
41
  exports.BuiltinSlashCommandConverters = BuiltinSlashCommandConverters;
@@ -126,9 +126,13 @@ class Registry {
126
126
  if (guild) {
127
127
  const syncForGuild = (g) => __awaiter(this, void 0, void 0, function* () {
128
128
  console.log(`Syncing for guild ${g.name}(${g.id})`);
129
- console.log(`Command List: ${commands.map((x) => x.commandBuilder.name)}`);
129
+ const commandsToRegister = [
130
+ ...commands.map((x) => x.commandBuilder),
131
+ ...this.slashCommands.filter((y) => { var _a; return y.guild === g.id || ((_a = y.guild) === null || _a === void 0 ? void 0 : _a.includes(g.id)) || false; }).map((x) => x.commandBuilder),
132
+ ];
133
+ console.log(`Command List: ${commandsToRegister.map((x) => x.name).join(', ')}`);
130
134
  yield this.client.rest.put(v9_1.Routes.applicationGuildCommands(this.client.client.application.id, g.id), {
131
- body: [...commands.map((x) => x.commandBuilder.toJSON()), ...this.slashCommands.filter((y) => { var _a; return y.guild === g.id || ((_a = y.guild) === null || _a === void 0 ? void 0 : _a.includes(g.id)) || false; })],
135
+ body: commandsToRegister.map((x) => x.toJSON()),
132
136
  });
133
137
  });
134
138
  if (typeof guild === 'string') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pikokr/command.ts",
3
3
  "description": "Discord.js command framework for typescript.",
4
- "version": "3.0.6-dev.f017886",
4
+ "version": "3.0.8-dev.0b83b2b",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  import { BuiltInModule } from './BuiltInModule'
2
2
  import { argumentConverter } from '../command'
3
- import { Client, GuildMember, Message, User } from 'discord.js'
3
+ import { Client, GuildMember, Message, User, Role } from 'discord.js'
4
4
  import { CommandClient } from '../structures'
5
5
 
6
6
  export class BuiltinCommandConverters extends BuiltInModule {
@@ -53,4 +53,24 @@ export class BuiltinCommandConverters extends BuiltInModule {
53
53
  const n = Number(value)
54
54
  return isNaN(n) ? undefined : n
55
55
  }
56
+
57
+ getRoleIDByMention(mention: string): `${bigint}` | undefined {
58
+ if (!mention) return
59
+ if (mention.startsWith('<@') && mention.endsWith('>')) {
60
+ mention = mention.slice(2, -1)
61
+ if (mention.startsWith('&')) {
62
+ mention = mention.slice(1)
63
+ }
64
+ return mention as `${bigint}`
65
+ }
66
+ }
67
+
68
+ @argumentConverter(Role)
69
+ role(msg: Message, value: string): Role | undefined{
70
+ const id = this.getRoleIDByMention(value)
71
+ if (!id) return
72
+ const role = msg.guild?.roles.cache.get(id)
73
+ return role || undefined
74
+ }
75
+
56
76
  }
@@ -1,6 +1,6 @@
1
1
  import { BuiltInModule } from './BuiltInModule'
2
2
  import { slashArgumentConverter } from '../command'
3
- import { Client, CommandInteraction } from 'discord.js'
3
+ import { Client, CommandInteraction, CommandInteractionOptionResolver } from 'discord.js'
4
4
  import { CommandClient } from '../structures'
5
5
 
6
6
  export class BuiltinSlashCommandConverters extends BuiltInModule {
@@ -15,4 +15,9 @@ export class BuiltinSlashCommandConverters extends BuiltInModule {
15
15
  message(interaction: CommandInteraction) {
16
16
  return interaction
17
17
  }
18
+
19
+ @slashArgumentConverter(CommandInteractionOptionResolver)
20
+ optionResolver(interaction: CommandInteraction): CommandInteractionOptionResolver {
21
+ return interaction.options
22
+ }
18
23
  }
@@ -124,9 +124,13 @@ export class Registry {
124
124
  if (guild) {
125
125
  const syncForGuild = async (g: Guild) => {
126
126
  console.log(`Syncing for guild ${g.name}(${g.id})`)
127
- console.log(`Command List: ${commands.map((x) => x.commandBuilder.name)}`)
127
+ const commandsToRegister = [
128
+ ...commands.map((x) => x.commandBuilder),
129
+ ...this.slashCommands.filter((y) => y.guild === g.id || y.guild?.includes(g.id) || false).map((x) => x.commandBuilder),
130
+ ]
131
+ console.log(`Command List: ${commandsToRegister.map((x) => x.name).join(', ')}`)
128
132
  await this.client.rest.put(Routes.applicationGuildCommands(this.client.client.application!.id, g.id) as any, {
129
- body: [...commands.map((x) => x.commandBuilder.toJSON()), ...this.slashCommands.filter((y) => y.guild === g.id || y.guild?.includes(g.id) || false)],
133
+ body: commandsToRegister.map((x) => x.toJSON()),
130
134
  })
131
135
  }
132
136