@pikokr/command.ts 3.0.8-dev.b4462b7 → 3.0.8-dev.e5806ef
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/.all-contributorsrc +33 -0
- package/README.md +2 -0
- package/dist/builtinModules/BuiltinCommandConverters.js +15 -3
- package/dist/builtinModules/CommandHandler.js +3 -0
- package/dist/error/CommandCheckFailed.d.ts +2 -2
- package/dist/error/CommandCheckFailed.js +2 -2
- package/dist/structures/CommandClient.d.ts +2 -1
- package/dist/structures/CommandClient.js +4 -0
- package/package.json +1 -1
- package/src/builtinModules/BuiltinCommandConverters.ts +10 -2
- package/src/builtinModules/CommandHandler.ts +4 -0
- package/src/error/CommandCheckFailed.ts +1 -1
- package/src/structures/CommandClient.ts +8 -1
- package/test/modules/dev.ts +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": [
|
|
3
|
+
"README.md"
|
|
4
|
+
],
|
|
5
|
+
"imageSize": 100,
|
|
6
|
+
"contributorsPerLine": 7,
|
|
7
|
+
"contributorsSortAlphabetically": false,
|
|
8
|
+
"badgeTemplate": "[](#contributors)",
|
|
9
|
+
"contributorTemplate": "<a href=\"<%= contributor.profile %>\"><img src=\"<%= contributor.avatar_url %>\" width=\"<%= options.imageSize %>px;\" alt=\"\"/><br /><sub><b><%= contributor.name %></b></sub></a>",
|
|
10
|
+
"types": {
|
|
11
|
+
"custom": {
|
|
12
|
+
"symbol": "🔭",
|
|
13
|
+
"description": "A custom contribution type.",
|
|
14
|
+
"link": "[<%= symbol %>](<%= url %> \"<%= description %>\"),"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"skipCi": true,
|
|
18
|
+
"contributors": [
|
|
19
|
+
{
|
|
20
|
+
"login": "pikokr",
|
|
21
|
+
"name": "파링",
|
|
22
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/68010770?v=4",
|
|
23
|
+
"profile": "https://pikokr.dev",
|
|
24
|
+
"contributions": [
|
|
25
|
+
"code"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"projectName": "command.ts",
|
|
30
|
+
"projectOwner": "pikokr",
|
|
31
|
+
"repoType": "github",
|
|
32
|
+
"repoHost": "https://github.com"
|
|
33
|
+
}
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Command.TS
|
|
2
2
|
|
|
3
|
+
[](https://github.com/pikokr/command.ts/actions/workflows/publish.yml)
|
|
4
|
+
|
|
3
5
|

|
|
4
6
|
|
|
5
7
|
Command framework for discord.js
|
|
@@ -37,18 +37,30 @@ class BuiltinCommandConverters extends BuiltInModule_1.BuiltInModule {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
user(msg, value) {
|
|
40
|
+
let user = this.client.users.cache.get(value);
|
|
41
|
+
if (user)
|
|
42
|
+
return user;
|
|
43
|
+
user = this.client.users.cache.find(x => x.tag === value);
|
|
44
|
+
if (user)
|
|
45
|
+
return user;
|
|
40
46
|
const id = this.getUserIDByMention(value);
|
|
41
47
|
if (!id)
|
|
42
48
|
return null;
|
|
43
|
-
|
|
49
|
+
user = this.client.users.cache.get(id);
|
|
44
50
|
return user || null;
|
|
45
51
|
}
|
|
46
52
|
member(msg, value) {
|
|
47
|
-
var _a;
|
|
53
|
+
var _a, _b, _c;
|
|
54
|
+
let user = (_a = msg.guild) === null || _a === void 0 ? void 0 : _a.members.cache.get(value);
|
|
55
|
+
if (!user)
|
|
56
|
+
return user;
|
|
57
|
+
user = (_b = msg.guild) === null || _b === void 0 ? void 0 : _b.members.cache.find(x => x.user.tag === value);
|
|
58
|
+
if (user)
|
|
59
|
+
return user;
|
|
48
60
|
const id = this.getUserIDByMention(value);
|
|
49
61
|
if (!id)
|
|
50
62
|
return;
|
|
51
|
-
|
|
63
|
+
user = (_c = msg.guild) === null || _c === void 0 ? void 0 : _c.members.cache.get(id);
|
|
52
64
|
return user || undefined;
|
|
53
65
|
}
|
|
54
66
|
number(msg, value) {
|
|
@@ -32,6 +32,9 @@ class CommandHandler extends BuiltInModule_1.BuiltInModule {
|
|
|
32
32
|
}
|
|
33
33
|
message(msg) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (!(yield this.client.options.command.check(msg))) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
35
38
|
const error = (error) => this.client.client.emit('commandError', error, msg);
|
|
36
39
|
try {
|
|
37
40
|
const prefixList = typeof this.client.options.command.prefix === 'string'
|
|
@@ -7,7 +7,7 @@ export declare class CommandCheckFailed extends Error {
|
|
|
7
7
|
constructor(msg: Message, command: Command);
|
|
8
8
|
}
|
|
9
9
|
export declare class SlashCommandCheckFailed extends Error {
|
|
10
|
-
|
|
10
|
+
interaction: CommandInteraction;
|
|
11
11
|
command: SlashCommand;
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(interaction: CommandInteraction, command: SlashCommand);
|
|
13
13
|
}
|
|
@@ -10,9 +10,9 @@ class CommandCheckFailed extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
exports.CommandCheckFailed = CommandCheckFailed;
|
|
12
12
|
class SlashCommandCheckFailed extends Error {
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(interaction, command) {
|
|
14
14
|
super();
|
|
15
|
-
this.
|
|
15
|
+
this.interaction = interaction;
|
|
16
16
|
this.command = command;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Registry } from './Registry';
|
|
2
|
-
import { Client, Snowflake } from 'discord.js';
|
|
2
|
+
import { Client, Message, Snowflake } from 'discord.js';
|
|
3
3
|
import { CoolDownAdapter } from '../command';
|
|
4
4
|
import { REST } from '@discordjs/rest';
|
|
5
5
|
export interface CommandOptions {
|
|
6
6
|
prefix: string | ((msg: any) => string | Promise<string | string[]> | string[]) | string[];
|
|
7
|
+
check: (msg: Message) => boolean | Promise<boolean>;
|
|
7
8
|
}
|
|
8
9
|
export interface SlashCommandOptions {
|
|
9
10
|
guild?: Snowflake | Snowflake[];
|
|
@@ -44,12 +44,16 @@ class CommandClient {
|
|
|
44
44
|
this.options = lodash_1.default.merge({
|
|
45
45
|
command: {
|
|
46
46
|
prefix: '!',
|
|
47
|
+
check: () => true
|
|
47
48
|
},
|
|
48
49
|
owners: 'auto',
|
|
49
50
|
slashCommands: {
|
|
50
51
|
autoSync: true,
|
|
51
52
|
},
|
|
52
53
|
}, options);
|
|
54
|
+
if (this.options.owners !== 'auto') {
|
|
55
|
+
this.owners = this.options.owners;
|
|
56
|
+
}
|
|
53
57
|
this.client.once('ready', () => this.ready());
|
|
54
58
|
this.registry.registerModule(new builtinModules_1.CommandHandler(this.registry));
|
|
55
59
|
this.registry.registerModule(new builtinModules_1.BuiltinCommandConverters(this));
|
package/package.json
CHANGED
|
@@ -34,17 +34,25 @@ export class BuiltinCommandConverters extends BuiltInModule {
|
|
|
34
34
|
|
|
35
35
|
@argumentConverter(User)
|
|
36
36
|
user(msg: Message, value: string): User | null {
|
|
37
|
+
let user = this.client.users.cache.get(value)
|
|
38
|
+
if (user) return user
|
|
39
|
+
user = this.client.users.cache.find(x=>x.tag === value)
|
|
40
|
+
if (user) return user
|
|
37
41
|
const id = this.getUserIDByMention(value)
|
|
38
42
|
if (!id) return null
|
|
39
|
-
|
|
43
|
+
user = this.client.users.cache.get(id)
|
|
40
44
|
return user || null
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
@argumentConverter(GuildMember)
|
|
44
48
|
member(msg: Message, value: string): GuildMember | undefined {
|
|
49
|
+
let user = msg.guild?.members.cache.get(value)
|
|
50
|
+
if (!user) return user
|
|
51
|
+
user = msg.guild?.members.cache.find(x=>x.user.tag===value)
|
|
52
|
+
if (user) return user
|
|
45
53
|
const id = this.getUserIDByMention(value)
|
|
46
54
|
if (!id) return
|
|
47
|
-
|
|
55
|
+
user = msg.guild?.members.cache.get(id)
|
|
48
56
|
return user || undefined
|
|
49
57
|
}
|
|
50
58
|
|
|
@@ -17,6 +17,10 @@ export class CommandHandler extends BuiltInModule {
|
|
|
17
17
|
|
|
18
18
|
@listener('messageCreate')
|
|
19
19
|
async message(msg: Message) {
|
|
20
|
+
if (!await this.client.options.command.check(msg)) {
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
const error = (error: Error) => this.client.client.emit('commandError', error, msg)
|
|
21
25
|
|
|
22
26
|
try {
|
|
@@ -9,7 +9,7 @@ export class CommandCheckFailed extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export class SlashCommandCheckFailed extends Error {
|
|
12
|
-
constructor(public
|
|
12
|
+
constructor(public interaction: CommandInteraction, public command: SlashCommand) {
|
|
13
13
|
super()
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import _ from 'lodash'
|
|
2
2
|
import { Registry } from './Registry'
|
|
3
|
-
import {
|
|
3
|
+
import {Client, Message, Snowflake, User} from 'discord.js'
|
|
4
4
|
import { BuiltinCommandConverters, BuiltinSlashCommandConverters, CommandHandler } from '../builtinModules'
|
|
5
5
|
import { CoolDownAdapter, DefaultCoolDownAdapter } from '../command'
|
|
6
6
|
import { REST } from '@discordjs/rest'
|
|
7
7
|
|
|
8
8
|
export interface CommandOptions {
|
|
9
9
|
prefix: string | ((msg: any) => string | Promise<string | string[]> | string[]) | string[]
|
|
10
|
+
check: (msg: Message) => boolean|Promise<boolean>
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface SlashCommandOptions {
|
|
@@ -64,6 +65,7 @@ export class CommandClient {
|
|
|
64
65
|
{
|
|
65
66
|
command: {
|
|
66
67
|
prefix: '!',
|
|
68
|
+
check: () => true
|
|
67
69
|
},
|
|
68
70
|
owners: 'auto',
|
|
69
71
|
slashCommands: {
|
|
@@ -72,6 +74,11 @@ export class CommandClient {
|
|
|
72
74
|
},
|
|
73
75
|
options,
|
|
74
76
|
)
|
|
77
|
+
|
|
78
|
+
if (this.options.owners !== 'auto') {
|
|
79
|
+
this.owners = this.options.owners
|
|
80
|
+
}
|
|
81
|
+
|
|
75
82
|
this.client.once('ready', () => this.ready())
|
|
76
83
|
this.registry.registerModule(new CommandHandler(this.registry))
|
|
77
84
|
this.registry.registerModule(new BuiltinCommandConverters(this))
|
package/test/modules/dev.ts
CHANGED
|
@@ -8,7 +8,7 @@ export class Dev extends BuiltInModule {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
@listener('slashCommandError')
|
|
11
|
-
|
|
11
|
+
slashError(e: Error, i: CommandInteraction) {
|
|
12
12
|
if (e instanceof SlashCommandCheckFailed) {
|
|
13
13
|
return i.reply({
|
|
14
14
|
content: 'Command before-run check failed',
|