reciple 6.0.0-dev.2 → 6.0.0-dev.21
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/lib/bin.mjs +65 -0
- package/dist/lib/esm.mjs +1 -0
- package/dist/{cjs → lib}/index.js +18 -17
- package/dist/{cjs → lib}/reciple/classes/RecipleClient.js +19 -22
- package/dist/{cjs → lib}/reciple/classes/RecipleConfig.js +10 -10
- package/dist/lib/reciple/classes/RecipleModule.js +94 -0
- package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js +325 -0
- package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandOptionBuilder.js +35 -13
- package/dist/{cjs → lib}/reciple/classes/builders/SlashCommandBuilder.js +42 -15
- package/dist/{cjs → lib}/reciple/classes/managers/ApplicationCommandManager.js +64 -23
- package/dist/{cjs → lib}/reciple/classes/managers/CommandCooldownManager.js +0 -0
- package/dist/{cjs/reciple/classes/managers/ClientCommandManager.js → lib/reciple/classes/managers/CommandManager.js} +14 -15
- package/dist/{cjs → lib}/reciple/classes/managers/MessageCommandOptionManager.js +0 -0
- package/dist/lib/reciple/classes/managers/ModuleManager.js +179 -0
- package/dist/{cjs → lib}/reciple/flags.js +2 -2
- package/dist/{cjs → lib}/reciple/permissions.js +0 -0
- package/dist/lib/reciple/types/builders.js +11 -0
- package/dist/{cjs → lib}/reciple/types/commands.js +6 -6
- package/dist/{cjs → lib}/reciple/types/paramOptions.js +0 -0
- package/dist/{cjs/reciple/logger.js → lib/reciple/util.js} +33 -2
- package/dist/{cjs → lib}/reciple/version.js +0 -1
- package/dist/types/{bin.d.ts → bin.d.mts} +0 -0
- package/dist/types/esm.d.mts +1 -0
- package/dist/types/index.d.ts +18 -17
- package/dist/types/reciple/classes/RecipleClient.d.ts +7 -5
- package/dist/types/reciple/classes/RecipleConfig.d.ts +3 -2
- package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
- package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +60 -26
- package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +15 -7
- package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +20 -10
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +43 -10
- package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +2 -2
- package/dist/types/reciple/classes/managers/{ClientCommandManager.d.ts → CommandManager.d.ts} +6 -7
- package/dist/types/reciple/classes/managers/ModuleManager.d.ts +49 -0
- package/dist/types/reciple/types/builders.d.ts +8 -8
- package/dist/types/reciple/types/commands.d.ts +16 -16
- package/dist/types/reciple/types/paramOptions.d.ts +79 -18
- package/dist/types/reciple/util.d.ts +11 -0
- package/package.json +28 -21
- package/resource/reciple.yml +25 -22
- package/dist/cjs/bin.js +0 -50
- package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +0 -242
- package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +0 -193
- package/dist/cjs/reciple/types/builders.js +0 -11
- package/dist/cjs/reciple/util.js +0 -32
- package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +0 -79
- package/dist/types/reciple/logger.d.ts +0 -8
- package/docs/README.md +0 -1
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
import { RecipleModule, RecipleScript } from '../classes/managers/ClientModuleManager';
|
|
2
1
|
import { ConfigCommandPermissions } from '../classes/RecipleConfig';
|
|
3
|
-
import { PermissionsBitField } from 'discord.js';
|
|
2
|
+
import { Awaitable, PermissionsBitField } from 'discord.js';
|
|
4
3
|
import { AnyCommandBuilder } from './builders';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The module script
|
|
8
|
-
*/
|
|
9
|
-
script: RecipleScript;
|
|
10
|
-
/**
|
|
11
|
-
* Register application commands if possible
|
|
12
|
-
*/
|
|
13
|
-
registerApplicationCommands?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Module optional info
|
|
16
|
-
*/
|
|
17
|
-
moduleInfo?: RecipleModule['info'];
|
|
18
|
-
}
|
|
4
|
+
import { RecipleModule } from '../classes/RecipleModule';
|
|
19
5
|
export interface UserHasCommandPermissionsOptions {
|
|
20
6
|
/**
|
|
21
7
|
* Command builder
|
|
@@ -33,8 +19,83 @@ export interface UserHasCommandPermissionsOptions {
|
|
|
33
19
|
commands: ConfigCommandPermissions[];
|
|
34
20
|
};
|
|
35
21
|
}
|
|
36
|
-
export interface
|
|
22
|
+
export interface ModuleManagerResolveModuleFilesOptions {
|
|
23
|
+
/**
|
|
24
|
+
* valid reciple module (ESM or CJS) Javascript file paths
|
|
25
|
+
*/
|
|
37
26
|
files: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Allow loading unsupported module versions
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
38
31
|
disabeVersionCheck?: boolean;
|
|
39
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Ignore errors
|
|
34
|
+
* @dafault true
|
|
35
|
+
*/
|
|
36
|
+
ignoreErrors?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ModuleManagerGetModulePathsOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Get javascript module file paths from folders
|
|
41
|
+
*/
|
|
42
|
+
folders?: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Add ignored files (wildcard)
|
|
45
|
+
* @example _*.js // Ignores _module.js and _hi.js
|
|
46
|
+
*/
|
|
47
|
+
ignoredFiles?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Filter found javascript files
|
|
50
|
+
* @param file Loaded javascript file
|
|
51
|
+
* @returns `true` if the path is acceptable
|
|
52
|
+
*/
|
|
53
|
+
filter?: (file: string) => Awaitable<boolean>;
|
|
54
|
+
}
|
|
55
|
+
export interface ModuleManagerStartModulesOptions {
|
|
56
|
+
/**
|
|
57
|
+
* Modules to start
|
|
58
|
+
*/
|
|
59
|
+
modules: RecipleModule[];
|
|
60
|
+
/**
|
|
61
|
+
* Add modules to Client modules collection
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
addToModulesCollection?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Ignore errors
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
ignoreErrors?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface ModuleManagerLoadModulesOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Modules to execute `load` method
|
|
74
|
+
*/
|
|
75
|
+
modules?: RecipleModule[];
|
|
76
|
+
/**
|
|
77
|
+
* Add commands to client
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
resolveCommands?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Ignore errors
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
ignoreErrors?: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface ModuleManagerUnloadModulesOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Modules to execute `unload` method
|
|
90
|
+
*/
|
|
91
|
+
modules?: RecipleModule[];
|
|
92
|
+
/**
|
|
93
|
+
* Reason for unloading modules
|
|
94
|
+
*/
|
|
95
|
+
reason?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Ignore errors
|
|
98
|
+
* @default true
|
|
99
|
+
*/
|
|
100
|
+
ignoreErrors?: boolean;
|
|
40
101
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Logger } from 'fallout-utility';
|
|
3
|
+
import { default as _path } from 'path';
|
|
1
4
|
import { AnyCommandBuilder } from './types/builders';
|
|
2
5
|
/**
|
|
3
6
|
* Check if an object is a class
|
|
@@ -10,3 +13,11 @@ export declare function isClass<T = any>(object: any): object is T;
|
|
|
10
13
|
*/
|
|
11
14
|
export declare function deprecationWarning(content: string | Error): void;
|
|
12
15
|
export declare function validateCommandBuilder(command: AnyCommandBuilder): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Create new logger
|
|
18
|
+
* @param stringifyJSON stringify json objects in console
|
|
19
|
+
* @param debugmode display debug messages
|
|
20
|
+
* @param colorizeMessage add logger colours to messages
|
|
21
|
+
*/
|
|
22
|
+
export declare function createLogger(stringifyJSON: boolean, debugmode?: boolean, colorizeMessage?: boolean): Logger;
|
|
23
|
+
export declare const path: _path.PlatformPath;
|
package/package.json
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reciple",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
4
|
-
"bin": "./dist/
|
|
3
|
+
"version": "6.0.0-dev.21",
|
|
4
|
+
"bin": "./dist/lib/bin.mjs",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
|
-
"
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "./dist/lib/index.js",
|
|
7
8
|
"types": "./dist/types/index.d.ts",
|
|
8
|
-
"module": "./dist/
|
|
9
|
+
"module": "./dist/lib/esm.mjs",
|
|
9
10
|
"author": "FalloutStudios",
|
|
10
11
|
"description": "Handler for Discord.js",
|
|
11
12
|
"homepage": "https://reciple.js.org",
|
|
12
13
|
"exports": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/types/index.d.ts",
|
|
17
|
+
"default": "./dist/lib/esm.mjs"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"default": "./dist/lib/index.js"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
16
24
|
},
|
|
17
25
|
"keywords": [
|
|
18
26
|
"Discord",
|
|
@@ -26,14 +34,14 @@
|
|
|
26
34
|
"url": "https://github.com/FalloutStudios/reciple/issues"
|
|
27
35
|
},
|
|
28
36
|
"scripts": {
|
|
29
|
-
"format": "
|
|
30
|
-
"clean": "
|
|
31
|
-
"build": "
|
|
32
|
-
"build:publish": "
|
|
33
|
-
"build:publish-dev": "
|
|
34
|
-
"test": "
|
|
35
|
-
"docs": "
|
|
36
|
-
"watch": "
|
|
37
|
+
"format": "npx prettier --write src",
|
|
38
|
+
"clean": "npx rimraf dist",
|
|
39
|
+
"build": "npm run clean && npx tsc",
|
|
40
|
+
"build:publish": "npm run format && npm run build && npm run docs && npm publish",
|
|
41
|
+
"build:publish-dev": "npm run format && npm run build && npm publish --tag dev",
|
|
42
|
+
"test": "npm run build && npm install && npm run start -w test",
|
|
43
|
+
"docs": "npx docgen --typescript true -c ./docs/index.json -o ./docs/docs.json -i src/index.ts",
|
|
44
|
+
"watch": "npx tsc --watch --noEmit"
|
|
37
45
|
},
|
|
38
46
|
"repository": {
|
|
39
47
|
"type": "git",
|
|
@@ -53,15 +61,15 @@
|
|
|
53
61
|
"chalk": "4.1.2",
|
|
54
62
|
"commander": "^9.4.1",
|
|
55
63
|
"dotenv": "^16.0.3",
|
|
56
|
-
"fallout-utility": "^1.5.
|
|
64
|
+
"fallout-utility": "^1.5.13",
|
|
57
65
|
"semver": "^7.3.7",
|
|
58
66
|
"wildcard-match": "^5.1.2",
|
|
59
67
|
"yaml": "^2.1.1"
|
|
60
68
|
},
|
|
61
69
|
"devDependencies": {
|
|
62
70
|
"@discordjs/docgen": "^0.12.1",
|
|
63
|
-
"@types/node": "^18.11.
|
|
64
|
-
"@types/semver": "^7.3.
|
|
71
|
+
"@types/node": "^18.11.7",
|
|
72
|
+
"@types/semver": "^7.3.13",
|
|
65
73
|
"discord.js": "^14.6.0",
|
|
66
74
|
"prettier": "2.7.1",
|
|
67
75
|
"rimraf": "^3.0.2",
|
|
@@ -72,6 +80,5 @@
|
|
|
72
80
|
},
|
|
73
81
|
"workspaces": [
|
|
74
82
|
"test"
|
|
75
|
-
]
|
|
76
|
-
|
|
77
|
-
}
|
|
83
|
+
]
|
|
84
|
+
}
|
package/resource/reciple.yml
CHANGED
|
@@ -4,20 +4,24 @@ token: TOKEN
|
|
|
4
4
|
|
|
5
5
|
# Commands options
|
|
6
6
|
commands:
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
-
# enable
|
|
7
|
+
# Interaction command options
|
|
8
|
+
slashCommand:
|
|
9
|
+
# enable interaction commands
|
|
10
10
|
enabled: true
|
|
11
|
-
# command prefix
|
|
12
|
-
prefix: '!'
|
|
13
11
|
# reply when an error occured
|
|
14
12
|
replyOnError: false
|
|
15
13
|
# enable the use of command cooldowns
|
|
16
14
|
enableCooldown: true
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
#
|
|
20
|
-
|
|
15
|
+
# register interaction commands on bot ready
|
|
16
|
+
registerCommands: true
|
|
17
|
+
# allow register empty list of application commands
|
|
18
|
+
allowRegisterEmptyCommandList: true
|
|
19
|
+
# set required permissions for interaction commands
|
|
20
|
+
setRequiredPermissions: true
|
|
21
|
+
# accept replied or deffered command interaction
|
|
22
|
+
acceptRepliedInteractions: false
|
|
23
|
+
# register commands to specific guild(s) empty to make it global
|
|
24
|
+
guilds: []
|
|
21
25
|
# overwrite command permissions
|
|
22
26
|
permissions:
|
|
23
27
|
# enable overwriten command permissions
|
|
@@ -27,22 +31,20 @@ commands:
|
|
|
27
31
|
permissions:
|
|
28
32
|
- Administrator
|
|
29
33
|
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
# enable
|
|
34
|
+
# message command options
|
|
35
|
+
messageCommand:
|
|
36
|
+
# enable message commands
|
|
33
37
|
enabled: true
|
|
38
|
+
# command prefix
|
|
39
|
+
prefix: '!'
|
|
34
40
|
# reply when an error occured
|
|
35
41
|
replyOnError: false
|
|
36
42
|
# enable the use of command cooldowns
|
|
37
43
|
enableCooldown: true
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
#
|
|
41
|
-
|
|
42
|
-
# accept replied or deffered command interaction
|
|
43
|
-
acceptRepliedInteractions: false
|
|
44
|
-
# register commands to specific guild(s) empty to make it global
|
|
45
|
-
guilds: []
|
|
44
|
+
# allow executing commands via aliases
|
|
45
|
+
allowCommandAlias: true
|
|
46
|
+
# command argument separator
|
|
47
|
+
commandArgumentSeparator: ' '
|
|
46
48
|
# overwrite command permissions
|
|
47
49
|
permissions:
|
|
48
50
|
# enable overwriten command permissions
|
|
@@ -52,7 +54,6 @@ commands:
|
|
|
52
54
|
permissions:
|
|
53
55
|
- Administrator
|
|
54
56
|
|
|
55
|
-
|
|
56
57
|
# Logger options
|
|
57
58
|
fileLogging:
|
|
58
59
|
# enable console output to file
|
|
@@ -93,7 +94,9 @@ messages:
|
|
|
93
94
|
ephemeral: true
|
|
94
95
|
|
|
95
96
|
# Ignored Files
|
|
96
|
-
ignoredFiles:
|
|
97
|
+
ignoredFiles:
|
|
98
|
+
- '_*'
|
|
99
|
+
- '.*'
|
|
97
100
|
|
|
98
101
|
|
|
99
102
|
####################################################
|
package/dist/cjs/bin.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const RecipleClient_1 = require("./reciple/classes/RecipleClient");
|
|
8
|
-
const RecipleConfig_1 = require("./reciple/classes/RecipleConfig");
|
|
9
|
-
const version_1 = require("./reciple/version");
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
const flags_1 = require("./reciple/flags");
|
|
12
|
-
const fallout_utility_1 = require("fallout-utility");
|
|
13
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
-
require("dotenv/config");
|
|
15
|
-
const path_1 = __importDefault(require("path"));
|
|
16
|
-
const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
|
|
17
|
-
const configPath = path_1.default.join(flags_1.cwd, './reciple.yml');
|
|
18
|
-
if ((0, fs_1.readdirSync)(flags_1.cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !(0, fs_1.existsSync)(flags_1.flags.config ?? configPath)) {
|
|
19
|
-
const ask = (flags_1.flags.yes ? 'y' : null) ?? (0, fallout_utility_1.input)('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ') ?? '';
|
|
20
|
-
if (ask.toString().toLowerCase() !== 'y')
|
|
21
|
-
process.exit(0);
|
|
22
|
-
}
|
|
23
|
-
let configParser;
|
|
24
|
-
try {
|
|
25
|
-
configParser = new RecipleConfig_1.RecipleConfig(flags_1.flags.config ?? configPath).parseConfig();
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
console.error(`${chalk_1.default.bold.red('Config Error')}: ${chalk_1.default.white(err.message)}`);
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
const config = configParser.getConfig();
|
|
32
|
-
const client = new RecipleClient_1.RecipleClient({ config: config, ...config.client });
|
|
33
|
-
if (!client.isClientLogsSilent)
|
|
34
|
-
client.logger.info('Starting Reciple client v' + version_1.rawVersion);
|
|
35
|
-
(async () => {
|
|
36
|
-
client.addCommandListeners();
|
|
37
|
-
await client.modules.startModulesFromFiles({
|
|
38
|
-
files: await client.modules.getModuleFiles(),
|
|
39
|
-
});
|
|
40
|
-
client.on('ready', async () => {
|
|
41
|
-
await client.modules.loadAll(true);
|
|
42
|
-
if (!client.isClientLogsSilent)
|
|
43
|
-
client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
|
|
44
|
-
client.on('cacheSweep', () => client.cooldowns.clean());
|
|
45
|
-
});
|
|
46
|
-
client.login(config.token).catch(err => {
|
|
47
|
-
if (!client.isClientLogsSilent)
|
|
48
|
-
client.logger.error(err);
|
|
49
|
-
});
|
|
50
|
-
})();
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
|
|
4
|
-
const builders_1 = require("../../types/builders");
|
|
5
|
-
const discord_js_1 = require("discord.js");
|
|
6
|
-
const MessageCommandOptionManager_1 = require("../managers/MessageCommandOptionManager");
|
|
7
|
-
const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
8
|
-
/**
|
|
9
|
-
* Reciple builder for message command
|
|
10
|
-
*/
|
|
11
|
-
class MessageCommandBuilder {
|
|
12
|
-
constructor(data) {
|
|
13
|
-
this.type = builders_1.CommandBuilderType.MessageCommand;
|
|
14
|
-
this.name = '';
|
|
15
|
-
this.description = '';
|
|
16
|
-
this.cooldown = 0;
|
|
17
|
-
this.aliases = [];
|
|
18
|
-
this.validateOptions = false;
|
|
19
|
-
this.options = [];
|
|
20
|
-
this.requiredBotPermissions = [];
|
|
21
|
-
this.requiredMemberPermissions = [];
|
|
22
|
-
this.allowExecuteInDM = true;
|
|
23
|
-
this.allowExecuteByBots = false;
|
|
24
|
-
this.execute = () => {
|
|
25
|
-
/* Execute */
|
|
26
|
-
};
|
|
27
|
-
if (data?.name !== undefined)
|
|
28
|
-
this.setName(data.name);
|
|
29
|
-
if (data?.description !== undefined)
|
|
30
|
-
this.setDescription(data.description);
|
|
31
|
-
if (data?.aliases !== undefined)
|
|
32
|
-
this.addAliases(data.aliases);
|
|
33
|
-
if (data?.cooldown !== undefined)
|
|
34
|
-
this.setCooldown(Number(data?.cooldown));
|
|
35
|
-
if (data?.requiredBotPermissions !== undefined)
|
|
36
|
-
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
37
|
-
if (data?.requiredMemberPermissions !== undefined)
|
|
38
|
-
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
39
|
-
if (data?.halt !== undefined)
|
|
40
|
-
this.setHalt(data.halt);
|
|
41
|
-
if (data?.execute !== undefined)
|
|
42
|
-
this.setExecute(data.execute);
|
|
43
|
-
if (data?.metadata !== undefined)
|
|
44
|
-
this.setMetadata(data.metadata);
|
|
45
|
-
if (data?.allowExecuteByBots !== undefined)
|
|
46
|
-
this.setAllowExecuteByBots(true);
|
|
47
|
-
if (data?.allowExecuteInDM !== undefined)
|
|
48
|
-
this.setAllowExecuteInDM(true);
|
|
49
|
-
if (data?.validateOptions !== undefined)
|
|
50
|
-
this.setValidateOptions(true);
|
|
51
|
-
if (data?.options !== undefined)
|
|
52
|
-
this.options = data.options.map(o => (o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o)));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Sets the command name
|
|
56
|
-
* @param name Command name
|
|
57
|
-
*/
|
|
58
|
-
setName(name) {
|
|
59
|
-
if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
60
|
-
throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/');
|
|
61
|
-
this.name = name;
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Sets the command description
|
|
66
|
-
* @param description Command description
|
|
67
|
-
*/
|
|
68
|
-
setDescription(description) {
|
|
69
|
-
if (!description || typeof description !== 'string')
|
|
70
|
-
throw new TypeError('description must be a string.');
|
|
71
|
-
this.description = description;
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Add aliases to the command
|
|
76
|
-
* @param aliases Command aliases
|
|
77
|
-
*/
|
|
78
|
-
addAliases(...aliases) {
|
|
79
|
-
aliases = (0, discord_js_1.normalizeArray)(aliases);
|
|
80
|
-
if (!aliases.length)
|
|
81
|
-
throw new TypeError('Provide atleast one alias');
|
|
82
|
-
if (aliases.some(a => !a || typeof a !== 'string' || a.match(/^\s+$/)))
|
|
83
|
-
throw new TypeError('aliases must be strings and should not contain whitespaces');
|
|
84
|
-
if (this.name && aliases.some(a => a == this.name))
|
|
85
|
-
throw new TypeError('alias cannot have same name to its real command name');
|
|
86
|
-
this.aliases = [...new Set(aliases.map(s => s.toLowerCase()))];
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Set if command can be executed in dms
|
|
91
|
-
* @param allowExecuteInDM `true` if the command can execute in DMs
|
|
92
|
-
*/
|
|
93
|
-
setAllowExecuteInDM(allowExecuteInDM) {
|
|
94
|
-
if (typeof allowExecuteInDM !== 'boolean')
|
|
95
|
-
throw new TypeError('allowExecuteInDM must be a boolean.');
|
|
96
|
-
this.allowExecuteInDM = allowExecuteInDM;
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Allow command to be executed by bots
|
|
101
|
-
* @param allowExecuteByBots `true` if the command can be executed by bots
|
|
102
|
-
*/
|
|
103
|
-
setAllowExecuteByBots(allowExecuteByBots) {
|
|
104
|
-
if (typeof allowExecuteByBots !== 'boolean')
|
|
105
|
-
throw new TypeError('allowExecuteByBots must be a boolean.');
|
|
106
|
-
this.allowExecuteByBots = allowExecuteByBots;
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Add option to the command
|
|
111
|
-
* @param option Message option builder
|
|
112
|
-
*/
|
|
113
|
-
addOption(option) {
|
|
114
|
-
if (!option)
|
|
115
|
-
throw new TypeError('option must be a MessageOption.');
|
|
116
|
-
option = typeof option === 'function' ? option(new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder()) : option;
|
|
117
|
-
if (this.options.find(o => o.name === option.name))
|
|
118
|
-
throw new TypeError('option with name "' + option.name + '" already exists.');
|
|
119
|
-
if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
|
|
120
|
-
throw new TypeError('All required options must be before optional options.');
|
|
121
|
-
this.options.push(option);
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Validate options before executing
|
|
126
|
-
* @param validateOptions `true` if the command options needs to be validated before executing
|
|
127
|
-
*/
|
|
128
|
-
setValidateOptions(validateOptions) {
|
|
129
|
-
if (typeof validateOptions !== 'boolean')
|
|
130
|
-
throw new TypeError('validateOptions must be a boolean.');
|
|
131
|
-
this.validateOptions = validateOptions;
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
setCooldown(cooldown) {
|
|
135
|
-
this.cooldown = cooldown;
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
setRequiredBotPermissions(...permissions) {
|
|
139
|
-
this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
setRequiredMemberPermissions(...permissions) {
|
|
143
|
-
this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
setHalt(halt) {
|
|
147
|
-
this.halt = halt ?? undefined;
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
setExecute(execute) {
|
|
151
|
-
if (!execute || typeof execute !== 'function')
|
|
152
|
-
throw new TypeError('execute must be a function.');
|
|
153
|
-
this.execute = execute;
|
|
154
|
-
return this;
|
|
155
|
-
}
|
|
156
|
-
setMetadata(metadata) {
|
|
157
|
-
this.metadata = metadata;
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Returns JSON object of this builder
|
|
162
|
-
*/
|
|
163
|
-
toJSON() {
|
|
164
|
-
return {
|
|
165
|
-
type: this.type,
|
|
166
|
-
name: this.name,
|
|
167
|
-
description: this.description,
|
|
168
|
-
aliases: this.aliases,
|
|
169
|
-
cooldown: this.cooldown,
|
|
170
|
-
requiredBotPermissions: this.requiredBotPermissions,
|
|
171
|
-
requiredMemberPermissions: this.requiredMemberPermissions,
|
|
172
|
-
halt: this.halt,
|
|
173
|
-
execute: this.execute,
|
|
174
|
-
metadata: this.metadata,
|
|
175
|
-
allowExecuteByBots: this.allowExecuteByBots,
|
|
176
|
-
allowExecuteInDM: this.allowExecuteInDM,
|
|
177
|
-
validateOptions: this.validateOptions,
|
|
178
|
-
options: this.options.map(o => o.toJSON()),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Resolve message command data/builder
|
|
183
|
-
* @param commandData Command data to resolve
|
|
184
|
-
*/
|
|
185
|
-
static resolveMessageCommand(commandData) {
|
|
186
|
-
return this.isMessageCommandBuilder(commandData) ? commandData : new MessageCommandBuilder(commandData);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Is a message command builder
|
|
190
|
-
* @param builder data to check
|
|
191
|
-
*/
|
|
192
|
-
static isMessageCommandBuilder(builder) {
|
|
193
|
-
return builder instanceof MessageCommandBuilder;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Is a message command execute data
|
|
197
|
-
* @param executeData data to check
|
|
198
|
-
*/
|
|
199
|
-
static isMessageCommandExecuteData(executeData) {
|
|
200
|
-
return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
exports.MessageCommandBuilder = MessageCommandBuilder;
|
|
204
|
-
/**
|
|
205
|
-
* Validate message command options
|
|
206
|
-
* @param builder Command builder
|
|
207
|
-
* @param options Parsed command args
|
|
208
|
-
*/
|
|
209
|
-
async function validateMessageCommandOptions(builder, options) {
|
|
210
|
-
const args = options.args || [];
|
|
211
|
-
const required = builder.options.filter(o => o.required);
|
|
212
|
-
const optional = builder.options.filter(o => !o.required);
|
|
213
|
-
const allOptions = [...required, ...optional];
|
|
214
|
-
const result = [];
|
|
215
|
-
let i = 0;
|
|
216
|
-
for (const option of allOptions) {
|
|
217
|
-
const arg = args[i];
|
|
218
|
-
const value = {
|
|
219
|
-
name: option.name,
|
|
220
|
-
value: arg ?? undefined,
|
|
221
|
-
required: option.required,
|
|
222
|
-
invalid: false,
|
|
223
|
-
missing: false,
|
|
224
|
-
};
|
|
225
|
-
if (arg == undefined && option.required) {
|
|
226
|
-
value.missing = true;
|
|
227
|
-
result.push(value);
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
if (arg == undefined && !option.required) {
|
|
231
|
-
result.push(value);
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
const validate = option.validator ? await Promise.resolve(option.validator(arg)) : true;
|
|
235
|
-
if (!validate)
|
|
236
|
-
value.invalid = true;
|
|
237
|
-
result.push(value);
|
|
238
|
-
i++;
|
|
239
|
-
}
|
|
240
|
-
return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
|
|
241
|
-
}
|
|
242
|
-
exports.validateMessageCommandOptions = validateMessageCommandOptions;
|