@sapphire/plugin-pattern-commands 1.1.0-next.832decb.0 → 2.0.1-next.3fe7e48.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 +2 -1
- package/dist/lib/utils/PaternCommandEvents.d.ts +51 -1
- package/dist/lib/utils/PaternCommandEvents.d.ts.map +1 -1
- package/dist/lib/utils/PaternCommandEvents.js +50 -0
- package/dist/lib/utils/PaternCommandEvents.js.map +1 -1
- package/dist/listeners/PluginCommandAccepted.d.ts +1 -0
- package/dist/listeners/PluginCommandAccepted.d.ts.map +1 -1
- package/dist/listeners/PluginCommandAccepted.js +17 -3
- package/dist/listeners/PluginCommandAccepted.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,12 +34,13 @@ With pattern commands you can define rulesets to which the bot may respond.
|
|
|
34
34
|
|
|
35
35
|
- [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)
|
|
36
36
|
- [`@sapphire/utilities`](https://www.npmjs.com/package/@sapphire/utilities)
|
|
37
|
+
- [`@sapphire/stopwatch`](https://www.npmjs.com/package/@sapphire/stopwatch)
|
|
37
38
|
- [`discord.js`](https://www.npmjs.com/package/discord.js)
|
|
38
39
|
|
|
39
40
|
You can use the following command to install this package, or replace `npm install` with your package manager of choice.
|
|
40
41
|
|
|
41
42
|
```sh
|
|
42
|
-
npm install @sapphire/plugin-pattern-commands @sapphire/framework @sapphire/utilities discord.js
|
|
43
|
+
npm install @sapphire/plugin-pattern-commands @sapphire/framework @sapphire/utilities @sapphire/stopwatch discord.js
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
---
|
|
@@ -1,9 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Events emitted during the parsing and command run.
|
|
3
|
+
* You can use these events for debugging and logging purposes.
|
|
4
|
+
*/
|
|
1
5
|
export declare enum PatternCommandEvents {
|
|
6
|
+
/**
|
|
7
|
+
* Event that is emitted when the RNG doesn't love the command
|
|
8
|
+
* @param message The message where the command was triggered
|
|
9
|
+
* @param command The command's piece
|
|
10
|
+
* @param alias The alias that triggered the command
|
|
11
|
+
*/
|
|
2
12
|
CommandNoLuck = "patternCommandNoLuck",
|
|
13
|
+
/**
|
|
14
|
+
* Event that is emitted when an alias triggered the command but before parsing the preconditions
|
|
15
|
+
* @param payload PatternCommandRunPayload which contains message, command and alias
|
|
16
|
+
*/
|
|
3
17
|
PreCommandRun = "patternCommandPreRun",
|
|
18
|
+
/**
|
|
19
|
+
* Event that is emitted after the preconditions if none of them denied the command
|
|
20
|
+
* @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias
|
|
21
|
+
*/
|
|
4
22
|
CommandAccepted = "patternCommandAccepted",
|
|
23
|
+
/**
|
|
24
|
+
* Event that is emitted after the preconditions if at least one of them denied the command
|
|
25
|
+
* @param error The error of the precondition which denied the command
|
|
26
|
+
* @param payload PatternCommandDeniedPayload which contains parameters, context, message, command and alias
|
|
27
|
+
*/
|
|
5
28
|
CommandDenied = "patternCommandDenied",
|
|
29
|
+
/**
|
|
30
|
+
* Event that is emitted just before the command is ran
|
|
31
|
+
* @param message The message where the command was triggered
|
|
32
|
+
* @param command The command's piece
|
|
33
|
+
* @param alias The alias that triggered the command
|
|
34
|
+
*/
|
|
6
35
|
CommandRun = "patternCommandRun",
|
|
7
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Event that is emitted if there's no error while running the command
|
|
38
|
+
* @param result The result of command's run
|
|
39
|
+
* @param command The command's piece
|
|
40
|
+
* @param alias The alias that triggered the command
|
|
41
|
+
*/
|
|
42
|
+
CommandSuccess = "patternCommandSuccess",
|
|
43
|
+
/**
|
|
44
|
+
* Event that is emitted if there's an error while running the command
|
|
45
|
+
* @param error The error message which happened while the command was running
|
|
46
|
+
* @param command The command's piece
|
|
47
|
+
* @param duration The duration which indicates how long it took the command to run
|
|
48
|
+
* @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias
|
|
49
|
+
*/
|
|
50
|
+
CommandError = "patternCommandError",
|
|
51
|
+
/**
|
|
52
|
+
* Event that is emitted if the command has finished, regardless of whether an error occurred or not
|
|
53
|
+
* @param command The command's piece
|
|
54
|
+
* @param duration The duration which indicates how long it took the command to run
|
|
55
|
+
* @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias
|
|
56
|
+
*/
|
|
57
|
+
CommandFinished = "patternCommandFinished"
|
|
8
58
|
}
|
|
9
59
|
//# sourceMappingURL=PaternCommandEvents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaternCommandEvents.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/PaternCommandEvents.ts"],"names":[],"mappings":"AAAA,oBAAY,oBAAoB;IAC/B,aAAa,yBAAyB;IACtC,aAAa,yBAAyB;IACtC,eAAe,2BAA2B;IAC1C,aAAa,yBAAyB;IACtC,UAAU,sBAAsB;IAChC,cAAc,0BAA0B;
|
|
1
|
+
{"version":3,"file":"PaternCommandEvents.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/PaternCommandEvents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,oBAAoB;IAC/B;;;;;OAKG;IACH,aAAa,yBAAyB;IACtC;;;OAGG;IACH,aAAa,yBAAyB;IACtC;;;OAGG;IACH,eAAe,2BAA2B;IAC1C;;;;OAIG;IACH,aAAa,yBAAyB;IACtC;;;;;OAKG;IACH,UAAU,sBAAsB;IAChC;;;;;OAKG;IACH,cAAc,0BAA0B;IACxC;;;;;;OAMG;IACH,YAAY,wBAAwB;IACpC;;;;;OAKG;IACH,eAAe,2BAA2B;CAC1C"}
|
|
@@ -1,13 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PatternCommandEvents = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Events emitted during the parsing and command run.
|
|
6
|
+
* You can use these events for debugging and logging purposes.
|
|
7
|
+
*/
|
|
4
8
|
var PatternCommandEvents;
|
|
5
9
|
(function (PatternCommandEvents) {
|
|
10
|
+
/**
|
|
11
|
+
* Event that is emitted when the RNG doesn't love the command
|
|
12
|
+
* @param message The message where the command was triggered
|
|
13
|
+
* @param command The command's piece
|
|
14
|
+
* @param alias The alias that triggered the command
|
|
15
|
+
*/
|
|
6
16
|
PatternCommandEvents["CommandNoLuck"] = "patternCommandNoLuck";
|
|
17
|
+
/**
|
|
18
|
+
* Event that is emitted when an alias triggered the command but before parsing the preconditions
|
|
19
|
+
* @param payload PatternCommandRunPayload which contains message, command and alias
|
|
20
|
+
*/
|
|
7
21
|
PatternCommandEvents["PreCommandRun"] = "patternCommandPreRun";
|
|
22
|
+
/**
|
|
23
|
+
* Event that is emitted after the preconditions if none of them denied the command
|
|
24
|
+
* @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias
|
|
25
|
+
*/
|
|
8
26
|
PatternCommandEvents["CommandAccepted"] = "patternCommandAccepted";
|
|
27
|
+
/**
|
|
28
|
+
* Event that is emitted after the preconditions if at least one of them denied the command
|
|
29
|
+
* @param error The error of the precondition which denied the command
|
|
30
|
+
* @param payload PatternCommandDeniedPayload which contains parameters, context, message, command and alias
|
|
31
|
+
*/
|
|
9
32
|
PatternCommandEvents["CommandDenied"] = "patternCommandDenied";
|
|
33
|
+
/**
|
|
34
|
+
* Event that is emitted just before the command is ran
|
|
35
|
+
* @param message The message where the command was triggered
|
|
36
|
+
* @param command The command's piece
|
|
37
|
+
* @param alias The alias that triggered the command
|
|
38
|
+
*/
|
|
10
39
|
PatternCommandEvents["CommandRun"] = "patternCommandRun";
|
|
40
|
+
/**
|
|
41
|
+
* Event that is emitted if there's no error while running the command
|
|
42
|
+
* @param result The result of command's run
|
|
43
|
+
* @param command The command's piece
|
|
44
|
+
* @param alias The alias that triggered the command
|
|
45
|
+
*/
|
|
11
46
|
PatternCommandEvents["CommandSuccess"] = "patternCommandSuccess";
|
|
47
|
+
/**
|
|
48
|
+
* Event that is emitted if there's an error while running the command
|
|
49
|
+
* @param error The error message which happened while the command was running
|
|
50
|
+
* @param command The command's piece
|
|
51
|
+
* @param duration The duration which indicates how long it took the command to run
|
|
52
|
+
* @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias
|
|
53
|
+
*/
|
|
54
|
+
PatternCommandEvents["CommandError"] = "patternCommandError";
|
|
55
|
+
/**
|
|
56
|
+
* Event that is emitted if the command has finished, regardless of whether an error occurred or not
|
|
57
|
+
* @param command The command's piece
|
|
58
|
+
* @param duration The duration which indicates how long it took the command to run
|
|
59
|
+
* @param payload PatternCommandAcceptedPayload which contains parameters, context, message, command and alias
|
|
60
|
+
*/
|
|
61
|
+
PatternCommandEvents["CommandFinished"] = "patternCommandFinished";
|
|
12
62
|
})(PatternCommandEvents = exports.PatternCommandEvents || (exports.PatternCommandEvents = {}));
|
|
13
63
|
//# sourceMappingURL=PaternCommandEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaternCommandEvents.js","sourceRoot":"","sources":["../../../src/lib/utils/PaternCommandEvents.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"PaternCommandEvents.js","sourceRoot":"","sources":["../../../src/lib/utils/PaternCommandEvents.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,IAAY,oBAqDX;AArDD,WAAY,oBAAoB;IAC/B;;;;;OAKG;IACH,8DAAsC,CAAA;IACtC;;;OAGG;IACH,8DAAsC,CAAA;IACtC;;;OAGG;IACH,kEAA0C,CAAA;IAC1C;;;;OAIG;IACH,8DAAsC,CAAA;IACtC;;;;;OAKG;IACH,wDAAgC,CAAA;IAChC;;;;;OAKG;IACH,gEAAwC,CAAA;IACxC;;;;;;OAMG;IACH,4DAAoC,CAAA;IACpC;;;;;OAKG;IACH,kEAA0C,CAAA;AAC3C,CAAC,EArDW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAqD/B"}
|
|
@@ -5,5 +5,6 @@ import type { PatternCommandAcceptedPayload } from '../lib/utils/PatternCommandI
|
|
|
5
5
|
export declare class CommandAcceptedListener extends Listener<typeof PatternCommandEvents.CommandAccepted> {
|
|
6
6
|
constructor(context: PieceContext);
|
|
7
7
|
run(payload: PatternCommandAcceptedPayload): Promise<void>;
|
|
8
|
+
runPatternCommand(payload: PatternCommandAcceptedPayload): Promise<void>;
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=PluginCommandAccepted.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginCommandAccepted.d.ts","sourceRoot":"","sources":["../../src/listeners/PluginCommandAccepted.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PluginCommandAccepted.d.ts","sourceRoot":"","sources":["../../src/listeners/PluginCommandAccepted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AAE3F,qBAAa,uBAAwB,SAAQ,QAAQ,CAAC,OAAO,oBAAoB,CAAC,eAAe,CAAC;gBAC9E,OAAO,EAAE,YAAY;IAI3B,GAAG,CAAC,OAAO,EAAE,6BAA6B;IAU1C,iBAAiB,CAAC,OAAO,EAAE,6BAA6B;CAmBrE"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandAcceptedListener = void 0;
|
|
4
4
|
const framework_1 = require("@sapphire/framework");
|
|
5
|
+
const stopwatch_1 = require("@sapphire/stopwatch");
|
|
5
6
|
const PaternCommandEvents_1 = require("../lib/utils/PaternCommandEvents");
|
|
6
7
|
class CommandAcceptedListener extends framework_1.Listener {
|
|
7
8
|
constructor(context) {
|
|
@@ -10,14 +11,27 @@ class CommandAcceptedListener extends framework_1.Listener {
|
|
|
10
11
|
async run(payload) {
|
|
11
12
|
const { message, command, alias } = payload;
|
|
12
13
|
if (command.chance > Math.round(Math.random() * 99) + 1) {
|
|
13
|
-
|
|
14
|
-
const result = await command.messageRun(message);
|
|
15
|
-
message.client.emit(PaternCommandEvents_1.PatternCommandEvents.CommandSuccess, result, command, alias);
|
|
14
|
+
await this.runPatternCommand(payload);
|
|
16
15
|
}
|
|
17
16
|
else {
|
|
18
17
|
message.client.emit(PaternCommandEvents_1.PatternCommandEvents.CommandNoLuck, message, command, alias);
|
|
19
18
|
}
|
|
20
19
|
}
|
|
20
|
+
async runPatternCommand(payload) {
|
|
21
|
+
const { message, command, alias } = payload;
|
|
22
|
+
const stopwatch = new stopwatch_1.Stopwatch();
|
|
23
|
+
const result = await (0, framework_1.fromAsync)(async () => {
|
|
24
|
+
message.client.emit(PaternCommandEvents_1.PatternCommandEvents.CommandRun, message, command, alias);
|
|
25
|
+
const result = await command.messageRun(message);
|
|
26
|
+
message.client.emit(PaternCommandEvents_1.PatternCommandEvents.CommandSuccess, result, command, alias);
|
|
27
|
+
return result;
|
|
28
|
+
});
|
|
29
|
+
const { duration } = stopwatch.stop();
|
|
30
|
+
if ((0, framework_1.isErr)(result)) {
|
|
31
|
+
message.client.emit(PaternCommandEvents_1.PatternCommandEvents.CommandError, result.error, command, duration, payload);
|
|
32
|
+
}
|
|
33
|
+
message.client.emit(PaternCommandEvents_1.PatternCommandEvents.CommandFinished, command, duration, payload);
|
|
34
|
+
}
|
|
21
35
|
}
|
|
22
36
|
exports.CommandAcceptedListener = CommandAcceptedListener;
|
|
23
37
|
//# sourceMappingURL=PluginCommandAccepted.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginCommandAccepted.js","sourceRoot":"","sources":["../../src/listeners/PluginCommandAccepted.ts"],"names":[],"mappings":";;;AAAA,
|
|
1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CAAC,CAAC;YAEjF,OAAO,MAAM,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QACtC,IAAI,IAAA,iBAAK,EAAC,MAAM,CAAC,EAAE;YAClB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,0CAAoB,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;SACjG;QAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,0CAAoB,CAAC,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvF,CAAC;CACD;AAlCD,0DAkCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-pattern-commands",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1-next.3fe7e48.0",
|
|
4
4
|
"description": "Plugin for @sapphire/framework that adds support for pattern commands.",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "3fe7e48a3577df6d9addc613cae74ccb07e41639"
|
|
69
69
|
}
|