@pikokr/command.ts 3.0.6-dev.d6740cf → 3.0.8
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/dist/builtinModules/BuiltinCommandConverters.d.ts +3 -1
- package/dist/builtinModules/BuiltinCommandConverters.js +25 -0
- package/dist/builtinModules/BuiltinSlashCommandConverters.d.ts +2 -1
- package/dist/builtinModules/BuiltinSlashCommandConverters.js +9 -0
- package/dist/structures/Registry.js +6 -2
- package/package.json +2 -2
- package/src/builtinModules/BuiltinCommandConverters.ts +21 -1
- package/src/builtinModules/BuiltinSlashCommandConverters.ts +6 -1
- package/src/structures/Registry.ts +6 -2
|
@@ -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
|
-
|
|
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:
|
|
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.
|
|
4
|
+
"version": "3.0.8",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
"docs:dev": "typedoc",
|
|
32
32
|
"docs:build": "typedoc"
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
}
|
|
@@ -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
|
-
|
|
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:
|
|
133
|
+
body: commandsToRegister.map((x) => x.toJSON()),
|
|
130
134
|
})
|
|
131
135
|
}
|
|
132
136
|
|