reciple 5.5.6 → 6.0.0-dev.1
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/cjs/bin.js +6 -7
- package/dist/cjs/index.js +6 -5
- package/dist/cjs/reciple/classes/RecipleClient.js +21 -144
- package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +13 -2
- package/dist/cjs/reciple/classes/builders/MessageCommandOptionBuilder.js +14 -0
- package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +9 -0
- package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +137 -0
- package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +62 -0
- package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +189 -0
- package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js} +8 -5
- package/dist/cjs/reciple/classes/{MessageCommandOptionManager.js → managers/MessageCommandOptionManager.js} +0 -0
- package/dist/cjs/reciple/permissions.js +0 -3
- package/dist/cjs/reciple/util.js +22 -1
- package/dist/cjs/reciple/version.js +1 -0
- package/dist/types/index.d.ts +6 -5
- package/dist/types/reciple/classes/RecipleClient.d.ts +21 -54
- package/dist/types/reciple/classes/RecipleConfig.d.ts +6 -0
- package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +53 -15
- package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +10 -0
- package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +29 -14
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +20 -0
- package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -0
- package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +79 -0
- package/dist/types/reciple/classes/{CommandCooldownManager.d.ts → managers/CommandCooldownManager.d.ts} +21 -2
- package/dist/types/reciple/classes/{MessageCommandOptionManager.d.ts → managers/MessageCommandOptionManager.d.ts} +1 -1
- package/dist/types/reciple/modules.d.ts +36 -4
- package/dist/types/reciple/permissions.d.ts +4 -2
- package/dist/types/reciple/types/builders.d.ts +16 -16
- package/dist/types/reciple/types/commands.d.ts +32 -13
- package/dist/types/reciple/types/paramOptions.d.ts +17 -16
- package/dist/types/reciple/util.d.ts +12 -1
- package/package.json +14 -10
- package/dist/cjs/reciple/registerApplicationCommands.js +0 -50
- package/dist/types/reciple/registerApplicationCommands.d.ts +0 -9
|
@@ -0,0 +1,189 @@
|
|
|
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;
|
package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js}
RENAMED
|
@@ -20,21 +20,24 @@ class CommandCooldownManager extends Array {
|
|
|
20
20
|
* Remove cooldown from specific user, channel or guild
|
|
21
21
|
* @param options Remove cooldown data options
|
|
22
22
|
* @param limit Remove cooldown data limit
|
|
23
|
+
* @returns Returns the removed values
|
|
23
24
|
*/
|
|
24
25
|
remove(options, limit = 0) {
|
|
25
26
|
if (!Object.keys(options).length)
|
|
26
27
|
throw new TypeError('Provide atleast one option to remove cooldown data.');
|
|
28
|
+
const removed = [];
|
|
27
29
|
let i = 0;
|
|
28
|
-
for (
|
|
29
|
-
if (!CommandCooldownManager.checkOptions(options, this[
|
|
30
|
+
for (let i = 0; i < this.length; i++) {
|
|
31
|
+
if (!CommandCooldownManager.checkOptions(options, this[i]))
|
|
30
32
|
continue;
|
|
31
|
-
if (options.expireTime && this[
|
|
33
|
+
if (options.expireTime && this[i].expireTime > Date.now())
|
|
32
34
|
continue;
|
|
33
35
|
if (limit && i >= limit)
|
|
34
36
|
continue;
|
|
35
|
-
|
|
36
|
-
i
|
|
37
|
+
removed.push(this[i]);
|
|
38
|
+
this.splice(Number(i));
|
|
37
39
|
}
|
|
40
|
+
return removed;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
43
|
* Check if the given user is cooled-down
|
|
File without changes
|
|
@@ -16,9 +16,6 @@ function userHasCommandPermissions(options) {
|
|
|
16
16
|
return options.memberPermissions ? options.memberPermissions.has(command.permissions) : false;
|
|
17
17
|
}
|
|
18
18
|
exports.userHasCommandPermissions = userHasCommandPermissions;
|
|
19
|
-
/**
|
|
20
|
-
* @param guildOrChannel Check permission in a guild or channel
|
|
21
|
-
*/
|
|
22
19
|
function botHasExecutePermissions(guildOrChannel, requiredPermissions) {
|
|
23
20
|
if (!requiredPermissions?.length)
|
|
24
21
|
return true;
|
package/dist/cjs/reciple/util.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isClass = void 0;
|
|
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
|
+
*/
|
|
4
9
|
function isClass(object) {
|
|
5
10
|
const isClassConstructor = object.constructor && object.constructor.toString().substring(0, 5) === 'class';
|
|
6
11
|
if (object.prototype === undefined)
|
|
@@ -9,3 +14,19 @@ function isClass(object) {
|
|
|
9
14
|
return isClassConstructor || isPrototypeClassConstructor;
|
|
10
15
|
}
|
|
11
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;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isSupportedVersion = exports.parseVersion = exports.isValidVersion = exports.rawVersion = exports.version = void 0;
|
|
7
7
|
const semver_1 = __importDefault(require("semver"));
|
|
8
|
+
// TODO: ESM support
|
|
8
9
|
/**
|
|
9
10
|
* Current reciple version
|
|
10
11
|
*/
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
export * from './reciple/classes/CommandCooldownManager';
|
|
2
|
-
export * from './reciple/classes/MessageCommandOptionManager';
|
|
3
|
-
export * from './reciple/classes/RecipleClient';
|
|
4
|
-
export * from './reciple/classes/RecipleConfig';
|
|
5
1
|
export * from './reciple/classes/builders/MessageCommandBuilder';
|
|
6
2
|
export * from './reciple/classes/builders/MessageCommandOptionBuilder';
|
|
7
3
|
export * from './reciple/classes/builders/SlashCommandBuilder';
|
|
4
|
+
export * from './reciple/classes/managers/ApplicationCommandManager';
|
|
5
|
+
export * from './reciple/classes/managers/CommandCooldownManager';
|
|
6
|
+
export * from './reciple/classes/managers/ClientCommandManager';
|
|
7
|
+
export * from './reciple/classes/managers/MessageCommandOptionManager';
|
|
8
|
+
export * from './reciple/classes/RecipleClient';
|
|
9
|
+
export * from './reciple/classes/RecipleConfig';
|
|
8
10
|
export * from './reciple/types/builders';
|
|
9
11
|
export * from './reciple/types/commands';
|
|
10
12
|
export * from './reciple/types/paramOptions';
|
|
@@ -12,6 +14,5 @@ export * from './reciple/flags';
|
|
|
12
14
|
export * from './reciple/logger';
|
|
13
15
|
export * from './reciple/modules';
|
|
14
16
|
export * from './reciple/permissions';
|
|
15
|
-
export * from './reciple/registerApplicationCommands';
|
|
16
17
|
export * from './reciple/util';
|
|
17
18
|
export * from './reciple/version';
|
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData } from './builders/MessageCommandBuilder';
|
|
2
2
|
import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData } from './builders/SlashCommandBuilder';
|
|
3
|
-
import { AnyCommandBuilder, AnyCommandData, AnySlashCommandBuilder, CommandBuilderType } from '../types/builders';
|
|
4
|
-
import { ApplicationCommandBuilder } from '../registerApplicationCommands';
|
|
5
3
|
import { AnyCommandExecuteData, AnyCommandHaltData } from '../types/commands';
|
|
6
|
-
import { CommandCooldownManager } from './CommandCooldownManager';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { CommandCooldownManager } from './managers/CommandCooldownManager';
|
|
5
|
+
import { ApplicationCommandManager } from './managers/ApplicationCommandManager';
|
|
6
|
+
import { ClientCommandManager } from './managers/ClientCommandManager';
|
|
9
7
|
import { Config } from './RecipleConfig';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { Logger } from 'fallout-utility';
|
|
9
|
+
import { Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
|
|
10
|
+
import { ClientModuleManager } from './managers/ClientModuleManager';
|
|
12
11
|
/**
|
|
13
|
-
* Options for
|
|
12
|
+
* Options for {@link RecipleClient}
|
|
14
13
|
*/
|
|
15
14
|
export interface RecipleClientOptions extends ClientOptions {
|
|
16
15
|
config?: Config;
|
|
17
16
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Reciple client commands
|
|
20
|
-
*/
|
|
21
|
-
export interface RecipleClientCommands {
|
|
22
|
-
slashCommands: Collection<string, AnySlashCommandBuilder>;
|
|
23
|
-
messageCommands: Collection<string, MessageCommandBuilder>;
|
|
24
|
-
}
|
|
25
17
|
/**
|
|
26
18
|
* Reciple client events
|
|
27
19
|
*/
|
|
28
20
|
export interface RecipleClientEvents extends ClientEvents {
|
|
29
21
|
recipleCommandExecute: [executeData: AnyCommandExecuteData];
|
|
30
22
|
recipleCommandHalt: [haltData: AnyCommandHaltData];
|
|
23
|
+
recipleRegisterApplicationCommands: [];
|
|
31
24
|
recipleReplyError: [error: unknown];
|
|
32
25
|
}
|
|
33
26
|
/**
|
|
@@ -47,36 +40,17 @@ export interface RecipleClient<Ready extends boolean = boolean> extends Client<R
|
|
|
47
40
|
isReady(): this is RecipleClient<true>;
|
|
48
41
|
}
|
|
49
42
|
export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
50
|
-
config: Config;
|
|
51
|
-
commands:
|
|
52
|
-
|
|
53
|
-
cooldowns: CommandCooldownManager;
|
|
54
|
-
modules:
|
|
55
|
-
logger:
|
|
56
|
-
version: string;
|
|
43
|
+
readonly config: Config;
|
|
44
|
+
readonly commands: ClientCommandManager;
|
|
45
|
+
readonly applicationCommands: ApplicationCommandManager;
|
|
46
|
+
readonly cooldowns: CommandCooldownManager;
|
|
47
|
+
readonly modules: ClientModuleManager;
|
|
48
|
+
readonly logger: Logger;
|
|
49
|
+
readonly version: string;
|
|
57
50
|
/**
|
|
58
51
|
* @param options Client options
|
|
59
52
|
*/
|
|
60
53
|
constructor(options: RecipleClientOptions);
|
|
61
|
-
/**
|
|
62
|
-
* Load modules from modules folder
|
|
63
|
-
* @param folders List of folders that contains the modules you want to load
|
|
64
|
-
*/
|
|
65
|
-
startModules(...folders: RestOrArray<string>): Promise<RecipleClient<Ready>>;
|
|
66
|
-
/**
|
|
67
|
-
* Execute `onLoad()` from client modules and register application commands if enabled
|
|
68
|
-
*/
|
|
69
|
-
loadModules(): Promise<RecipleClient<Ready>>;
|
|
70
|
-
/**
|
|
71
|
-
* Add module
|
|
72
|
-
* @param options Module options
|
|
73
|
-
*/
|
|
74
|
-
addModule(options: RecipleClientAddModuleOptions): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* Add slash or message command to client
|
|
77
|
-
* @param command Slash/Message command builder
|
|
78
|
-
*/
|
|
79
|
-
addCommand(command: AnyCommandData | AnyCommandBuilder): RecipleClient<Ready>;
|
|
80
54
|
/**
|
|
81
55
|
* Listed to command executions
|
|
82
56
|
*/
|
|
@@ -85,32 +59,25 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
85
59
|
* Execute a slash command
|
|
86
60
|
* @param interaction Slash command interaction
|
|
87
61
|
*/
|
|
88
|
-
slashCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<
|
|
62
|
+
slashCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<undefined | SlashCommandExecuteData>;
|
|
89
63
|
/**
|
|
90
64
|
* Execute a Message command
|
|
91
65
|
* @param message Message command executor
|
|
92
66
|
* @param prefix Message command prefix
|
|
93
67
|
*/
|
|
94
|
-
messageCommandExecute(message: Message, prefix?: string): Promise<
|
|
68
|
+
messageCommandExecute(message: Message, prefix?: string): Promise<undefined | MessageCommandExecuteData>;
|
|
95
69
|
/**
|
|
96
70
|
* Get a message from config
|
|
97
71
|
* @param messageKey Config messages key
|
|
98
72
|
* @param defaultMessage Default message when the key does not exists
|
|
99
73
|
*/
|
|
100
74
|
getConfigMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
|
|
101
|
-
/**
|
|
102
|
-
* Get command builder by name or alias if it's a message command
|
|
103
|
-
* @param command Command name
|
|
104
|
-
* @param type Command type
|
|
105
|
-
*/
|
|
106
|
-
findCommand(command: string, type: CommandBuilderType.MessageCommand): MessageCommandBuilder | undefined;
|
|
107
|
-
findCommand(command: string, type: CommandBuilderType.SlashCommand): SlashCommandBuilder | undefined;
|
|
108
75
|
/**
|
|
109
76
|
* Returns true if client logs is enabled
|
|
110
77
|
*/
|
|
111
78
|
isClientLogsEnabled(): boolean;
|
|
112
79
|
/**
|
|
113
|
-
* Emits the "recipleReplyError" event
|
|
80
|
+
* Emits the {@link RecipleClientEvents["recipleReplyError"]} event
|
|
114
81
|
* @param error Received Error
|
|
115
82
|
*/
|
|
116
83
|
protected _replyError(error: unknown): void;
|
|
@@ -122,12 +89,12 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
122
89
|
protected _haltCommand(command: SlashCommandBuilder, haltData: SlashCommandHaltData): Promise<boolean>;
|
|
123
90
|
protected _haltCommand(command: MessageCommandBuilder, haltData: MessageCommandHaltData): Promise<boolean>;
|
|
124
91
|
/**
|
|
125
|
-
* Executes a command
|
|
92
|
+
* Executes a command's {@link SharedCommandBuilderProperties["execute"]} method
|
|
126
93
|
* @param command Command builder
|
|
127
94
|
* @param executeData Command execute data
|
|
128
95
|
*/
|
|
129
|
-
protected _executeCommand(command: SlashCommandBuilder, executeData: SlashCommandExecuteData): Promise<SlashCommandExecuteData |
|
|
130
|
-
protected _executeCommand(command: MessageCommandBuilder, executeData: MessageCommandExecuteData): Promise<MessageCommandExecuteData |
|
|
96
|
+
protected _executeCommand(command: SlashCommandBuilder, executeData: SlashCommandExecuteData): Promise<SlashCommandExecuteData | undefined>;
|
|
97
|
+
protected _executeCommand(command: MessageCommandBuilder, executeData: MessageCommandExecuteData): Promise<MessageCommandExecuteData | undefined>;
|
|
131
98
|
/**
|
|
132
99
|
* Error message when a command fails to execute
|
|
133
100
|
* @param err Received error
|
|
@@ -3,7 +3,13 @@ import { ClientOptions, PermissionResolvable } from 'discord.js';
|
|
|
3
3
|
* Command permissions config object interface
|
|
4
4
|
*/
|
|
5
5
|
export interface ConfigCommandPermissions {
|
|
6
|
+
/**
|
|
7
|
+
* Command name
|
|
8
|
+
*/
|
|
6
9
|
command: string;
|
|
10
|
+
/**
|
|
11
|
+
* Override command builder permissions
|
|
12
|
+
*/
|
|
7
13
|
permissions: PermissionResolvable[];
|
|
8
14
|
}
|
|
9
15
|
/**
|
|
@@ -1,44 +1,71 @@
|
|
|
1
1
|
import { CommandBuilderType, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties, MessageCommandData } from '../../types/builders';
|
|
2
2
|
import { Message, PermissionResolvable, RestOrArray } from 'discord.js';
|
|
3
3
|
import { BaseCommandExecuteData, CommandHaltData } from '../../types/commands';
|
|
4
|
-
import { MessageCommandOptionManager } from '../MessageCommandOptionManager';
|
|
4
|
+
import { MessageCommandOptionManager } from '../managers/MessageCommandOptionManager';
|
|
5
5
|
import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
|
|
6
|
-
import { Command
|
|
6
|
+
import { Command } from 'fallout-utility';
|
|
7
7
|
/**
|
|
8
8
|
* Execute data for message command
|
|
9
9
|
*/
|
|
10
|
-
export interface MessageCommandExecuteData<T
|
|
10
|
+
export interface MessageCommandExecuteData<T = unknown> extends BaseCommandExecuteData {
|
|
11
|
+
/**
|
|
12
|
+
* Command message
|
|
13
|
+
*/
|
|
11
14
|
message: Message;
|
|
15
|
+
/**
|
|
16
|
+
* Command option args
|
|
17
|
+
*/
|
|
12
18
|
options: MessageCommandOptionManager;
|
|
13
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Command parsed args
|
|
21
|
+
*/
|
|
22
|
+
command: Command;
|
|
23
|
+
/**
|
|
24
|
+
* Command builder
|
|
25
|
+
*/
|
|
14
26
|
builder: MessageCommandBuilder<T>;
|
|
15
27
|
}
|
|
16
28
|
/**
|
|
17
29
|
* Validated message command option
|
|
18
30
|
*/
|
|
19
31
|
export interface MessageCommandValidatedOption {
|
|
32
|
+
/**
|
|
33
|
+
* Option name
|
|
34
|
+
*/
|
|
20
35
|
name: string;
|
|
21
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Option value
|
|
38
|
+
*/
|
|
39
|
+
value?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Is the option required
|
|
42
|
+
*/
|
|
22
43
|
required: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Is the option invalid
|
|
46
|
+
*/
|
|
23
47
|
invalid: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Is the option missing
|
|
50
|
+
*/
|
|
24
51
|
missing: boolean;
|
|
25
52
|
}
|
|
26
53
|
/**
|
|
27
54
|
* Halt data for message command
|
|
28
55
|
*/
|
|
29
|
-
export declare type MessageCommandHaltData = CommandHaltData<CommandBuilderType.MessageCommand>;
|
|
56
|
+
export declare type MessageCommandHaltData<T = unknown> = CommandHaltData<CommandBuilderType.MessageCommand, T>;
|
|
30
57
|
/**
|
|
31
58
|
* Message command halt function
|
|
32
59
|
*/
|
|
33
|
-
export declare type MessageCommandHaltFunction = CommandHaltFunction<CommandBuilderType.MessageCommand>;
|
|
60
|
+
export declare type MessageCommandHaltFunction<T = unknown> = CommandHaltFunction<CommandBuilderType.MessageCommand, T>;
|
|
34
61
|
/**
|
|
35
62
|
* Message command execute function
|
|
36
63
|
*/
|
|
37
|
-
export declare type MessageCommandExecuteFunction = CommandExecuteFunction<CommandBuilderType.MessageCommand>;
|
|
64
|
+
export declare type MessageCommandExecuteFunction<T = unknown> = CommandExecuteFunction<CommandBuilderType.MessageCommand, T>;
|
|
38
65
|
/**
|
|
39
66
|
* Reciple builder for message command
|
|
40
67
|
*/
|
|
41
|
-
export declare class MessageCommandBuilder<T
|
|
68
|
+
export declare class MessageCommandBuilder<T = unknown> implements SharedCommandBuilderProperties<T> {
|
|
42
69
|
readonly type = CommandBuilderType.MessageCommand;
|
|
43
70
|
name: string;
|
|
44
71
|
description: string;
|
|
@@ -50,8 +77,8 @@ export declare class MessageCommandBuilder<T extends unknown = any> implements S
|
|
|
50
77
|
requiredMemberPermissions: PermissionResolvable[];
|
|
51
78
|
allowExecuteInDM: boolean;
|
|
52
79
|
allowExecuteByBots: boolean;
|
|
53
|
-
halt?: MessageCommandHaltFunction
|
|
54
|
-
execute: MessageCommandExecuteFunction
|
|
80
|
+
halt?: MessageCommandHaltFunction<T>;
|
|
81
|
+
execute: MessageCommandExecuteFunction<T>;
|
|
55
82
|
metadata?: T;
|
|
56
83
|
constructor(data?: Partial<Omit<MessageCommandData<T>, "type">>);
|
|
57
84
|
/**
|
|
@@ -92,21 +119,32 @@ export declare class MessageCommandBuilder<T extends unknown = any> implements S
|
|
|
92
119
|
setCooldown(cooldown: number): this;
|
|
93
120
|
setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
94
121
|
setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
95
|
-
setHalt(halt?: MessageCommandHaltFunction | null): this;
|
|
96
|
-
setExecute(execute: MessageCommandExecuteFunction): this;
|
|
122
|
+
setHalt(halt?: MessageCommandHaltFunction<T> | null): this;
|
|
123
|
+
setExecute(execute: MessageCommandExecuteFunction<T>): this;
|
|
97
124
|
setMetadata(metadata?: T): this;
|
|
98
125
|
/**
|
|
99
126
|
* Returns JSON object of this builder
|
|
100
127
|
*/
|
|
101
128
|
toJSON(): MessageCommandData<T>;
|
|
102
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Resolve message command data/builder
|
|
131
|
+
* @param commandData Command data to resolve
|
|
132
|
+
*/
|
|
133
|
+
static resolveMessageCommand<T = unknown>(commandData: MessageCommandData<T> | MessageCommandBuilder<T>): MessageCommandBuilder<T>;
|
|
103
134
|
/**
|
|
104
135
|
* Is a message command builder
|
|
136
|
+
* @param builder data to check
|
|
105
137
|
*/
|
|
106
138
|
static isMessageCommandBuilder<T>(builder: unknown): builder is MessageCommandBuilder<T>;
|
|
107
139
|
/**
|
|
108
140
|
* Is a message command execute data
|
|
141
|
+
* @param executeData data to check
|
|
109
142
|
*/
|
|
110
143
|
static isMessageCommandExecuteData(executeData: unknown): executeData is MessageCommandExecuteData;
|
|
111
144
|
}
|
|
112
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Validate message command options
|
|
147
|
+
* @param builder Command builder
|
|
148
|
+
* @param options Parsed command args
|
|
149
|
+
*/
|
|
150
|
+
export declare function validateMessageCommandOptions(builder: MessageCommandBuilder, options: Command): Promise<MessageCommandOptionManager>;
|
|
@@ -30,4 +30,14 @@ export declare class MessageCommandOptionBuilder {
|
|
|
30
30
|
*/
|
|
31
31
|
setValidator(validator: (value: string) => Awaitable<boolean>): this;
|
|
32
32
|
toJSON(): MessageCommandOptionData;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves message command option data/builder
|
|
35
|
+
* @param option Option data to resolve
|
|
36
|
+
*/
|
|
37
|
+
static resolveMessageCommandOption(option: MessageCommandOptionBuilder | MessageCommandOptionBuilder): MessageCommandOptionBuilder;
|
|
38
|
+
/**
|
|
39
|
+
* Is a Message command option builder
|
|
40
|
+
* @param builder data to check
|
|
41
|
+
*/
|
|
42
|
+
static isMessageCommandOption(builder: unknown): builder is MessageCommandOptionBuilder;
|
|
33
43
|
}
|