@sapphire/plugin-subcommands 2.2.1-next.ffb97f6.0 → 3.0.0-pr-271.cde343c3.0
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/README.md +47 -16
- package/dist/index.d.ts +3 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -4
- package/dist/lib/Subcommand.d.ts +18 -0
- package/dist/lib/Subcommand.d.ts.map +1 -0
- package/dist/lib/Subcommand.js +172 -0
- package/dist/lib/Subcommand.js.map +1 -0
- package/dist/lib/SubcommandMappings.d.ts +94 -0
- package/dist/lib/SubcommandMappings.d.ts.map +1 -0
- package/dist/lib/SubcommandMappings.js +100 -0
- package/dist/lib/SubcommandMappings.js.map +1 -0
- package/dist/lib/types/Events.d.ts +94 -0
- package/dist/lib/types/Events.d.ts.map +1 -0
- package/dist/lib/types/Events.js +22 -0
- package/dist/lib/types/Events.js.map +1 -0
- package/package.json +2 -2
- package/dist/lib/SubCommandEntry.d.ts +0 -44
- package/dist/lib/SubCommandEntry.d.ts.map +0 -1
- package/dist/lib/SubCommandEntry.js +0 -38
- package/dist/lib/SubCommandEntry.js.map +0 -1
- package/dist/lib/SubCommandEntryCommand.d.ts +0 -17
- package/dist/lib/SubCommandEntryCommand.d.ts.map +0 -1
- package/dist/lib/SubCommandEntryCommand.js +0 -26
- package/dist/lib/SubCommandEntryCommand.js.map +0 -1
- package/dist/lib/SubCommandEntryMethod.d.ts +0 -31
- package/dist/lib/SubCommandEntryMethod.d.ts.map +0 -1
- package/dist/lib/SubCommandEntryMethod.js +0 -39
- package/dist/lib/SubCommandEntryMethod.js.map +0 -1
- package/dist/lib/SubCommandManager.d.ts +0 -20
- package/dist/lib/SubCommandManager.d.ts.map +0 -1
- package/dist/lib/SubCommandManager.js +0 -68
- package/dist/lib/SubCommandManager.js.map +0 -1
- package/dist/lib/SubCommandPluginCommand.d.ts +0 -26
- package/dist/lib/SubCommandPluginCommand.d.ts.map +0 -1
- package/dist/lib/SubCommandPluginCommand.js +0 -24
- package/dist/lib/SubCommandPluginCommand.js.map +0 -1
package/README.md
CHANGED
|
@@ -45,27 +45,44 @@ npm install @sapphire/plugin-subcommands @sapphire/framework @sapphire/utilities
|
|
|
45
45
|
_With TypeScript:_
|
|
46
46
|
|
|
47
47
|
```typescript
|
|
48
|
-
import {
|
|
48
|
+
import {
|
|
49
|
+
SubCommandPluginCommand,
|
|
50
|
+
MessageSubcommandMappings,
|
|
51
|
+
ChatInputSubcommandMappings,
|
|
52
|
+
SubcommandMappingsArray
|
|
53
|
+
} from '@sapphire/plugin-subcommands';
|
|
49
54
|
import { ApplyOptions } from '@sapphire/decorators';
|
|
50
55
|
import type { Args } from '@sapphire/framework';
|
|
51
|
-
import type { Message } from 'discord.js';
|
|
56
|
+
import type { Message, CommandInteraction } from 'discord.js';
|
|
52
57
|
|
|
53
58
|
// Using ApplyOptions decorator makes it easy to configure
|
|
54
59
|
@ApplyOptions<SubCommandPluginCommand.Options>({
|
|
55
|
-
|
|
60
|
+
subcommands: [
|
|
61
|
+
new MessageSubcommandMappings([
|
|
62
|
+
{ name: 'add', to: 'messageAdd' },
|
|
63
|
+
{ name: 'remove', to: 'messageRemove' },
|
|
64
|
+
{ name: 'list', to: 'messageList', default: true }
|
|
65
|
+
]),
|
|
66
|
+
new ChatInputSubcommandMappings([
|
|
67
|
+
{ name: 'add', to: 'chatInputAdd' },
|
|
68
|
+
{ name: 'remove', to: 'chatInputRemove' },
|
|
69
|
+
{ name: 'list', to: 'chatInputList' }
|
|
70
|
+
])
|
|
71
|
+
]
|
|
56
72
|
})
|
|
57
73
|
// Extend `SubCommandPluginCommand` instead of `Command`
|
|
58
74
|
export class UserCommand extends SubCommandPluginCommand {
|
|
59
|
-
|
|
60
|
-
public async add(message: Message, args: Args) {}
|
|
75
|
+
public async messageAdd(message: Message, args: Args) {}
|
|
61
76
|
|
|
62
|
-
public async
|
|
77
|
+
public async messageRemove(message: Message, args: Args) {}
|
|
63
78
|
|
|
64
|
-
public async
|
|
79
|
+
public async messageList(message: Message, args: Args) {}
|
|
65
80
|
|
|
66
|
-
public async
|
|
81
|
+
public async chatInputAdd(interaction: CommandInteraction) {}
|
|
67
82
|
|
|
68
|
-
public async
|
|
83
|
+
public async chatInputRemove(interaction: CommandInteraction) {}
|
|
84
|
+
|
|
85
|
+
public async chatInputList(interaction: CommandInteraction) {}
|
|
69
86
|
}
|
|
70
87
|
```
|
|
71
88
|
|
|
@@ -79,23 +96,37 @@ module.exports = class UserCommand extends SubCommandPluginCommand {
|
|
|
79
96
|
constructor(context, options) {
|
|
80
97
|
super(context, {
|
|
81
98
|
...options,
|
|
82
|
-
|
|
99
|
+
subcommands: [
|
|
100
|
+
new MessageSubcommandMappings([
|
|
101
|
+
{ name: 'add', to: 'messageAdd' },
|
|
102
|
+
{ name: 'remove', to: 'messageRemove' },
|
|
103
|
+
{ name: 'list', to: 'messageList', default: true }
|
|
104
|
+
]),
|
|
105
|
+
new ChatInputSubcommandMappings([
|
|
106
|
+
{ name: 'add', to: 'chatInputAdd' },
|
|
107
|
+
{ name: 'remove', to: 'chatInputRemove' },
|
|
108
|
+
{ name: 'list', to: 'chatInputList' }
|
|
109
|
+
])
|
|
110
|
+
]
|
|
83
111
|
});
|
|
84
112
|
}
|
|
85
113
|
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
async messageAdd(message, args) {}
|
|
115
|
+
|
|
116
|
+
async messageRemove(message, args) {}
|
|
88
117
|
|
|
89
|
-
async
|
|
118
|
+
async messageList(message, args) {}
|
|
90
119
|
|
|
91
|
-
async
|
|
120
|
+
async chatInputAdd(interaction) {}
|
|
92
121
|
|
|
93
|
-
async
|
|
122
|
+
async chatInputRemove(interaction) {}
|
|
94
123
|
|
|
95
|
-
async
|
|
124
|
+
async chatInputList(interaction) {}
|
|
96
125
|
};
|
|
97
126
|
```
|
|
98
127
|
|
|
128
|
+
For more documentation please refer to [guide](https://www.sapphirejs.dev/docs/Guide/plugins/Subcommands/getting-started)
|
|
129
|
+
|
|
99
130
|
## Buy us some doughnuts
|
|
100
131
|
|
|
101
132
|
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
export * from './lib/
|
|
2
|
-
export * from './lib/
|
|
3
|
-
export * from './lib/
|
|
4
|
-
export * from './lib/SubCommandManager';
|
|
5
|
-
export * from './lib/SubCommandPluginCommand';
|
|
6
|
-
declare module '@sapphire/framework' {
|
|
7
|
-
const enum Identifiers {
|
|
8
|
-
SubCommandNoMatch = "subCommandNoMatch"
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
export * from './lib/types/Events';
|
|
2
|
+
export * from './lib/Subcommand';
|
|
3
|
+
export * from './lib/SubcommandMappings';
|
|
11
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./lib/
|
|
5
|
-
tslib_1.__exportStar(require("./lib/
|
|
6
|
-
tslib_1.__exportStar(require("./lib/
|
|
7
|
-
tslib_1.__exportStar(require("./lib/SubCommandManager"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./lib/SubCommandPluginCommand"), exports);
|
|
4
|
+
tslib_1.__exportStar(require("./lib/types/Events"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/Subcommand"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/SubcommandMappings"), exports);
|
|
9
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,2DAAiC;AACjC,mEAAyC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import mod from "./index.js";
|
|
2
2
|
|
|
3
3
|
export default mod;
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
4
|
+
export const ChatInputSubcommandGroupMappings = mod.ChatInputSubcommandGroupMappings;
|
|
5
|
+
export const ChatInputSubcommandMappings = mod.ChatInputSubcommandMappings;
|
|
6
|
+
export const MessageSubcommandGroupMappings = mod.MessageSubcommandGroupMappings;
|
|
7
|
+
export const MessageSubcommandMappings = mod.MessageSubcommandMappings;
|
|
8
8
|
export const SubCommandPluginCommand = mod.SubCommandPluginCommand;
|
|
9
|
+
export const SubcommandPluginEvents = mod.SubcommandPluginEvents;
|
|
10
|
+
export const SubcommandPluginIdentifiers = mod.SubcommandPluginIdentifiers;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Args, Command, type PieceContext, type ChatInputCommand, type MessageCommand } from '@sapphire/framework';
|
|
2
|
+
import type { Message } from 'discord.js';
|
|
3
|
+
import { type SubcommandMappingsArray } from './SubcommandMappings';
|
|
4
|
+
export declare class SubCommandPluginCommand<PreParseReturn extends Args = Args, O extends SubCommandPluginCommand.Options = SubCommandPluginCommand.Options> extends Command<PreParseReturn, O> {
|
|
5
|
+
#private;
|
|
6
|
+
private subcommandsInternalMapping;
|
|
7
|
+
constructor(context: PieceContext, options: O);
|
|
8
|
+
onLoad(): void;
|
|
9
|
+
messageRun(message: Message, args: PreParseReturn, context: MessageCommand.RunContext): Promise<void>;
|
|
10
|
+
chatInputRun(interaction: ChatInputCommand.Interaction, context: ChatInputCommand.RunContext): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export interface SubcommandPluginCommandOptions extends Command.Options {
|
|
13
|
+
subcommands?: SubcommandMappingsArray;
|
|
14
|
+
}
|
|
15
|
+
export declare namespace SubCommandPluginCommand {
|
|
16
|
+
type Options = SubcommandPluginCommandOptions;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Subcommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subcommand.d.ts","sourceRoot":"","sources":["../../src/lib/Subcommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,IAAI,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAa,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrJ,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAQN,KAAK,uBAAuB,EAE5B,MAAM,sBAAsB,CAAC;AAQ9B,qBAAa,uBAAuB,CACnC,cAAc,SAAS,IAAI,GAAG,IAAI,EAClC,CAAC,SAAS,uBAAuB,CAAC,OAAO,GAAG,uBAAuB,CAAC,OAAO,CAC1E,SAAQ,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;;IACnC,OAAO,CAAC,0BAA0B,CAA0B;gBAEzC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;IAK7C,MAAM;IAWA,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,CAAC,UAAU;IA8BrF,YAAY,CAAC,WAAW,EAAE,gBAAgB,CAAC,WAAW,EAAE,OAAO,EAAE,gBAAgB,CAAC,UAAU;CA0IzG;AAED,MAAM,WAAW,8BAA+B,SAAQ,OAAO,CAAC,OAAO;IACtE,WAAW,CAAC,EAAE,uBAAuB,CAAC;CACtC;AAED,yBAAiB,uBAAuB,CAAC;IACxC,KAAY,OAAO,GAAG,8BAA8B,CAAC;CACrD"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _SubCommandPluginCommand_instances, _SubCommandPluginCommand_handleInteractionRun, _SubCommandPluginCommand_handleMessageRun;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SubCommandPluginCommand = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const framework_1 = require("@sapphire/framework");
|
|
7
|
+
const SubcommandMappings_1 = require("./SubcommandMappings");
|
|
8
|
+
const Events_1 = require("./types/Events");
|
|
9
|
+
class SubCommandPluginCommand extends framework_1.Command {
|
|
10
|
+
constructor(context, options) {
|
|
11
|
+
super(context, options);
|
|
12
|
+
_SubCommandPluginCommand_instances.add(this);
|
|
13
|
+
Object.defineProperty(this, "subcommandsInternalMapping", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
this.subcommandsInternalMapping = options.subcommands ?? [];
|
|
20
|
+
}
|
|
21
|
+
onLoad() {
|
|
22
|
+
super.onLoad();
|
|
23
|
+
const externalMapping = Reflect.get(this, 'subcommandMappings');
|
|
24
|
+
if (externalMapping) {
|
|
25
|
+
const subcommands = Array.isArray(externalMapping) ? externalMapping : [];
|
|
26
|
+
this.subcommandsInternalMapping = subcommands;
|
|
27
|
+
this.options.subcommands = subcommands;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async messageRun(message, args, context) {
|
|
31
|
+
args.save();
|
|
32
|
+
const subcommandOrGroup = args.nextMaybe();
|
|
33
|
+
const subcommandName = args.nextMaybe();
|
|
34
|
+
let defaultCommmand = null;
|
|
35
|
+
for (const mapping of this.subcommandsInternalMapping) {
|
|
36
|
+
if (mapping instanceof SubcommandMappings_1.MessageSubcommandMappings && subcommandOrGroup.exists) {
|
|
37
|
+
defaultCommmand = mapping.subcommands.find((s) => s.default === true) ?? null;
|
|
38
|
+
const subcommand = mapping.subcommands.find(({ name }) => name === subcommandOrGroup.value);
|
|
39
|
+
if (subcommand)
|
|
40
|
+
return tslib_1.__classPrivateFieldGet(this, _SubCommandPluginCommand_instances, "m", _SubCommandPluginCommand_handleMessageRun).call(this, message, args, context, subcommand);
|
|
41
|
+
}
|
|
42
|
+
if (mapping instanceof SubcommandMappings_1.MessageSubcommandGroupMappings && mapping.groupName === subcommandOrGroup.value) {
|
|
43
|
+
defaultCommmand = mapping.subcommands.find((s) => s.default === true) ?? null;
|
|
44
|
+
const subcommand = mapping.subcommands.find(({ name }) => name === subcommandName.value);
|
|
45
|
+
if (subcommand)
|
|
46
|
+
return tslib_1.__classPrivateFieldGet(this, _SubCommandPluginCommand_instances, "m", _SubCommandPluginCommand_handleMessageRun).call(this, message, args, context, subcommand);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// No subcommand matched, let's restore and try to run default, if any:
|
|
50
|
+
args.restore();
|
|
51
|
+
if (defaultCommmand)
|
|
52
|
+
return tslib_1.__classPrivateFieldGet(this, _SubCommandPluginCommand_instances, "m", _SubCommandPluginCommand_handleMessageRun).call(this, message, args, context, defaultCommmand);
|
|
53
|
+
// No match and no subcommand, return an err:
|
|
54
|
+
throw new framework_1.UserError({ identifier: "messageSubcommandNoMatch" /* MessageSubcommandNoMatch */, context });
|
|
55
|
+
}
|
|
56
|
+
async chatInputRun(interaction, context) {
|
|
57
|
+
const subcommandName = interaction.options.getSubcommand(false);
|
|
58
|
+
const subcommandGroupName = interaction.options.getSubcommandGroup(false);
|
|
59
|
+
for (const mapping of this.subcommandsInternalMapping) {
|
|
60
|
+
if (mapping instanceof SubcommandMappings_1.ChatInputSubcommandMappings && subcommandName && !subcommandGroupName) {
|
|
61
|
+
const subcommand = mapping.subcommands.find(({ name }) => name === subcommandName);
|
|
62
|
+
if (subcommand)
|
|
63
|
+
return tslib_1.__classPrivateFieldGet(this, _SubCommandPluginCommand_instances, "m", _SubCommandPluginCommand_handleInteractionRun).call(this, interaction, context, subcommand);
|
|
64
|
+
}
|
|
65
|
+
if (mapping instanceof SubcommandMappings_1.ChatInputSubcommandGroupMappings && subcommandGroupName && mapping.groupName === subcommandGroupName) {
|
|
66
|
+
const subcommand = mapping.subcommands.find(({ name }) => name === subcommandName);
|
|
67
|
+
if (subcommand)
|
|
68
|
+
return tslib_1.__classPrivateFieldGet(this, _SubCommandPluginCommand_instances, "m", _SubCommandPluginCommand_handleInteractionRun).call(this, interaction, context, subcommand);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// No match and no subcommand, return an err:
|
|
72
|
+
throw new framework_1.UserError({ identifier: "chatInputSubcommandNoMatch" /* ChatInputSubcommandNoMatch */, context });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.SubCommandPluginCommand = SubCommandPluginCommand;
|
|
76
|
+
_SubCommandPluginCommand_instances = new WeakSet(), _SubCommandPluginCommand_handleInteractionRun = async function _SubCommandPluginCommand_handleInteractionRun(interaction, context, subcommand) {
|
|
77
|
+
const payload = { command: this, context, interaction };
|
|
78
|
+
const result = await (0, framework_1.fromAsync)(async () => {
|
|
79
|
+
interaction.client.emit(Events_1.SubcommandPluginEvents.ChatInputSubcommandRun, interaction, subcommand, payload);
|
|
80
|
+
subcommand.type ?? (subcommand.type = 'method');
|
|
81
|
+
let result;
|
|
82
|
+
if (subcommand.type === 'command') {
|
|
83
|
+
const parsedCommandName = subcommand.to && typeof subcommand.to === 'string' ? subcommand.to : subcommand.name;
|
|
84
|
+
const command = this.container.stores.get('commands').get(parsedCommandName);
|
|
85
|
+
if (!command?.supportsChatInputCommands())
|
|
86
|
+
throw new framework_1.UserError({ identifier: "subcommandNotFound" /* SubcommandNotFound */, context: { ...payload } });
|
|
87
|
+
// Run global preconditions:
|
|
88
|
+
const globalResult = await this.container.stores
|
|
89
|
+
.get('preconditions')
|
|
90
|
+
.chatInputRun(interaction, command, context);
|
|
91
|
+
if (!globalResult.success) {
|
|
92
|
+
this.container.client.emit(Events_1.SubcommandPluginEvents.ChatInputSubcommandDenied, globalResult.error, { ...payload, subcommand });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Run command-specific preconditions:
|
|
96
|
+
const localResult = await command.preconditions.chatInputRun(interaction, command, context);
|
|
97
|
+
if (!localResult.success) {
|
|
98
|
+
this.container.client.emit(Events_1.SubcommandPluginEvents.ChatInputSubcommandDenied, localResult.error, { ...payload, subcommand });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
result = await command.chatInputRun(interaction, context);
|
|
102
|
+
}
|
|
103
|
+
if (subcommand.type === 'method' && subcommand.to) {
|
|
104
|
+
if (typeof subcommand.to === 'string') {
|
|
105
|
+
const method = Reflect.get(this, subcommand.to);
|
|
106
|
+
if (!method)
|
|
107
|
+
throw new framework_1.UserError({ identifier: "subcommandNotFound" /* SubcommandNotFound */, context: { ...payload } });
|
|
108
|
+
result = await Reflect.apply(method, this, [interaction, context]);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
result = await subcommand.to(interaction, context);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
interaction.client.emit(Events_1.SubcommandPluginEvents.ChatInputSubcommandSuccess, interaction, subcommand, { ...payload, result });
|
|
115
|
+
});
|
|
116
|
+
if ((0, framework_1.isErr)(result)) {
|
|
117
|
+
interaction.client.emit(Events_1.SubcommandPluginEvents.ChatInputSubcommandError, result.error, payload);
|
|
118
|
+
}
|
|
119
|
+
}, _SubCommandPluginCommand_handleMessageRun = async function _SubCommandPluginCommand_handleMessageRun(message, args, context, subcommand) {
|
|
120
|
+
const payload = { message, command: this, context };
|
|
121
|
+
const result = await (0, framework_1.fromAsync)(async () => {
|
|
122
|
+
message.client.emit(Events_1.SubcommandPluginEvents.MessageSubcommandRun, message, subcommand, payload);
|
|
123
|
+
subcommand.type ?? (subcommand.type = 'method');
|
|
124
|
+
let result;
|
|
125
|
+
if (subcommand.type === 'command') {
|
|
126
|
+
const parsedCommandName = subcommand.to && typeof subcommand.to === 'string' ? subcommand.to : subcommand.name;
|
|
127
|
+
const command = this.container.stores.get('commands').get(parsedCommandName);
|
|
128
|
+
if (!command?.supportsMessageCommands())
|
|
129
|
+
throw new framework_1.UserError({ identifier: "subcommandNotFound" /* SubcommandNotFound */, context: { ...payload } });
|
|
130
|
+
const prefixLess = message.content.slice(context.commandPrefix.length).trim();
|
|
131
|
+
const spaceIndex = prefixLess.indexOf(' ');
|
|
132
|
+
const parameters = spaceIndex === -1 ? '' : prefixLess.substring(spaceIndex + 1).trim();
|
|
133
|
+
// Run global preconditions:
|
|
134
|
+
const globalResult = await this.container.stores.get('preconditions').messageRun(message, command, payload);
|
|
135
|
+
if (!globalResult.success) {
|
|
136
|
+
this.container.client.emit(Events_1.SubcommandPluginEvents.MessageSubcommandDenied, globalResult.error, {
|
|
137
|
+
...payload,
|
|
138
|
+
parameters,
|
|
139
|
+
subcommand
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// Run command-specific preconditions:
|
|
144
|
+
const localResult = await command.preconditions.messageRun(message, command, context);
|
|
145
|
+
if (!localResult.success) {
|
|
146
|
+
this.container.client.emit(Events_1.SubcommandPluginEvents.MessageSubcommandDenied, localResult.error, {
|
|
147
|
+
...payload,
|
|
148
|
+
parameters,
|
|
149
|
+
subcommand
|
|
150
|
+
});
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
result = await command.messageRun(message, args, context);
|
|
154
|
+
}
|
|
155
|
+
if (subcommand.type === 'method' && subcommand.to) {
|
|
156
|
+
if (typeof subcommand.to === 'string') {
|
|
157
|
+
const method = Reflect.get(this, subcommand.to);
|
|
158
|
+
if (!method)
|
|
159
|
+
throw new framework_1.UserError({ identifier: "subcommandNotFound" /* SubcommandNotFound */, context: { ...payload } });
|
|
160
|
+
result = await Reflect.apply(method, this, [message, args, context]);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
result = await subcommand.to(message, args, context);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
message.client.emit(Events_1.SubcommandPluginEvents.MessageSubcommandSuccess, message, subcommand, { ...payload, result });
|
|
167
|
+
});
|
|
168
|
+
if ((0, framework_1.isErr)(result)) {
|
|
169
|
+
message.client.emit(Events_1.SubcommandPluginEvents.MessageSubcommandError, result.error, payload);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=Subcommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subcommand.js","sourceRoot":"","sources":["../../src/lib/Subcommand.ts"],"names":[],"mappings":";;;;;AAAA,mDAAqJ;AAErJ,6DAU8B;AAC9B,2CAKwB;AAExB,MAAa,uBAGX,SAAQ,mBAA0B;IAGnC,YAAmB,OAAqB,EAAE,OAAU;QACnD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;;QAHzB;;;;;WAA4D;QAI3D,IAAI,CAAC,0BAA0B,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;IAC7D,CAAC;IAEM,MAAM;QACZ,KAAK,CAAC,MAAM,EAAE,CAAC;QAEf,MAAM,eAAe,GAAwC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;QACrG,IAAI,eAAe,EAAE;YACpB,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1E,IAAI,CAAC,0BAA0B,GAAG,WAAW,CAAC;YAC9C,IAAI,CAAC,OAAO,CA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gBACH,OAAO;aACP;YAED,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;SAC1D;QAED,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,IAAI,UAAU,CAAC,EAAE,EAAE;YAClD,IAAI,OAAO,UAAU,CAAC,EAAE,KAAK,QAAQ,EAAE;gBACtC,MAAM,MAAM,GAA4C,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;gBACzF,IAAI,CAAC,MAAM;oBAAE,MAAM,IAAI,qBAAS,CAAC,EAAE,UAAU,+CAAgD,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC,CAAC;gBAE1H,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;aACrE;iBAAM;gBACN,MAAM,GAAG,MAAM,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;aACrD;SACD;QAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,+BAAsB,CAAC,wBAAwB,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACnH,CAAC,CAAC,CAAC;IAEH,IAAI,IAAA,iBAAK,EAAC,MAAM,CAAC,EAAE;QAClB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,+BAAsB,CAAC,sBAAsB,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KAC1F;AACF,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Args, Awaitable, ChatInputCommand, MessageCommand } from '@sapphire/framework';
|
|
2
|
+
import type { Message } from 'discord.js';
|
|
3
|
+
export declare type SubcommandMappingsArray = (ChatInputSubcommandGroupMappings | ChatInputSubcommandMappings | MessageSubcommandMappings | MessageSubcommandGroupMappings)[];
|
|
4
|
+
export declare type ChatInputSubcommandToProperty = (interaction: ChatInputCommand.Interaction, context: ChatInputCommand.RunContext) => Awaitable<unknown>;
|
|
5
|
+
export declare type MessageSubcommandToProperty = (message: Message, args: Args, context: MessageCommand.RunContext) => Awaitable<unknown>;
|
|
6
|
+
export declare type SubcommandType = 'method' | 'command';
|
|
7
|
+
export declare class ChatInputSubcommandGroupMappings {
|
|
8
|
+
/**
|
|
9
|
+
* Name of the subcommand group
|
|
10
|
+
*/
|
|
11
|
+
groupName: string;
|
|
12
|
+
/**
|
|
13
|
+
* Subcommands for this command with groups
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* /config mod-roles add role
|
|
17
|
+
* command group subcommand option
|
|
18
|
+
*/
|
|
19
|
+
subcommands: ChatInputSubcommandMappingValue[];
|
|
20
|
+
constructor(groupName: string, mappings: ChatInputSubcommandMappingValue[]);
|
|
21
|
+
}
|
|
22
|
+
export declare class MessageSubcommandGroupMappings {
|
|
23
|
+
/**
|
|
24
|
+
* Name of the subcommand group
|
|
25
|
+
*/
|
|
26
|
+
groupName: string;
|
|
27
|
+
/**
|
|
28
|
+
* Subcommands for this command with groups
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* !config mod-roles add role
|
|
32
|
+
* command group subcommand option
|
|
33
|
+
*/
|
|
34
|
+
subcommands: MessageSubcommandMappingValue[];
|
|
35
|
+
constructor(groupName: string, mappings: MessageSubcommandMappingValue[]);
|
|
36
|
+
}
|
|
37
|
+
export declare class ChatInputSubcommandMappings {
|
|
38
|
+
/**
|
|
39
|
+
* Subcommands for this Command
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* /config language en-US
|
|
43
|
+
* command subcommand option
|
|
44
|
+
*/
|
|
45
|
+
subcommands: ChatInputSubcommandMappingValue[];
|
|
46
|
+
constructor(subcommands: ChatInputSubcommandMappingValue[]);
|
|
47
|
+
}
|
|
48
|
+
export declare class MessageSubcommandMappings {
|
|
49
|
+
/**
|
|
50
|
+
* Subcommands for this Command
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* !config language en-US
|
|
54
|
+
* command subcommand option
|
|
55
|
+
*/
|
|
56
|
+
subcommands: MessageSubcommandMappingValue[];
|
|
57
|
+
constructor(subcommands: MessageSubcommandMappingValue[]);
|
|
58
|
+
}
|
|
59
|
+
export interface SubCommandMappingValueBase {
|
|
60
|
+
/**
|
|
61
|
+
* Name of the Subcommand
|
|
62
|
+
*
|
|
63
|
+
* @since 3.0.0
|
|
64
|
+
*/
|
|
65
|
+
name: string;
|
|
66
|
+
/**
|
|
67
|
+
* Select whether you want to execute a command class method or a command registered in the store.
|
|
68
|
+
* @since 3.0.0
|
|
69
|
+
*/
|
|
70
|
+
type?: SubcommandType;
|
|
71
|
+
}
|
|
72
|
+
export interface ChatInputSubcommandMappingValue extends SubCommandMappingValueBase {
|
|
73
|
+
/**
|
|
74
|
+
* The method or name used used to run the subcommand
|
|
75
|
+
*
|
|
76
|
+
* @since 3.0.0
|
|
77
|
+
*/
|
|
78
|
+
to?: ChatInputSubcommandToProperty | string;
|
|
79
|
+
}
|
|
80
|
+
export interface MessageSubcommandMappingValue extends SubCommandMappingValueBase {
|
|
81
|
+
/**
|
|
82
|
+
* The method or name used used to run the subcommand
|
|
83
|
+
*
|
|
84
|
+
* @since 3.0.0
|
|
85
|
+
*/
|
|
86
|
+
to?: MessageSubcommandToProperty | string;
|
|
87
|
+
/**
|
|
88
|
+
* Should this command be ran if no input is given
|
|
89
|
+
*
|
|
90
|
+
* @since 3.0.0
|
|
91
|
+
*/
|
|
92
|
+
default?: boolean;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=SubcommandMappings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubcommandMappings.d.ts","sourceRoot":"","sources":["../../src/lib/SubcommandMappings.ts"],"names":[],"mapp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AA0B;IAC1C;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,+BAAgC,SAAQ,0BAA0B;IAClF;;;;OAIG;IACH,EAAE,CAAC,EAAE,6BAA6B,GAAG,MAAM,CAAC;CAC5C;AAED,MAAM,WAAW,6BAA8B,SAAQ,0BAA0B;IAChF;;;;OAIG;IACH,EAAE,CAAC,EAAE,2BAA2B,GAAG,MAAM,CAAC;IAE1C;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageSubcommandMappings = exports.ChatInputSubcommandMappings = exports.MessageSubcommandGroupMappings = exports.ChatInputSubcommandGroupMappings = void 0;
|
|
4
|
+
class ChatInputSubcommandGroupMappings {
|
|
5
|
+
constructor(groupName, mappings) {
|
|
6
|
+
/**
|
|
7
|
+
* Name of the subcommand group
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(this, "groupName", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: void 0
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Subcommands for this command with groups
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* /config mod-roles add role
|
|
20
|
+
* command group subcommand option
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(this, "subcommands", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
this.groupName = groupName;
|
|
29
|
+
this.subcommands = mappings;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ChatInputSubcommandGroupMappings = ChatInputSubcommandGroupMappings;
|
|
33
|
+
class MessageSubcommandGroupMappings {
|
|
34
|
+
constructor(groupName, mappings) {
|
|
35
|
+
/**
|
|
36
|
+
* Name of the subcommand group
|
|
37
|
+
*/
|
|
38
|
+
Object.defineProperty(this, "groupName", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: void 0
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Subcommands for this command with groups
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* !config mod-roles add role
|
|
49
|
+
* command group subcommand option
|
|
50
|
+
*/
|
|
51
|
+
Object.defineProperty(this, "subcommands", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
this.groupName = groupName;
|
|
58
|
+
this.subcommands = mappings;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.MessageSubcommandGroupMappings = MessageSubcommandGroupMappings;
|
|
62
|
+
class ChatInputSubcommandMappings {
|
|
63
|
+
constructor(subcommands) {
|
|
64
|
+
/**
|
|
65
|
+
* Subcommands for this Command
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* /config language en-US
|
|
69
|
+
* command subcommand option
|
|
70
|
+
*/
|
|
71
|
+
Object.defineProperty(this, "subcommands", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: void 0
|
|
76
|
+
});
|
|
77
|
+
this.subcommands = subcommands;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.ChatInputSubcommandMappings = ChatInputSubcommandMappings;
|
|
81
|
+
class MessageSubcommandMappings {
|
|
82
|
+
constructor(subcommands) {
|
|
83
|
+
/**
|
|
84
|
+
* Subcommands for this Command
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* !config language en-US
|
|
88
|
+
* command subcommand option
|
|
89
|
+
*/
|
|
90
|
+
Object.defineProperty(this, "subcommands", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: void 0
|
|
95
|
+
});
|
|
96
|
+
this.subcommands = subcommands;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.MessageSubcommandMappings = MessageSubcommandMappings;
|
|
100
|
+
//# sourceMappingURL=SubcommandMappings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubcommandMappings.js","sourceRoot":"","sources":["../../src/lib/SubcommandMappings.ts"],"names":[],"mappings":";;;AAaA,MAAa,gCAAgC;IAe5C,YAAmB,SAAiB,EAAE,QAA2C;QAdjF;;WAEG;QACH;;;;;WAAyB;QAEzB;;;;;;WAMG;QACH;;;;;WAAsD;QAGrD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACD;AAnBD,4EAmBC;AAED,MAAa,8BAA8B;IAe1C,YAAmB,SAAiB,EAAE,QAAyC;QAd/E;;WAEG;QACH;;;;;WAAyB;QAEzB;;;;;;WAMG;QACH;;;;;WAAoD;QAGnD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACD;AAnBD,wEAmBC;AAED,MAAa,2BAA2B;IAUvC,YAAmB,WAA8C;QATjE;;;;;;WAMG;QACH;;;;;WAAsD;QAGrD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IAChC,CAAC;CACD;AAbD,kEAaC;AAED,MAAa,yBAAyB;IAUrC,YAAmB,WAA4C;QAT/D;;;;;;WAMG;QACH;;;;;WAAoD;QAGnD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IAChC,CAAC;CACD;AAbD,8DAaC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ChatInputCommand, MessageCommand, UserError } from '@sapphire/framework';
|
|
2
|
+
import type { Message } from 'discord.js';
|
|
3
|
+
import type { ChatInputSubcommandMappingValue, MessageSubcommandMappingValue } from '../SubcommandMappings';
|
|
4
|
+
export declare const SubcommandPluginEvents: {
|
|
5
|
+
ChatInputSubcommandRun: "chatInputSubcommandRun";
|
|
6
|
+
ChatInputSubcommandSuccess: "chatInputSubcommandSuccess";
|
|
7
|
+
ChatInputSubcommandNotFound: "chatInputSubcommandNotFound";
|
|
8
|
+
ChatInputSubcommandDenied: "chatInputSubcommandDenied";
|
|
9
|
+
ChatInputSubcommandError: "chatInputSubcommandError";
|
|
10
|
+
MessageSubcommandRun: "messageSubcommandRun";
|
|
11
|
+
MessageSubcommandSuccess: "messageSubcommandSuccess";
|
|
12
|
+
MessageSubcommandNotFound: "messageSubcommandNotFound";
|
|
13
|
+
MessageSubcommandDenied: "messageSubcommandDenied";
|
|
14
|
+
MessageSubcommandError: "messageSubcommandError";
|
|
15
|
+
};
|
|
16
|
+
export declare const enum SubcommandPluginIdentifiers {
|
|
17
|
+
MessageSubcommandNoMatch = "messageSubcommandNoMatch",
|
|
18
|
+
ChatInputSubcommandNoMatch = "chatInputSubcommandNoMatch",
|
|
19
|
+
SubcommandNotFound = "subcommandNotFound"
|
|
20
|
+
}
|
|
21
|
+
export interface IMessageSubcommandPayload {
|
|
22
|
+
message: Message;
|
|
23
|
+
command: MessageCommand;
|
|
24
|
+
}
|
|
25
|
+
export interface MessageSubcommandAcceptedPayload extends IMessageSubcommandPayload {
|
|
26
|
+
context: MessageCommand.RunContext;
|
|
27
|
+
}
|
|
28
|
+
export interface MessageSubcommandRunPayload extends MessageSubcommandAcceptedPayload {
|
|
29
|
+
}
|
|
30
|
+
export interface MessageSubcommandErrorPayload extends MessageSubcommandRunPayload {
|
|
31
|
+
}
|
|
32
|
+
export interface MessageSubcommandDeniedPayload extends MessageSubcommandRunPayload {
|
|
33
|
+
parameters: string;
|
|
34
|
+
subcommand: MessageSubcommandMappingValue;
|
|
35
|
+
}
|
|
36
|
+
export interface MessageSubcommandSuccessPayload extends MessageSubcommandRunPayload {
|
|
37
|
+
result: unknown;
|
|
38
|
+
}
|
|
39
|
+
export interface IChatInputSubcommandPayload {
|
|
40
|
+
interaction: ChatInputCommand.Interaction;
|
|
41
|
+
command: ChatInputCommand;
|
|
42
|
+
}
|
|
43
|
+
export interface ChatInputSubcommandAcceptedPayload extends IChatInputSubcommandPayload {
|
|
44
|
+
context: ChatInputCommand.RunContext;
|
|
45
|
+
}
|
|
46
|
+
export interface ChatInputSubcommandRunPayload extends ChatInputSubcommandAcceptedPayload {
|
|
47
|
+
}
|
|
48
|
+
export interface ChatInputSubcommandErrorPayload extends ChatInputSubcommandRunPayload {
|
|
49
|
+
}
|
|
50
|
+
export interface ChatInputSubcommandDeniedPayload extends ChatInputSubcommandRunPayload {
|
|
51
|
+
subcommand: ChatInputSubcommandMappingValue;
|
|
52
|
+
}
|
|
53
|
+
export interface ChatInputSubcommandSuccessPayload extends ChatInputSubcommandRunPayload {
|
|
54
|
+
result: unknown;
|
|
55
|
+
}
|
|
56
|
+
declare module 'discord.js' {
|
|
57
|
+
interface ClientEvents {
|
|
58
|
+
[SubcommandPluginEvents.ChatInputSubcommandRun]: [
|
|
59
|
+
interaction: Interaction,
|
|
60
|
+
subcommand: ChatInputSubcommandMappingValue,
|
|
61
|
+
payload: ChatInputSubcommandRunPayload
|
|
62
|
+
];
|
|
63
|
+
[SubcommandPluginEvents.ChatInputSubcommandSuccess]: [
|
|
64
|
+
interaction: Interaction,
|
|
65
|
+
subcommand: ChatInputSubcommandMappingValue,
|
|
66
|
+
payload: ChatInputSubcommandSuccessPayload
|
|
67
|
+
];
|
|
68
|
+
[SubcommandPluginEvents.ChatInputSubcommandNotFound]: [
|
|
69
|
+
interaction: Interaction,
|
|
70
|
+
subcommand: ChatInputSubcommandMappingValue,
|
|
71
|
+
context: ChatInputCommand.Context
|
|
72
|
+
];
|
|
73
|
+
[SubcommandPluginEvents.ChatInputSubcommandDenied]: [error: UserError, payload: ChatInputSubcommandDeniedPayload];
|
|
74
|
+
[SubcommandPluginEvents.ChatInputSubcommandError]: [error: unknown, payload: ChatInputSubcommandErrorPayload];
|
|
75
|
+
[SubcommandPluginEvents.MessageSubcommandRun]: [
|
|
76
|
+
message: Message,
|
|
77
|
+
subcommand: MessageSubcommandMappingValue,
|
|
78
|
+
payload: MessageSubcommandRunPayload
|
|
79
|
+
];
|
|
80
|
+
[SubcommandPluginEvents.MessageSubcommandSuccess]: [
|
|
81
|
+
message: Message,
|
|
82
|
+
subcommand: MessageSubcommandMappingValue,
|
|
83
|
+
payload: MessageSubcommandSuccessPayload
|
|
84
|
+
];
|
|
85
|
+
[SubcommandPluginEvents.MessageSubcommandNotFound]: [
|
|
86
|
+
message: Message,
|
|
87
|
+
subcommand: MessageSubcommandMappingValue,
|
|
88
|
+
context: ChatInputCommand.Context
|
|
89
|
+
];
|
|
90
|
+
[SubcommandPluginEvents.MessageSubcommandDenied]: [error: UserError, payload: MessageSubcommandDeniedPayload];
|
|
91
|
+
[SubcommandPluginEvents.MessageSubcommandError]: [error: unknown, payload: MessageSubcommandErrorPayload];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=Events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Events.d.ts","sourceRoot":"","sources":["../../../src/lib/types/Events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EAAE,+BAA+B,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAE5G,eAAO,MAAM,sBAAsB;;;;;;;;;;;CAWlC,CAAC;AAEF,0BAAkB,2BAA2B;IAC5C,wBAAwB,6BAA6B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;YACxB,UAAU,EAAE,+BAA+B;YAC3C,OAAO,EAAE,iCAAiC;SAC1C,CAAC;QACF,CAAC,sBAAsB,CAAC,2BAA2B,CAAC,EAAE;YACrD,WAAW,EAAE,WAAW;YACxB,UAAU,EAAE,+BAA+B;YAC3C,OAAO,EAAE,gBAAgB,CAAC,OAAO;SACjC,CAAC;QACF,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,gCAAgC,CAAC,CAAC;QAClH,CAAC,sBAAsB,CAAC,wBAAwB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,+BAA+B,CAAC,CAAC;QAC9G,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,EAAE;YAC9C,OAAO,EAAE,OAAO;YAChB,UAAU,EAAE,6BAA6B;YACzC,OAAO,EAAE,2BAA2B;SACpC,CAAC;QACF,CAAC,sBAAsB,CAAC,wBAAwB,CAAC,EAAE;YAClD,OAAO,EAAE,OAAO;YAChB,UAAU,EAAE,6BAA6B;YACzC,OAAO,EAAE,+BAA+B;SACxC,CAAC;QACF,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,EAAE;YACnD,OAAO,EAAE,OAAO;YAChB,UAAU,EAAE,6BAA6B;YACzC,OAAO,EAAE,gBAAgB,CAAC,OAAO;SACjC,CAAC;QACF,CAAC,sBAAsB,CAAC,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,8BAA8B,CAAC,CAAC;QAC9G,CAAC,sBAAsB,CAAC,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,6BAA6B,CAAC,CAAC;KAC1G;CACD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubcommandPluginIdentifiers = exports.SubcommandPluginEvents = void 0;
|
|
4
|
+
exports.SubcommandPluginEvents = {
|
|
5
|
+
ChatInputSubcommandRun: 'chatInputSubcommandRun',
|
|
6
|
+
ChatInputSubcommandSuccess: 'chatInputSubcommandSuccess',
|
|
7
|
+
ChatInputSubcommandNotFound: 'chatInputSubcommandNotFound',
|
|
8
|
+
ChatInputSubcommandDenied: 'chatInputSubcommandDenied',
|
|
9
|
+
ChatInputSubcommandError: 'chatInputSubcommandError',
|
|
10
|
+
MessageSubcommandRun: 'messageSubcommandRun',
|
|
11
|
+
MessageSubcommandSuccess: 'messageSubcommandSuccess',
|
|
12
|
+
MessageSubcommandNotFound: 'messageSubcommandNotFound',
|
|
13
|
+
MessageSubcommandDenied: 'messageSubcommandDenied',
|
|
14
|
+
MessageSubcommandError: 'messageSubcommandError'
|
|
15
|
+
};
|
|
16
|
+
var SubcommandPluginIdentifiers;
|
|
17
|
+
(function (SubcommandPluginIdentifiers) {
|
|
18
|
+
SubcommandPluginIdentifiers["MessageSubcommandNoMatch"] = "messageSubcommandNoMatch";
|
|
19
|
+
SubcommandPluginIdentifiers["ChatInputSubcommandNoMatch"] = "chatInputSubcommandNoMatch";
|
|
20
|
+
SubcommandPluginIdentifiers["SubcommandNotFound"] = "subcommandNotFound";
|
|
21
|
+
})(SubcommandPluginIdentifiers = exports.SubcommandPluginIdentifiers || (exports.SubcommandPluginIdentifiers = {}));
|
|
22
|
+
//# sourceMappingURL=Events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Events.js","sourceRoot":"","sources":["../../../src/lib/types/Events.ts"],"names":[],"mappings":";;;AAKa,QAAA,sBAAsB,GAAG;IACrC,sBAAsB,EAAE,wBAAiC;IACzD,0BAA0B,EAAE,4BAAqC;IACjE,2BAA2B,EAAE,6BAAsC;IACnE,yBAAyB,EAAE,2BAAoC;IAC/D,wBAAwB,EAAE,0BAAmC;IAC7D,oBAAoB,EAAE,sBAA+B;IACrD,wBAAwB,EAAE,0BAAmC;IAC7D,yBAAyB,EAAE,2BAAoC;IAC/D,uBAAuB,EAAE,yBAAkC;IAC3D,sBAAsB,EAAE,wBAAiC;CACzD,CAAC;AAEF,IAAkB,2BAIjB;AAJD,WAAkB,2BAA2B;IAC5C,oFAAqD,CAAA;IACrD,wFAAyD,CAAA;IACzD,wEAAyC,CAAA;AAC1C,CAAC,EAJiB,2BAA2B,GAA3B,mCAA2B,KAA3B,mCAA2B,QAI5C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-subcommands",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-pr-271.cde343c3.0",
|
|
4
4
|
"description": "Plugin for @sapphire/framework that adds support for subcommands.",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint": "eslint src --ext ts --fix",
|
|
21
21
|
"build": "tsc -b src && yarn esm:default",
|
|
22
22
|
"esm:default": "gen-esm-wrapper dist/index.js dist/index.mjs",
|
|
23
|
-
"
|
|
23
|
+
"prepack": "yarn build",
|
|
24
24
|
"bump": "cliff-jumper",
|
|
25
25
|
"check-update": "cliff-jumper --dry-run"
|
|
26
26
|
},
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Args, Awaitable, Command } from '@sapphire/framework';
|
|
2
|
-
import type { Message } from 'discord.js';
|
|
3
|
-
/**
|
|
4
|
-
* @since 1.0.0
|
|
5
|
-
* SubCommandEntry represents a basic subcommand entry. Methods and command names are supported in core.
|
|
6
|
-
* @see {@link SubCommandEntryCommand}
|
|
7
|
-
* @see {@link SubCommandEntryMethod}
|
|
8
|
-
*/
|
|
9
|
-
export declare abstract class SubCommandEntry<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> {
|
|
10
|
-
readonly input: string | ((context: SubCommandEntry.MessageRunContext<ArgType, CommandType>) => Awaitable<string>);
|
|
11
|
-
readonly output: string;
|
|
12
|
-
constructor(options: SubCommandEntry.Options<ArgType, CommandType>);
|
|
13
|
-
match(value: string, context: SubCommandEntry.MessageRunContext<ArgType, CommandType>): Promise<boolean>;
|
|
14
|
-
abstract messageRun(context: SubCommandEntry.MessageRunContext<ArgType, CommandType>): unknown;
|
|
15
|
-
}
|
|
16
|
-
export declare namespace SubCommandEntry {
|
|
17
|
-
/**
|
|
18
|
-
* The options for a SubCommandEntry.
|
|
19
|
-
* @property input Input represents the subcommand that the user will type in.
|
|
20
|
-
* @property output Output represents the method/command called for the subcommand.
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* subCommands: [{
|
|
24
|
-
* input: ({ message }) => message.resolveKey('subcommands:set'),
|
|
25
|
-
* output: 'set'
|
|
26
|
-
* }]
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
interface Options<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> {
|
|
30
|
-
input: string | ((context: MessageRunContext<ArgType, CommandType>) => Awaitable<string>);
|
|
31
|
-
output?: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* MessageRunContext is passed to SubCommandManager.messageRun() and to input (if it is a function)
|
|
35
|
-
* @see {@link SubCommandEntry.Options}
|
|
36
|
-
*/
|
|
37
|
-
interface MessageRunContext<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> {
|
|
38
|
-
command: CommandType;
|
|
39
|
-
message: Message;
|
|
40
|
-
args: ArgType;
|
|
41
|
-
context: Command.RunContext;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=SubCommandEntry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandEntry.d.ts","sourceRoot":"","sources":["../../src/lib/SubCommandEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAa,MAAM,qBAAqB,CAAC;AAE1E,OAAO,KA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,CAAC;QACjB,IAAI,EAAE,OAAO,CAAC;QACd,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC;KAC5B;CACD"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubCommandEntry = void 0;
|
|
4
|
-
const framework_1 = require("@sapphire/framework");
|
|
5
|
-
const utilities_1 = require("@sapphire/utilities");
|
|
6
|
-
/**
|
|
7
|
-
* @since 1.0.0
|
|
8
|
-
* SubCommandEntry represents a basic subcommand entry. Methods and command names are supported in core.
|
|
9
|
-
* @see {@link SubCommandEntryCommand}
|
|
10
|
-
* @see {@link SubCommandEntryMethod}
|
|
11
|
-
*/
|
|
12
|
-
class SubCommandEntry {
|
|
13
|
-
constructor(options) {
|
|
14
|
-
Object.defineProperty(this, "input", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: void 0
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(this, "output", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: void 0
|
|
25
|
-
});
|
|
26
|
-
this.input = options.input;
|
|
27
|
-
if (!options.output && typeof options.input !== 'string')
|
|
28
|
-
throw new ReferenceError('No output provided.');
|
|
29
|
-
this.output = options.output ?? options.input;
|
|
30
|
-
}
|
|
31
|
-
async match(value, context) {
|
|
32
|
-
const input = (0, utilities_1.isFunction)(this.input) ? await this.input(context) : this.input;
|
|
33
|
-
const caseInsensitive = framework_1.container.client.options.caseInsensitiveCommands;
|
|
34
|
-
return caseInsensitive ? input.toLowerCase() === value.toLowerCase() : input === value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.SubCommandEntry = SubCommandEntry;
|
|
38
|
-
//# sourceMappingURL=SubCommandEntry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandEntry.js","sourceRoot":"","sources":["../../src/lib/SubCommandEntry.ts"],"names":[],"mappings":";;;AAAA,mDAA0E;AAC1E,mDAAiD;AAGjD;;;;;GAKG;AACH,MAAsB,eAAe;IAIpC,YAAmB,OAAsD;QAHzE;;;;;WAA0H;QAC1H;;;;;WAA+B;QAG9B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;YAAE,MAAM,IAAI,cAAc,CAAC,qBAAqB,CAAC,CAAC;QAC1G,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAK,OAAO,CAAC,KAAgB,CAAC;IAC3D,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,KAAa,EAAE,OAAgE;QACjG,MAAM,KAAK,GAAG,IAAA,sBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9E,MAAM,eAAe,GAAG,qBAAS,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC;QACzE,OAAO,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC;IACxF,CAAC;CAGD;AAjBD,0CAiBC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Args, Command } from '@sapphire/framework';
|
|
2
|
-
import { SubCommandEntry } from './SubCommandEntry';
|
|
3
|
-
/**
|
|
4
|
-
* SubCommandEntryCommand uses other commands as the caller function for subcommands.
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* // here, using `command set` would call the command `modify-settings`.
|
|
8
|
-
* subCommands: [{
|
|
9
|
-
* input: 'set',
|
|
10
|
-
* output: 'modify-settings'
|
|
11
|
-
* }]
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export declare class SubCommandEntryCommand<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> extends SubCommandEntry<ArgType, CommandType> {
|
|
15
|
-
messageRun(context: SubCommandEntry.MessageRunContext<ArgType, CommandType>): unknown;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=SubCommandEntryCommand.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandEntryCommand.d.ts","sourceRoot":"","sources":["../../src/lib/SubCommandEntryCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAgC,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,qBAAa,sBAAsB,CAAC,OAAO,SAAS,IAAI,GAAG,IAAI,EAAE,WAAW,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAE,SAAQ,eAAe,CAChJ,OAAO,EACP,WAAW,CACX;IACO,UAAU,CAAC,OAAO,EAAE,eAAe,CAAC,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,OAAO;CAK5F"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubCommandEntryCommand = void 0;
|
|
4
|
-
const framework_1 = require("@sapphire/framework");
|
|
5
|
-
const SubCommandEntry_1 = require("./SubCommandEntry");
|
|
6
|
-
/**
|
|
7
|
-
* SubCommandEntryCommand uses other commands as the caller function for subcommands.
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* // here, using `command set` would call the command `modify-settings`.
|
|
11
|
-
* subCommands: [{
|
|
12
|
-
* input: 'set',
|
|
13
|
-
* output: 'modify-settings'
|
|
14
|
-
* }]
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
class SubCommandEntryCommand extends SubCommandEntry_1.SubCommandEntry {
|
|
18
|
-
messageRun(context) {
|
|
19
|
-
const command = framework_1.container.stores.get('commands').get(this.output);
|
|
20
|
-
if (command)
|
|
21
|
-
return command.messageRun(context.message, context.args, context.context);
|
|
22
|
-
throw new ReferenceError(`The command '${this.input}' does not exist.`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.SubCommandEntryCommand = SubCommandEntryCommand;
|
|
26
|
-
//# sourceMappingURL=SubCommandEntryCommand.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandEntryCommand.js","sourceRoot":"","sources":["../../src/lib/SubCommandEntryCommand.ts"],"names":[],"mappings":";;;AAAA,mDAAkF;AAClF,uDAAoD;AAEpD;;;;;;;;;;GAUG;AACH,MAAa,sBAA6G,SAAQ,iCAGjI;IACO,UAAU,CAAC,OAAgE;QACjF,MAAM,OAAO,GAAI,qBAAS,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAA6B,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/F,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACvF,MAAM,IAAI,cAAc,CAAC,gBAAgB,IAAI,CAAC,KAAK,mBAAmB,CAAC,CAAC;IACzE,CAAC;CACD;AATD,wDASC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Args, Command } from '@sapphire/framework';
|
|
2
|
-
import { SubCommandEntry } from './SubCommandEntry';
|
|
3
|
-
/**
|
|
4
|
-
* SubCommandEntryMethods support method names as subcommand functions. All methods must be on the **same** class.
|
|
5
|
-
* For splitting sub-commands into different commands, see {@link SubCommandEntryCommand}
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* export class extends SubCommandPluginCommand {
|
|
9
|
-
* public constructor(context: PieceContext) {
|
|
10
|
-
* super(context, {
|
|
11
|
-
* name: 'conf',
|
|
12
|
-
* // by default, outputs default to inputs
|
|
13
|
-
* subCommands: ['set', { input: 'list', default: true }]
|
|
14
|
-
* })
|
|
15
|
-
* }
|
|
16
|
-
*
|
|
17
|
-
* public async set(message: Message, args: Args) {
|
|
18
|
-
* // !conf set is called here.
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* public async list(message: Message, args: Args) {
|
|
22
|
-
* // !conf list is called here.
|
|
23
|
-
* // !conf is also called here. (see SubCommandEntry.default)
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare class SubCommandEntryMethod<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> extends SubCommandEntry<ArgType, CommandType> {
|
|
29
|
-
messageRun(context: SubCommandEntry.MessageRunContext<ArgType, CommandType>): unknown;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=SubCommandEntryMethod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandEntryMethod.d.ts","sourceRoot":"","sources":["../../src/lib/SubCommandEntryMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,qBAAqB,CAAC,OAAO,SAAS,IAAI,GAAG,IAAI,EAAE,WAAW,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAE,SAAQ,eAAe,CAC/I,OAAO,EACP,WAAW,CACX;IACO,UAAU,CAAC,OAAO,EAAE,eAAe,CAAC,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,OAAO;CAK5F"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubCommandEntryMethod = void 0;
|
|
4
|
-
const SubCommandEntry_1 = require("./SubCommandEntry");
|
|
5
|
-
/**
|
|
6
|
-
* SubCommandEntryMethods support method names as subcommand functions. All methods must be on the **same** class.
|
|
7
|
-
* For splitting sub-commands into different commands, see {@link SubCommandEntryCommand}
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* export class extends SubCommandPluginCommand {
|
|
11
|
-
* public constructor(context: PieceContext) {
|
|
12
|
-
* super(context, {
|
|
13
|
-
* name: 'conf',
|
|
14
|
-
* // by default, outputs default to inputs
|
|
15
|
-
* subCommands: ['set', { input: 'list', default: true }]
|
|
16
|
-
* })
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* public async set(message: Message, args: Args) {
|
|
20
|
-
* // !conf set is called here.
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* public async list(message: Message, args: Args) {
|
|
24
|
-
* // !conf list is called here.
|
|
25
|
-
* // !conf is also called here. (see SubCommandEntry.default)
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
class SubCommandEntryMethod extends SubCommandEntry_1.SubCommandEntry {
|
|
31
|
-
messageRun(context) {
|
|
32
|
-
const method = Reflect.get(context.command, this.output);
|
|
33
|
-
if (method)
|
|
34
|
-
return Reflect.apply(method, context.command, [context.message, context.args, context.context]);
|
|
35
|
-
throw new ReferenceError(`The method '${this.input}' does not exist for the command '${context.command.name}'.`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.SubCommandEntryMethod = SubCommandEntryMethod;
|
|
39
|
-
//# sourceMappingURL=SubCommandEntryMethod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandEntryMethod.js","sourceRoot":"","sources":["../../src/lib/SubCommandEntryMethod.ts"],"names":[],"mappings":";;;AACA,uDAAoD;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,qBAA4G,SAAQ,iCAGhI;IACO,UAAU,CAAC,OAAgE;QACjF,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACzD,IAAI,MAAM;YAAE,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAC5G,MAAM,IAAI,cAAc,CAAC,eAAe,IAAI,CAAC,KAAK,qCAAqC,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC;IAClH,CAAC;CACD;AATD,sDASC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Args, Command } from '@sapphire/framework';
|
|
2
|
-
import type { SubCommandEntry } from './SubCommandEntry';
|
|
3
|
-
import { SubCommandEntryCommand } from './SubCommandEntryCommand';
|
|
4
|
-
export declare class SubCommandManager<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> {
|
|
5
|
-
private readonly entries;
|
|
6
|
-
private readonly default;
|
|
7
|
-
constructor(entries: SubCommandManager.RawEntries<ArgType, CommandType>);
|
|
8
|
-
messageRun(context: SubCommandEntry.MessageRunContext<ArgType, CommandType>): Promise<unknown>;
|
|
9
|
-
protected resolve(value: string | SubCommandManager.Entry<ArgType, CommandType>): SubCommandManager.Entry<ArgType, CommandType>;
|
|
10
|
-
static readonly handlers: Map<string, typeof SubCommandEntryCommand>;
|
|
11
|
-
}
|
|
12
|
-
export declare namespace SubCommandManager {
|
|
13
|
-
type Type = 'command' | 'method';
|
|
14
|
-
interface Entry<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> extends SubCommandEntry.Options<ArgType, CommandType> {
|
|
15
|
-
type?: Type;
|
|
16
|
-
default?: boolean;
|
|
17
|
-
}
|
|
18
|
-
type RawEntries<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> = readonly (string | Entry<ArgType, CommandType>)[];
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=SubCommandManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandManager.d.ts","sourceRoot":"","sources":["../../src/lib/SubCommandManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAA+B,MAAM,qBAAqB,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,qBAAa,iBAAiB,CAAC,OAAO,SAAS,IAAI,GAAG,IAAI,EAAE,WAAW,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAClH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+C;IACvE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsD;gBAE3D,OAAO,EAAE,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC;IAgBjE,UAAU,CAAC,OAAO,EAAE,eAAe,CAAC,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC;IAmBxF,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC;IAK/H,gBAAuB,QAAQ,6CAG5B;CACH;AAED,yBAAiB,iBAAiB,CAAC;IAClC,KAAY,IAAI,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxC,UAAiB,KAAK,CAAC,OAAO,SAAS,IAAI,GAAG,IAAI,EAAE,WAAW,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAC1G,SAAQ,eAAe,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC;QACrD,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,OAAO,CAAC,EAAE,OAAO,CAAC;KAClB;IAED,KAAY,UAAU,CAAC,OAAO,SAAS,IAAI,GAAG,IAAI,EAAE,WAAW,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,SAAS,CACrH,MAAM,GACN,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAC7B,EAAE,CAAC;CACJ"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubCommandManager = void 0;
|
|
4
|
-
const framework_1 = require("@sapphire/framework");
|
|
5
|
-
const SubCommandEntryCommand_1 = require("./SubCommandEntryCommand");
|
|
6
|
-
const SubCommandEntryMethod_1 = require("./SubCommandEntryMethod");
|
|
7
|
-
class SubCommandManager {
|
|
8
|
-
constructor(entries) {
|
|
9
|
-
Object.defineProperty(this, "entries", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: []
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "default", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: null
|
|
20
|
-
});
|
|
21
|
-
for (const data of entries) {
|
|
22
|
-
const value = this.resolve(data);
|
|
23
|
-
const Ctor = SubCommandManager.handlers.get(value.type ?? 'method');
|
|
24
|
-
if (!Ctor)
|
|
25
|
-
throw new ReferenceError(`There is no sub command handler named '${value.type}' in 'SubCommandManager.handlers'.`);
|
|
26
|
-
const entry = new Ctor(value);
|
|
27
|
-
if (value.default) {
|
|
28
|
-
if (this.default)
|
|
29
|
-
throw new Error(`There was already a default of '${this.default.input}', cannot add '${value.input}'.`);
|
|
30
|
-
this.default = entry;
|
|
31
|
-
}
|
|
32
|
-
this.entries.push(entry);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async messageRun(context) {
|
|
36
|
-
// Pick one argument, then try to match a subcommand:
|
|
37
|
-
context.args.save();
|
|
38
|
-
const value = context.args.nextMaybe();
|
|
39
|
-
if (value.exists) {
|
|
40
|
-
for (const entry of this.entries) {
|
|
41
|
-
if (await entry.match(value.value, context))
|
|
42
|
-
return entry.messageRun(context);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// No subcommand matched, let's restore and try to run default, if any:
|
|
46
|
-
context.args.restore();
|
|
47
|
-
if (this.default)
|
|
48
|
-
return this.default.messageRun(context);
|
|
49
|
-
// No match and no subcommand, return an err:
|
|
50
|
-
return (0, framework_1.err)(new framework_1.UserError({ identifier: "subCommandNoMatch" /* SubCommandNoMatch */, context }));
|
|
51
|
-
}
|
|
52
|
-
resolve(value) {
|
|
53
|
-
if (typeof value !== 'string')
|
|
54
|
-
return value;
|
|
55
|
-
return { input: value, output: value, type: 'method' };
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.SubCommandManager = SubCommandManager;
|
|
59
|
-
Object.defineProperty(SubCommandManager, "handlers", {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true,
|
|
63
|
-
value: new Map([
|
|
64
|
-
['command', SubCommandEntryCommand_1.SubCommandEntryCommand],
|
|
65
|
-
['method', SubCommandEntryMethod_1.SubCommandEntryMethod]
|
|
66
|
-
])
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=SubCommandManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandManager.js","sourceRoot":"","sources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AAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;aAC9E;SACD;QAED,uEAAuE;QACvE,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAE1D,6CAA6C;QAC7C,OAAO,IAAA,eAAG,EAAC,IAAI,qBAAS,CAAC,EAAE,UAAU,6CAA+B,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACnF,CAAC;IAES,OAAO,CAAC,KAA6D;QAC9E,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACxD,CAAC;;AA1CF,8CAgDC;AAJA;;;;WAAkC,IAAI,GAAG,CAAC;QACzC,CAAC,SAAS,EAAE,+CAAsB,CAAC;QACnC,CAAC,QAAQ,EAAE,6CAAqB,CAAC;KACjC,CAAC;GAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Args, Awaitable, Command, PieceContext } from '@sapphire/framework';
|
|
2
|
-
import type { Message } from 'discord.js';
|
|
3
|
-
import { SubCommandManager } from './SubCommandManager';
|
|
4
|
-
export declare class SubCommandPluginCommand<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> extends Command<ArgType> {
|
|
5
|
-
readonly subCommands: SubCommandManager<ArgType, CommandType> | null;
|
|
6
|
-
constructor(context: PieceContext, options: SubCommandPluginCommandOptions<ArgType>);
|
|
7
|
-
messageRun(message: Message, args: ArgType, context: Command.RunContext): Awaitable<unknown>;
|
|
8
|
-
}
|
|
9
|
-
export interface SubCommandPluginCommandOptions<ArgType extends Args = Args, CommandType extends Command<ArgType> = Command<ArgType>> extends Command.Options {
|
|
10
|
-
subCommands?: SubCommandManager.RawEntries<ArgType, CommandType>;
|
|
11
|
-
}
|
|
12
|
-
export declare namespace SubCommandPluginCommand {
|
|
13
|
-
/** Re-export of {@link Command.Context} */
|
|
14
|
-
type Context = Command.Context;
|
|
15
|
-
/** Re-export of {@link Command.RunContext} */
|
|
16
|
-
type RunContext = Command.RunContext;
|
|
17
|
-
/** Re-export of {@link Command.JSON} */
|
|
18
|
-
type JSON = Command.JSON;
|
|
19
|
-
/** Re-export of {@link Command.RunInTypes} */
|
|
20
|
-
type RunInTypes = Command.RunInTypes;
|
|
21
|
-
/**
|
|
22
|
-
* The SubCommandPluginCommand Options
|
|
23
|
-
*/
|
|
24
|
-
type Options = SubCommandPluginCommandOptions;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=SubCommandPluginCommand.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandPluginCommand.d.ts","sourceRoot":"","sources":["../../src/lib/SubCommandPluginCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,qBAAa,uBAAuB,CAAC,OAAO,SAAS,IAAI,GAAG,IAAI,EAAE,WAAW,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAE,SAAQ,OAAO,CAAC,OAAO,CAAC;IAClJ,SAAgB,WAAW,EAAE,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC;gBAEzD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,8BAA8B,CAAC,OAAO,CAAC;IAMnF,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC;CAInG;AAED,MAAM,WAAW,8BAA8B,CAAC,OAAO,SAAS,IAAI,GAAG,IAAI,EAAE,WAAW,SAAS,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CACnI,SAAQ,OAAO,CAAC,OAAO;IACvB,WAAW,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;CACjE;AAED,yBAAiB,uBAAuB,CAAC;IACxC,2CAA2C;IAC3C,KAAY,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAEtC,8CAA8C;IAC9C,KAAY,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAE5C,wCAAwC;IACxC,KAAY,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEhC,8CAA8C;IAC9C,KAAY,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAE5C;;OAEG;IACH,KAAY,OAAO,GAAG,8BAA8B,CAAC;CACrD"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubCommandPluginCommand = void 0;
|
|
4
|
-
const framework_1 = require("@sapphire/framework");
|
|
5
|
-
const SubCommandManager_1 = require("./SubCommandManager");
|
|
6
|
-
class SubCommandPluginCommand extends framework_1.Command {
|
|
7
|
-
constructor(context, options) {
|
|
8
|
-
super(context, options);
|
|
9
|
-
Object.defineProperty(this, "subCommands", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: void 0
|
|
14
|
-
});
|
|
15
|
-
this.subCommands = options.subCommands ? new SubCommandManager_1.SubCommandManager(options.subCommands) : null;
|
|
16
|
-
}
|
|
17
|
-
messageRun(message, args, context) {
|
|
18
|
-
if (!this.subCommands)
|
|
19
|
-
throw new Error(`The command ${this.name} does not have a 'messageRun' method and does not support sub-commands.`);
|
|
20
|
-
return this.subCommands.messageRun({ message, args, context, command: this });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.SubCommandPluginCommand = SubCommandPluginCommand;
|
|
24
|
-
//# sourceMappingURL=SubCommandPluginCommand.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubCommandPluginCommand.js","sourceRoot":"","sources":["../../src/lib/SubCommandPluginCommand.ts"],"names":[],"mappings":";;;AAAA,mDAA6E;AAE7E,2DAAwD;AAExD,MAAa,uBAA8G,SAAQ,mBAAgB;IAGlJ,YAAmB,OAAqB,EAAE,OAAgD;QACzF,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAHzB;;;;;WAA4E;QAK3E,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,qCAAiB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5F,CAAC;IAEM,UAAU,CAAC,OAAgB,EAAE,IAAa,EAAE,OAA2B;QAC7E,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,CAAC,IAAI,yEAAyE,CAAC,CAAC;QAC1I,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAA8B,EAAE,CAAC,CAAC;IACzG,CAAC;CACD;AAbD,0DAaC"}
|