reciple 6.0.0-dev.1 → 6.0.0-dev.12
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 +53 -0
- package/dist/lib/esm.mjs +1 -0
- package/dist/{cjs → lib}/index.js +18 -18
- package/dist/{cjs → lib}/reciple/classes/RecipleClient.js +88 -47
- package/dist/{cjs → lib}/reciple/classes/RecipleConfig.js +13 -6
- package/dist/lib/reciple/classes/RecipleModule.js +94 -0
- package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandBuilder.js +6 -4
- package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandOptionBuilder.js +0 -0
- package/dist/{cjs → lib}/reciple/classes/builders/SlashCommandBuilder.js +12 -23
- package/dist/{cjs → lib}/reciple/classes/managers/ApplicationCommandManager.js +32 -33
- package/dist/{cjs → lib}/reciple/classes/managers/ClientCommandManager.js +14 -14
- package/dist/lib/reciple/classes/managers/ClientModuleManager.js +144 -0
- package/dist/{cjs → lib}/reciple/classes/managers/CommandCooldownManager.js +7 -1
- package/dist/{cjs → lib}/reciple/classes/managers/MessageCommandOptionManager.js +0 -0
- package/dist/{cjs → lib}/reciple/flags.js +2 -2
- package/dist/{cjs → lib}/reciple/permissions.js +3 -4
- package/dist/lib/reciple/types/builders.js +11 -0
- package/dist/{cjs → lib}/reciple/types/commands.js +0 -0
- package/dist/{cjs → lib}/reciple/types/paramOptions.js +0 -0
- package/dist/lib/reciple/util.js +66 -0
- 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 -18
- package/dist/types/reciple/classes/RecipleClient.d.ts +3 -6
- package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
- package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +6 -6
- package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +17 -17
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +6 -11
- package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +3 -3
- package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +11 -71
- package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +2 -2
- package/dist/types/reciple/types/builders.d.ts +19 -19
- package/dist/types/reciple/types/commands.d.ts +10 -10
- package/dist/types/reciple/types/paramOptions.d.ts +7 -17
- package/dist/types/reciple/util.d.ts +8 -0
- package/package.json +28 -18
- package/dist/cjs/bin.js +0 -50
- package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +0 -189
- package/dist/cjs/reciple/logger.js +0 -35
- package/dist/cjs/reciple/modules.js +0 -113
- package/dist/cjs/reciple/types/builders.js +0 -11
- package/dist/cjs/reciple/util.js +0 -32
- package/dist/types/reciple/logger.d.ts +0 -8
- package/dist/types/reciple/modules.d.ts +0 -64
- package/docs/README.md +0 -1
package/package.json
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reciple",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
4
|
-
"bin": "./dist/
|
|
3
|
+
"version": "6.0.0-dev.12",
|
|
4
|
+
"bin": "./dist/lib/bin.mjs",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "./dist/lib/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"module": "./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
|
-
|
|
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
|
+
}
|
|
15
24
|
},
|
|
16
25
|
"keywords": [
|
|
17
26
|
"Discord",
|
|
@@ -25,13 +34,14 @@
|
|
|
25
34
|
"url": "https://github.com/FalloutStudios/reciple/issues"
|
|
26
35
|
},
|
|
27
36
|
"scripts": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"build
|
|
31
|
-
"build:publish
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
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"
|
|
35
45
|
},
|
|
36
46
|
"repository": {
|
|
37
47
|
"type": "git",
|
|
@@ -51,7 +61,7 @@
|
|
|
51
61
|
"chalk": "4.1.2",
|
|
52
62
|
"commander": "^9.4.1",
|
|
53
63
|
"dotenv": "^16.0.3",
|
|
54
|
-
"fallout-utility": "^1.5.
|
|
64
|
+
"fallout-utility": "^1.5.13",
|
|
55
65
|
"semver": "^7.3.7",
|
|
56
66
|
"wildcard-match": "^5.1.2",
|
|
57
67
|
"yaml": "^2.1.1"
|
|
@@ -61,6 +71,7 @@
|
|
|
61
71
|
"@types/node": "^18.11.0",
|
|
62
72
|
"@types/semver": "^7.3.12",
|
|
63
73
|
"discord.js": "^14.6.0",
|
|
74
|
+
"prettier": "2.7.1",
|
|
64
75
|
"rimraf": "^3.0.2",
|
|
65
76
|
"typescript": "^4.8.4"
|
|
66
77
|
},
|
|
@@ -69,6 +80,5 @@
|
|
|
69
80
|
},
|
|
70
81
|
"workspaces": [
|
|
71
82
|
"test"
|
|
72
|
-
]
|
|
73
|
-
|
|
74
|
-
}
|
|
83
|
+
]
|
|
84
|
+
}
|
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 (config.fileLogging.clientLogs)
|
|
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.isClientLogsEnabled())
|
|
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.isClientLogsEnabled())
|
|
48
|
-
client.logger.error(err);
|
|
49
|
-
});
|
|
50
|
-
})();
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.ClientModuleManager = void 0;
|
|
30
|
-
const crypto_1 = require("crypto");
|
|
31
|
-
const discord_js_1 = require("discord.js");
|
|
32
|
-
const fs_1 = require("fs");
|
|
33
|
-
const path_1 = __importDefault(require("path"));
|
|
34
|
-
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
35
|
-
const flags_1 = require("../../flags");
|
|
36
|
-
const builders_1 = require("../../types/builders");
|
|
37
|
-
const util_1 = require("../../util");
|
|
38
|
-
const version_1 = require("../../version");
|
|
39
|
-
const MessageCommandBuilder_1 = require("../builders/MessageCommandBuilder");
|
|
40
|
-
const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
|
|
41
|
-
class ClientModuleManager {
|
|
42
|
-
constructor(options) {
|
|
43
|
-
this.modules = new discord_js_1.Collection();
|
|
44
|
-
this.client = options.client;
|
|
45
|
-
options.modules?.forEach(m => {
|
|
46
|
-
if (!m.id)
|
|
47
|
-
m.id = (0, crypto_1.randomUUID)();
|
|
48
|
-
this.modules.set(m.id, this.resolveModule(m));
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async startModulesFromFiles(options) {
|
|
52
|
-
const modules = await this.resolveModulesFromFiles(options);
|
|
53
|
-
for (const module_ of modules) {
|
|
54
|
-
try {
|
|
55
|
-
await this.startModule(module_);
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
if (options.dontSkipError)
|
|
59
|
-
throw err;
|
|
60
|
-
if (this.client.isClientLogsEnabled())
|
|
61
|
-
this.client.logger.err(`Cannot start module ${ClientModuleManager.getModuleDisplayId(module_)}:`, err);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return modules;
|
|
65
|
-
}
|
|
66
|
-
async resolveModulesFromFiles(options) {
|
|
67
|
-
const modules = [];
|
|
68
|
-
const isVersionCheckDisabled = (options.disabeVersionCheck || this.client.config.disableVersionCheck);
|
|
69
|
-
for (const file of options.files) {
|
|
70
|
-
const moduleFileName = path_1.default.basename(file);
|
|
71
|
-
const moduleDirPath = path_1.default.dirname(file);
|
|
72
|
-
const id = (0, crypto_1.randomUUID)();
|
|
73
|
-
let script;
|
|
74
|
-
try {
|
|
75
|
-
const resolveModuleFile = await Promise.resolve().then(() => __importStar(require(file)));
|
|
76
|
-
script = resolveModuleFile?.default ?? resolveModuleFile;
|
|
77
|
-
const module_ = this.resolveModule({
|
|
78
|
-
id,
|
|
79
|
-
script,
|
|
80
|
-
info: {
|
|
81
|
-
filename: moduleFileName,
|
|
82
|
-
path: moduleDirPath
|
|
83
|
-
}
|
|
84
|
-
}, isVersionCheckDisabled);
|
|
85
|
-
modules.push(module_);
|
|
86
|
-
if (this.client.isClientLogsEnabled())
|
|
87
|
-
this.client.logger.log(`Resolved ${file}`);
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
if (options.dontSkipError)
|
|
91
|
-
throw err;
|
|
92
|
-
if (this.client.isClientLogsEnabled())
|
|
93
|
-
this.client.logger.err(`Cannot resolve module file ${file}:`, err);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return modules;
|
|
97
|
-
}
|
|
98
|
-
resolveScriptCommands(...modules) {
|
|
99
|
-
const resolvedCommands = [];
|
|
100
|
-
for (const script of (0, discord_js_1.normalizeArray)(modules)) {
|
|
101
|
-
const commands = [];
|
|
102
|
-
if (Array.isArray(script?.commands)) {
|
|
103
|
-
for (const command of script.commands) {
|
|
104
|
-
if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
105
|
-
commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
106
|
-
}
|
|
107
|
-
else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
108
|
-
commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const invalidBuilders = commands.some(c => !(0, util_1.validateCommandBuilder)(c));
|
|
113
|
-
if (invalidBuilders)
|
|
114
|
-
throw new Error(`Module script commands contains a command builder without name or option name`);
|
|
115
|
-
resolvedCommands.push({
|
|
116
|
-
script,
|
|
117
|
-
commands
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return resolvedCommands;
|
|
121
|
-
}
|
|
122
|
-
async loadAll(registerApplicationCommands, ...registerApplicationCommandsGuilds) {
|
|
123
|
-
await Promise.all(this.modules.map(async (m) => {
|
|
124
|
-
if (typeof m.script?.onLoad === 'function') {
|
|
125
|
-
try {
|
|
126
|
-
await Promise.resolve(m.script.onLoad(this.client)).catch(err => { throw err; });
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
this.modules.delete(m.id);
|
|
130
|
-
if (this.client.isClientLogsEnabled())
|
|
131
|
-
this.client.logger.error(`Error loading ${m.info.filename ?? 'unknown module'}:`, err);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
this.client.commands.add(m.commands);
|
|
136
|
-
if (this.client.isClientLogsEnabled())
|
|
137
|
-
this.client.logger.log(`Loaded module: ${ClientModuleManager.getModuleDisplayId(m)}`);
|
|
138
|
-
}));
|
|
139
|
-
if (this.client.isClientLogsEnabled()) {
|
|
140
|
-
this.client.logger.info(`${this.modules.size} modules loaded.`);
|
|
141
|
-
this.client.logger.info(`${this.client.commands.messageCommands.size} message commands loaded.`);
|
|
142
|
-
this.client.logger.info(`${this.client.commands.slashCommands.size} slash commands loaded.`);
|
|
143
|
-
}
|
|
144
|
-
if (registerApplicationCommands)
|
|
145
|
-
this.client.commands.registerApplicationCommands((0, discord_js_1.normalizeArray)(registerApplicationCommandsGuilds));
|
|
146
|
-
}
|
|
147
|
-
async startModule(mod) {
|
|
148
|
-
let err;
|
|
149
|
-
const identifier = ClientModuleManager.getModuleDisplayId(mod);
|
|
150
|
-
if (this.client.isClientLogsEnabled())
|
|
151
|
-
this.client.logger.log(`Starting Module: ${identifier}`);
|
|
152
|
-
const start = await Promise.resolve(mod.script.onStart(this.client)).catch(e => err = e);
|
|
153
|
-
if (err)
|
|
154
|
-
throw err;
|
|
155
|
-
if (!start)
|
|
156
|
-
throw new Error(`Module ${identifier} returned 'false' on start`);
|
|
157
|
-
this.modules.set(mod.id, mod);
|
|
158
|
-
}
|
|
159
|
-
resolveModule(mod, disabeVersionCheck) {
|
|
160
|
-
const identifier = ClientModuleManager.getModuleDisplayId(mod);
|
|
161
|
-
if (!disabeVersionCheck && !mod?.script?.versions?.length)
|
|
162
|
-
throw new Error(`Module ${identifier} does not contain supported versions`);
|
|
163
|
-
if (typeof mod.script?.onStart !== 'function')
|
|
164
|
-
throw new Error(`Module ${identifier} does not have a valid 'onStart' method`);
|
|
165
|
-
const versions = (0, discord_js_1.normalizeArray)([mod.script.versions]);
|
|
166
|
-
const commands = this.resolveScriptCommands(mod.script)[0].commands;
|
|
167
|
-
if (!disabeVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
|
|
168
|
-
throw new Error(`Module ${identifier} does not support 'reciple@${version_1.rawVersion}'`);
|
|
169
|
-
return {
|
|
170
|
-
...mod,
|
|
171
|
-
commands,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
async getModuleFiles(...folders) {
|
|
175
|
-
const modules = [];
|
|
176
|
-
for (const dir of ((0, discord_js_1.normalizeArray)(folders).length ? (0, discord_js_1.normalizeArray)(folders) : (0, discord_js_1.normalizeArray)([this.client.config.modulesFolder]))) {
|
|
177
|
-
if (!(0, fs_1.existsSync)(dir))
|
|
178
|
-
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
179
|
-
if (!(0, fs_1.lstatSync)(dir).isDirectory())
|
|
180
|
-
continue;
|
|
181
|
-
modules.push(...(0, fs_1.readdirSync)(dir).map(file => path_1.default.join(flags_1.cwd, dir, file)).filter(file => file.endsWith('.js') || file.endsWith('.cjs')));
|
|
182
|
-
}
|
|
183
|
-
return modules.filter(file => !this.client.config.ignoredFiles.some(ignored => (0, wildcard_match_1.default)(ignored, path_1.default.basename(file))));
|
|
184
|
-
}
|
|
185
|
-
static getModuleDisplayId(mod) {
|
|
186
|
-
return mod.info.path && mod.info.filename ? path_1.default.join(mod.info.path, mod.info.filename) : mod.id;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.ClientModuleManager = ClientModuleManager;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createLogger = void 0;
|
|
7
|
-
const fallout_utility_1 = require("fallout-utility");
|
|
8
|
-
const flags_1 = require("./flags");
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
/**
|
|
11
|
-
* Create new logger
|
|
12
|
-
* @param stringifyJSON stringify json objects in console
|
|
13
|
-
* @param debugmode display debug messages
|
|
14
|
-
* @param colorizeMessage add logger colours to messages
|
|
15
|
-
*/
|
|
16
|
-
function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true) {
|
|
17
|
-
return new fallout_utility_1.Logger({
|
|
18
|
-
stringifyJSON: stringifyJSON,
|
|
19
|
-
enableDebugMode: flags_1.flags.debugmode ?? debugmode,
|
|
20
|
-
loggerName: 'Main',
|
|
21
|
-
prefixes: {
|
|
22
|
-
[fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString(undefined, { hour12: false })}][${(name ? name + "/" : '') + "INFO"}]`,
|
|
23
|
-
[fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.yellow(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.yellow((name ? name + "/" : '') + "WARN")}]`,
|
|
24
|
-
[fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.red(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.red((name ? name + "/" : '') + "ERROR")}]`,
|
|
25
|
-
[fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.blue(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.blue((name ? name + "/" : '') + "DEBUG")}]`
|
|
26
|
-
},
|
|
27
|
-
colorMessages: {
|
|
28
|
-
[fallout_utility_1.LogLevels.INFO]: (message) => message,
|
|
29
|
-
[fallout_utility_1.LogLevels.WARN]: (message) => !colorizeMessage ? message : chalk_1.default.yellow(message),
|
|
30
|
-
[fallout_utility_1.LogLevels.ERROR]: (message) => !colorizeMessage ? message : chalk_1.default.red(message),
|
|
31
|
-
[fallout_utility_1.LogLevels.DEBUG]: (message) => !colorizeMessage ? message : chalk_1.default.blue(message)
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
exports.createLogger = createLogger;
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getModules = void 0;
|
|
30
|
-
const builders_1 = require("./types/builders");
|
|
31
|
-
const MessageCommandBuilder_1 = require("./classes/builders/MessageCommandBuilder");
|
|
32
|
-
const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
|
|
33
|
-
const discord_js_1 = require("discord.js");
|
|
34
|
-
const version_1 = require("./version");
|
|
35
|
-
const fs_1 = require("fs");
|
|
36
|
-
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
37
|
-
const flags_1 = require("./flags");
|
|
38
|
-
const path_1 = __importDefault(require("path"));
|
|
39
|
-
/**
|
|
40
|
-
* Load modules from folder
|
|
41
|
-
* @param client Reciple client
|
|
42
|
-
* @param folder Modules folder
|
|
43
|
-
*/
|
|
44
|
-
async function getModules(client, folder) {
|
|
45
|
-
const response = { commands: [], modules: [] };
|
|
46
|
-
const modulesDir = folder || path_1.default.join(flags_1.cwd, 'modules');
|
|
47
|
-
if (!(0, fs_1.existsSync)(modulesDir))
|
|
48
|
-
(0, fs_1.mkdirSync)(modulesDir, { recursive: true });
|
|
49
|
-
const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
|
|
50
|
-
const scripts = (0, fs_1.readdirSync)(modulesDir).filter(file => {
|
|
51
|
-
return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
|
|
52
|
-
});
|
|
53
|
-
for (const script of scripts) {
|
|
54
|
-
const modulePath = path_1.default.join(modulesDir, script);
|
|
55
|
-
const commands = [];
|
|
56
|
-
let module_;
|
|
57
|
-
try {
|
|
58
|
-
const reqMod = await Promise.resolve().then(() => __importStar(require(modulePath)));
|
|
59
|
-
module_ = reqMod?.default !== undefined ? reqMod.default : reqMod;
|
|
60
|
-
if (typeof module_ !== 'object')
|
|
61
|
-
throw new Error(`Module ${modulePath} is not an object`);
|
|
62
|
-
if (!client.config.disableVersionCheck && !module_?.versions?.length)
|
|
63
|
-
throw new Error(`${modulePath} does not have supported versions.`);
|
|
64
|
-
const versions = (0, discord_js_1.normalizeArray)([module_.versions]);
|
|
65
|
-
if (!client.config.disableVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
|
|
66
|
-
throw new Error(`${modulePath} is unsupported; current version: ${version_1.version}; module supported versions: ` + versions.join(', ') ?? 'none');
|
|
67
|
-
if (!await Promise.resolve(module_.onStart(client)).catch(() => false))
|
|
68
|
-
throw new Error(script + ' onStart returned false or undefined.');
|
|
69
|
-
if (module_.commands) {
|
|
70
|
-
for (const command of module_.commands) {
|
|
71
|
-
if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
72
|
-
commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
73
|
-
}
|
|
74
|
-
else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
75
|
-
commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
if (client.isClientLogsEnabled()) {
|
|
82
|
-
client.logger.error(`Failed to load module ${script}`);
|
|
83
|
-
client.logger.error(error);
|
|
84
|
-
}
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
response.commands.push(...commands.filter((c) => {
|
|
88
|
-
if (!c.name) {
|
|
89
|
-
if (client.isClientLogsEnabled())
|
|
90
|
-
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${modulePath}`);
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
|
|
94
|
-
if (client.isClientLogsEnabled())
|
|
95
|
-
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${modulePath}`);
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
}));
|
|
100
|
-
response.modules.push({
|
|
101
|
-
script: module_,
|
|
102
|
-
info: {
|
|
103
|
-
filename: script,
|
|
104
|
-
versions: (0, discord_js_1.normalizeArray)([module_.versions]),
|
|
105
|
-
path: modulePath
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
if (client.isClientLogsEnabled())
|
|
109
|
-
client.logger.info(`Loaded module ${modulePath}`);
|
|
110
|
-
}
|
|
111
|
-
return response;
|
|
112
|
-
}
|
|
113
|
-
exports.getModules = getModules;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandBuilderType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Types of command builders
|
|
6
|
-
*/
|
|
7
|
-
var CommandBuilderType;
|
|
8
|
-
(function (CommandBuilderType) {
|
|
9
|
-
CommandBuilderType[CommandBuilderType["MessageCommand"] = 0] = "MessageCommand";
|
|
10
|
-
CommandBuilderType[CommandBuilderType["SlashCommand"] = 1] = "SlashCommand";
|
|
11
|
-
})(CommandBuilderType = exports.CommandBuilderType || (exports.CommandBuilderType = {}));
|
package/dist/cjs/reciple/util.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateCommandBuilder = exports.deprecationWarning = exports.isClass = void 0;
|
|
4
|
-
const builders_1 = require("./types/builders");
|
|
5
|
-
/**
|
|
6
|
-
* Check if an object is a class
|
|
7
|
-
* @param object Object to identify
|
|
8
|
-
*/
|
|
9
|
-
function isClass(object) {
|
|
10
|
-
const isClassConstructor = object.constructor && object.constructor.toString().substring(0, 5) === 'class';
|
|
11
|
-
if (object.prototype === undefined)
|
|
12
|
-
return isClassConstructor;
|
|
13
|
-
const isPrototypeClassConstructor = object.prototype.constructor && object.prototype.constructor.toString && object.prototype.constructor.toString().substring(0, 5) === 'class';
|
|
14
|
-
return isClassConstructor || isPrototypeClassConstructor;
|
|
15
|
-
}
|
|
16
|
-
exports.isClass = isClass;
|
|
17
|
-
/**
|
|
18
|
-
* Emit process warning about deprecated method/function
|
|
19
|
-
* @param content Warning content
|
|
20
|
-
*/
|
|
21
|
-
function deprecationWarning(content) {
|
|
22
|
-
process.emitWarning(content, 'DeprecationWarning');
|
|
23
|
-
}
|
|
24
|
-
exports.deprecationWarning = deprecationWarning;
|
|
25
|
-
function validateCommandBuilder(command) {
|
|
26
|
-
if (!command.name)
|
|
27
|
-
return false;
|
|
28
|
-
if (command.type === builders_1.CommandBuilderType.MessageCommand && command.options.length && command.options.some(o => !o.name))
|
|
29
|
-
return false;
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
exports.validateCommandBuilder = validateCommandBuilder;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'fallout-utility';
|
|
2
|
-
/**
|
|
3
|
-
* Create new logger
|
|
4
|
-
* @param stringifyJSON stringify json objects in console
|
|
5
|
-
* @param debugmode display debug messages
|
|
6
|
-
* @param colorizeMessage add logger colours to messages
|
|
7
|
-
*/
|
|
8
|
-
export declare function createLogger(stringifyJSON: boolean, debugmode?: boolean, colorizeMessage?: boolean): Logger;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { AnyCommandBuilder, AnyCommandData } from './types/builders';
|
|
2
|
-
import { RecipleClient } from './classes/RecipleClient';
|
|
3
|
-
/**
|
|
4
|
-
* Loaded modules and commands
|
|
5
|
-
*/
|
|
6
|
-
export interface LoadedModules {
|
|
7
|
-
commands: AnyCommandBuilder[];
|
|
8
|
-
modules: RecipleModule[];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Reciple script object
|
|
12
|
-
*/
|
|
13
|
-
export interface RecipleScript {
|
|
14
|
-
/**
|
|
15
|
-
* Supported reciple versions
|
|
16
|
-
*/
|
|
17
|
-
versions: string | string[];
|
|
18
|
-
/**
|
|
19
|
-
* Module commands
|
|
20
|
-
*/
|
|
21
|
-
commands?: (AnyCommandBuilder | AnyCommandData)[];
|
|
22
|
-
/**
|
|
23
|
-
* Action on bot ready
|
|
24
|
-
* @param client Bot client
|
|
25
|
-
*/
|
|
26
|
-
onLoad?(client: RecipleClient<true>): void | Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Action on module start
|
|
29
|
-
* @param client Bot client
|
|
30
|
-
*/
|
|
31
|
-
onStart(client: RecipleClient<false>): boolean | Promise<boolean>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Reciple module object
|
|
35
|
-
*/
|
|
36
|
-
export interface RecipleModule {
|
|
37
|
-
/**
|
|
38
|
-
* Module script
|
|
39
|
-
*/
|
|
40
|
-
script: RecipleScript;
|
|
41
|
-
/**
|
|
42
|
-
* Module local information
|
|
43
|
-
*/
|
|
44
|
-
info: {
|
|
45
|
-
/**
|
|
46
|
-
* Module file name
|
|
47
|
-
*/
|
|
48
|
-
filename?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Supported reciple versions
|
|
51
|
-
*/
|
|
52
|
-
versions: string[];
|
|
53
|
-
/**
|
|
54
|
-
* Module local file path
|
|
55
|
-
*/
|
|
56
|
-
path?: string;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Load modules from folder
|
|
61
|
-
* @param client Reciple client
|
|
62
|
-
* @param folder Modules folder
|
|
63
|
-
*/
|
|
64
|
-
export declare function getModules(client: RecipleClient, folder?: string): Promise<LoadedModules>;
|
package/docs/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# [VIEW DOCS](https://reciple.js.org/#/docs)
|