reciple 6.0.0-dev.18 → 6.0.0-dev.19
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/LICENSE +674 -674
- package/README.md +183 -183
- package/dist/lib/bin.mjs +65 -66
- package/dist/lib/esm.mjs +1 -1
- package/dist/lib/index.js +35 -35
- package/dist/lib/reciple/classes/RecipleClient.js +296 -300
- package/dist/lib/reciple/classes/RecipleConfig.js +106 -106
- package/dist/lib/reciple/classes/RecipleModule.js +94 -94
- package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js +242 -242
- package/dist/lib/reciple/classes/builders/MessageCommandOptionBuilder.js +85 -85
- package/dist/lib/reciple/classes/builders/SlashCommandBuilder.js +216 -216
- package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js +172 -172
- package/dist/lib/reciple/classes/managers/ClientCommandManager.js +62 -62
- package/dist/lib/reciple/classes/managers/ClientModuleManager.js +183 -183
- package/dist/lib/reciple/classes/managers/CommandCooldownManager.js +100 -100
- package/dist/lib/reciple/classes/managers/MessageCommandOptionManager.js +25 -25
- package/dist/lib/reciple/flags.js +31 -31
- package/dist/lib/reciple/permissions.js +30 -30
- package/dist/lib/reciple/types/builders.js +11 -11
- package/dist/lib/reciple/types/commands.js +15 -15
- package/dist/lib/reciple/types/paramOptions.js +2 -2
- package/dist/lib/reciple/util.js +68 -66
- package/dist/lib/reciple/version.js +47 -47
- package/dist/types/bin.d.mts +2 -2
- package/dist/types/esm.d.mts +1 -1
- package/dist/types/index.d.ts +19 -19
- package/dist/types/reciple/classes/RecipleClient.d.ts +103 -103
- package/dist/types/reciple/classes/RecipleConfig.d.ts +100 -100
- package/dist/types/reciple/classes/RecipleModule.d.ts +56 -56
- package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +150 -150
- package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +43 -43
- package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +88 -88
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +51 -51
- package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -37
- package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +49 -49
- package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +70 -70
- package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts +22 -22
- package/dist/types/reciple/flags.d.ts +17 -17
- package/dist/types/reciple/permissions.d.ts +19 -19
- package/dist/types/reciple/types/builders.d.ts +197 -197
- package/dist/types/reciple/types/commands.d.ts +81 -81
- package/dist/types/reciple/types/paramOptions.d.ts +101 -101
- package/dist/types/reciple/util.d.ts +23 -20
- package/dist/types/reciple/version.d.ts +25 -25
- package/package.json +1 -1
- package/resource/reciple.yml +120 -120
|
@@ -1,183 +1,183 @@
|
|
|
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.ClientModuleManager = void 0;
|
|
7
|
-
const discord_js_1 = require("discord.js");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
class ClientModuleManager {
|
|
14
|
-
constructor(options) {
|
|
15
|
-
this.modules = new discord_js_1.Collection();
|
|
16
|
-
this.client = options.client;
|
|
17
|
-
options.modules?.forEach(m => (m instanceof RecipleModule_1.RecipleModule ? m : new RecipleModule_1.RecipleModule({ client: this.client, script: m })));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Start modules
|
|
21
|
-
* @param options start modules options
|
|
22
|
-
* @returns started modules
|
|
23
|
-
*/
|
|
24
|
-
async startModules(options) {
|
|
25
|
-
const startedModules = [];
|
|
26
|
-
for (const module_ of options.modules) {
|
|
27
|
-
if (!this.client.isClientLogsSilent)
|
|
28
|
-
this.client.logger.log(`Starting module '${module_}'`);
|
|
29
|
-
try {
|
|
30
|
-
let error;
|
|
31
|
-
const start = await module_.start().catch(err => {
|
|
32
|
-
error = err;
|
|
33
|
-
return false;
|
|
34
|
-
});
|
|
35
|
-
if (error)
|
|
36
|
-
throw new Error(`An error occured while loading module '${module_}': \n${(0, util_1.inspect)(error)}`);
|
|
37
|
-
if (!start) {
|
|
38
|
-
if (!this.client.isClientLogsSilent)
|
|
39
|
-
this.client.logger.error(`Module '${module_}' returned false onStart`);
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (options.addToModulesCollection !== false)
|
|
43
|
-
this.modules.set(module_.id, module_);
|
|
44
|
-
startedModules.push(module_);
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
if (options?.ignoreErrors === false)
|
|
48
|
-
throw err;
|
|
49
|
-
if (!this.client.isClientLogsSilent)
|
|
50
|
-
this.client.logger.error(`Failed to start module '${module_}': `, err);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return startedModules;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Load modules
|
|
57
|
-
* @param options load modules options
|
|
58
|
-
* @returns loaded modules
|
|
59
|
-
*/
|
|
60
|
-
async loadModules(options) {
|
|
61
|
-
const loadedModules = [];
|
|
62
|
-
for (const module_ of options?.modules ?? this.modules.toJSON()) {
|
|
63
|
-
try {
|
|
64
|
-
await module_.load().catch(err => {
|
|
65
|
-
throw err;
|
|
66
|
-
});
|
|
67
|
-
if (options?.resolveCommands !== false) {
|
|
68
|
-
module_.resolveCommands();
|
|
69
|
-
this.client.commands.add(module_.commands);
|
|
70
|
-
}
|
|
71
|
-
loadedModules.push(module_);
|
|
72
|
-
if (!this.client.isClientLogsSilent)
|
|
73
|
-
this.client.logger.log(`Loaded module '${module_}'`);
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
if (options?.ignoreErrors === false)
|
|
77
|
-
throw err;
|
|
78
|
-
if (!this.client.isClientLogsSilent)
|
|
79
|
-
this.client.logger.error(`Failed to load module '${module_}': `, err);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return loadedModules;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Unload modules
|
|
86
|
-
* @param options unload modules options
|
|
87
|
-
* @returns unloaded modules
|
|
88
|
-
*/
|
|
89
|
-
async unloadModules(options) {
|
|
90
|
-
const unloadedModules = [];
|
|
91
|
-
for (const module_ of options?.modules ?? this.modules.toJSON()) {
|
|
92
|
-
try {
|
|
93
|
-
await module_.unload().catch(err => {
|
|
94
|
-
throw err;
|
|
95
|
-
});
|
|
96
|
-
unloadedModules.push(module_);
|
|
97
|
-
if (!this.client.isClientLogsSilent)
|
|
98
|
-
this.client.logger.log(`Unloaded module '${module_}'`);
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
if (options?.ignoreErrors === false)
|
|
102
|
-
throw err;
|
|
103
|
-
if (!this.client.isClientLogsSilent)
|
|
104
|
-
this.client.logger.error(`Failed to unLoad module '${module_}': `, err);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return unloadedModules;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Resolve modules from file paths
|
|
111
|
-
* @param options resolve module files options
|
|
112
|
-
* @returns resolved modules
|
|
113
|
-
*/
|
|
114
|
-
async resolveModuleFiles(options) {
|
|
115
|
-
const modules = [];
|
|
116
|
-
for (const file of options.files) {
|
|
117
|
-
try {
|
|
118
|
-
const resolveFile = await import(file);
|
|
119
|
-
let script = resolveFile instanceof RecipleModule_1.RecipleModule || ClientModuleManager.validateScript(resolveFile)
|
|
120
|
-
? resolveFile
|
|
121
|
-
: resolveFile?.default?.default instanceof RecipleModule_1.RecipleModule || ClientModuleManager.validateScript(resolveFile?.default?.default)
|
|
122
|
-
? resolveFile.default.default
|
|
123
|
-
: resolveFile?.default;
|
|
124
|
-
if (script instanceof RecipleModule_1.RecipleModule) {
|
|
125
|
-
modules.push(script);
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (!ClientModuleManager.validateScript(script))
|
|
129
|
-
throw new Error(`Invalid module script: ${file}`);
|
|
130
|
-
modules.push(new RecipleModule_1.RecipleModule({
|
|
131
|
-
client: this.client,
|
|
132
|
-
script,
|
|
133
|
-
filePath: file,
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
catch (err) {
|
|
137
|
-
if (options.ignoreErrors === false)
|
|
138
|
-
throw err;
|
|
139
|
-
if (!this.client.isClientLogsSilent)
|
|
140
|
-
this.client.logger.error(`Can't resolve module from: ${file}`, err);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return modules;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Validate module script
|
|
147
|
-
* @param script module script
|
|
148
|
-
* @returns `true` if script is valid
|
|
149
|
-
*/
|
|
150
|
-
static validateScript(script) {
|
|
151
|
-
const s = script;
|
|
152
|
-
if (typeof s !== 'object')
|
|
153
|
-
return false;
|
|
154
|
-
if (typeof s.versions !== 'string' && !Array.isArray(s.versions))
|
|
155
|
-
return false;
|
|
156
|
-
if (typeof s.onStart !== 'function')
|
|
157
|
-
return false;
|
|
158
|
-
if (s.onLoad && typeof s.onLoad !== 'function')
|
|
159
|
-
return false;
|
|
160
|
-
if (s.onUnload && typeof s.onUnload !== 'function')
|
|
161
|
-
return false;
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Get module file paths from folders
|
|
166
|
-
* @param options get module paths options
|
|
167
|
-
* @returns module paths
|
|
168
|
-
*/
|
|
169
|
-
async getModulePaths(options) {
|
|
170
|
-
const modules = [];
|
|
171
|
-
for (const dir of options?.folders ?? (0, discord_js_1.normalizeArray)([this.client.config.modulesFolder])) {
|
|
172
|
-
if (!(0, fs_1.existsSync)(dir))
|
|
173
|
-
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
174
|
-
if (!(0, fs_1.lstatSync)(dir).isDirectory())
|
|
175
|
-
continue;
|
|
176
|
-
modules.push(...(0, fs_1.readdirSync)(dir)
|
|
177
|
-
.map(file =>
|
|
178
|
-
.filter(file => (options?.filter ? options.filter(file) : file.endsWith('.js'))));
|
|
179
|
-
}
|
|
180
|
-
return modules.filter(file => !(options?.ignoredFiles ?? this.client.config.ignoredFiles).some(ignored => (0, wildcard_match_1.default)(ignored)(
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
exports.ClientModuleManager = ClientModuleManager;
|
|
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.ClientModuleManager = void 0;
|
|
7
|
+
const discord_js_1 = require("discord.js");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const util_1 = require("util");
|
|
10
|
+
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
11
|
+
const RecipleModule_1 = require("../RecipleModule");
|
|
12
|
+
const util_2 = require("../../util");
|
|
13
|
+
class ClientModuleManager {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.modules = new discord_js_1.Collection();
|
|
16
|
+
this.client = options.client;
|
|
17
|
+
options.modules?.forEach(m => (m instanceof RecipleModule_1.RecipleModule ? m : new RecipleModule_1.RecipleModule({ client: this.client, script: m })));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Start modules
|
|
21
|
+
* @param options start modules options
|
|
22
|
+
* @returns started modules
|
|
23
|
+
*/
|
|
24
|
+
async startModules(options) {
|
|
25
|
+
const startedModules = [];
|
|
26
|
+
for (const module_ of options.modules) {
|
|
27
|
+
if (!this.client.isClientLogsSilent)
|
|
28
|
+
this.client.logger.log(`Starting module '${module_}'`);
|
|
29
|
+
try {
|
|
30
|
+
let error;
|
|
31
|
+
const start = await module_.start().catch(err => {
|
|
32
|
+
error = err;
|
|
33
|
+
return false;
|
|
34
|
+
});
|
|
35
|
+
if (error)
|
|
36
|
+
throw new Error(`An error occured while loading module '${module_}': \n${(0, util_1.inspect)(error)}`);
|
|
37
|
+
if (!start) {
|
|
38
|
+
if (!this.client.isClientLogsSilent)
|
|
39
|
+
this.client.logger.error(`Module '${module_}' returned false onStart`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (options.addToModulesCollection !== false)
|
|
43
|
+
this.modules.set(module_.id, module_);
|
|
44
|
+
startedModules.push(module_);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (options?.ignoreErrors === false)
|
|
48
|
+
throw err;
|
|
49
|
+
if (!this.client.isClientLogsSilent)
|
|
50
|
+
this.client.logger.error(`Failed to start module '${module_}': `, err);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return startedModules;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Load modules
|
|
57
|
+
* @param options load modules options
|
|
58
|
+
* @returns loaded modules
|
|
59
|
+
*/
|
|
60
|
+
async loadModules(options) {
|
|
61
|
+
const loadedModules = [];
|
|
62
|
+
for (const module_ of options?.modules ?? this.modules.toJSON()) {
|
|
63
|
+
try {
|
|
64
|
+
await module_.load().catch(err => {
|
|
65
|
+
throw err;
|
|
66
|
+
});
|
|
67
|
+
if (options?.resolveCommands !== false) {
|
|
68
|
+
module_.resolveCommands();
|
|
69
|
+
this.client.commands.add(module_.commands);
|
|
70
|
+
}
|
|
71
|
+
loadedModules.push(module_);
|
|
72
|
+
if (!this.client.isClientLogsSilent)
|
|
73
|
+
this.client.logger.log(`Loaded module '${module_}'`);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (options?.ignoreErrors === false)
|
|
77
|
+
throw err;
|
|
78
|
+
if (!this.client.isClientLogsSilent)
|
|
79
|
+
this.client.logger.error(`Failed to load module '${module_}': `, err);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return loadedModules;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Unload modules
|
|
86
|
+
* @param options unload modules options
|
|
87
|
+
* @returns unloaded modules
|
|
88
|
+
*/
|
|
89
|
+
async unloadModules(options) {
|
|
90
|
+
const unloadedModules = [];
|
|
91
|
+
for (const module_ of options?.modules ?? this.modules.toJSON()) {
|
|
92
|
+
try {
|
|
93
|
+
await module_.unload().catch(err => {
|
|
94
|
+
throw err;
|
|
95
|
+
});
|
|
96
|
+
unloadedModules.push(module_);
|
|
97
|
+
if (!this.client.isClientLogsSilent)
|
|
98
|
+
this.client.logger.log(`Unloaded module '${module_}'`);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (options?.ignoreErrors === false)
|
|
102
|
+
throw err;
|
|
103
|
+
if (!this.client.isClientLogsSilent)
|
|
104
|
+
this.client.logger.error(`Failed to unLoad module '${module_}': `, err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return unloadedModules;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Resolve modules from file paths
|
|
111
|
+
* @param options resolve module files options
|
|
112
|
+
* @returns resolved modules
|
|
113
|
+
*/
|
|
114
|
+
async resolveModuleFiles(options) {
|
|
115
|
+
const modules = [];
|
|
116
|
+
for (const file of options.files) {
|
|
117
|
+
try {
|
|
118
|
+
const resolveFile = await import((util_2.path.isAbsolute(file) ? 'file://' : '') + file);
|
|
119
|
+
let script = resolveFile instanceof RecipleModule_1.RecipleModule || ClientModuleManager.validateScript(resolveFile)
|
|
120
|
+
? resolveFile
|
|
121
|
+
: resolveFile?.default?.default instanceof RecipleModule_1.RecipleModule || ClientModuleManager.validateScript(resolveFile?.default?.default)
|
|
122
|
+
? resolveFile.default.default
|
|
123
|
+
: resolveFile?.default;
|
|
124
|
+
if (script instanceof RecipleModule_1.RecipleModule) {
|
|
125
|
+
modules.push(script);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (!ClientModuleManager.validateScript(script))
|
|
129
|
+
throw new Error(`Invalid module script: ${file}`);
|
|
130
|
+
modules.push(new RecipleModule_1.RecipleModule({
|
|
131
|
+
client: this.client,
|
|
132
|
+
script,
|
|
133
|
+
filePath: file,
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (options.ignoreErrors === false)
|
|
138
|
+
throw err;
|
|
139
|
+
if (!this.client.isClientLogsSilent)
|
|
140
|
+
this.client.logger.error(`Can't resolve module from: ${file}`, err);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return modules;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Validate module script
|
|
147
|
+
* @param script module script
|
|
148
|
+
* @returns `true` if script is valid
|
|
149
|
+
*/
|
|
150
|
+
static validateScript(script) {
|
|
151
|
+
const s = script;
|
|
152
|
+
if (typeof s !== 'object')
|
|
153
|
+
return false;
|
|
154
|
+
if (typeof s.versions !== 'string' && !Array.isArray(s.versions))
|
|
155
|
+
return false;
|
|
156
|
+
if (typeof s.onStart !== 'function')
|
|
157
|
+
return false;
|
|
158
|
+
if (s.onLoad && typeof s.onLoad !== 'function')
|
|
159
|
+
return false;
|
|
160
|
+
if (s.onUnload && typeof s.onUnload !== 'function')
|
|
161
|
+
return false;
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get module file paths from folders
|
|
166
|
+
* @param options get module paths options
|
|
167
|
+
* @returns module paths
|
|
168
|
+
*/
|
|
169
|
+
async getModulePaths(options) {
|
|
170
|
+
const modules = [];
|
|
171
|
+
for (const dir of options?.folders ?? (0, discord_js_1.normalizeArray)([this.client.config.modulesFolder])) {
|
|
172
|
+
if (!(0, fs_1.existsSync)(dir))
|
|
173
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
174
|
+
if (!(0, fs_1.lstatSync)(dir).isDirectory())
|
|
175
|
+
continue;
|
|
176
|
+
modules.push(...(0, fs_1.readdirSync)(dir)
|
|
177
|
+
.map(file => util_2.path.join(!dir.startsWith('/') ? this.client.cwd : '', dir, file))
|
|
178
|
+
.filter(file => (options?.filter ? options.filter(file) : file.endsWith('.js'))));
|
|
179
|
+
}
|
|
180
|
+
return modules.filter(file => !(options?.ignoredFiles ?? this.client.config.ignoredFiles).some(ignored => (0, wildcard_match_1.default)(ignored)(util_2.path.basename(file))));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.ClientModuleManager = ClientModuleManager;
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandCooldownManager = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
/**
|
|
6
|
-
* cooled-down users manager
|
|
7
|
-
*/
|
|
8
|
-
class CommandCooldownManager extends Array {
|
|
9
|
-
constructor(...data) {
|
|
10
|
-
super(...(0, discord_js_1.normalizeArray)(data));
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Alias for `CommandCooldownManager#push()`
|
|
14
|
-
* @param options Cooled-down user data
|
|
15
|
-
*/
|
|
16
|
-
add(...options) {
|
|
17
|
-
return this.push(...options);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Remove cooldown from specific user, channel or guild
|
|
21
|
-
* @param options Remove cooldown data options
|
|
22
|
-
* @param limit Remove cooldown data limit
|
|
23
|
-
* @returns Returns the removed values
|
|
24
|
-
*/
|
|
25
|
-
remove(options, limit = 0) {
|
|
26
|
-
if (!Object.keys(options).length)
|
|
27
|
-
throw new TypeError('Provide atleast one option to remove cooldown data.');
|
|
28
|
-
const removed = [];
|
|
29
|
-
let i = 0;
|
|
30
|
-
for (let i = 0; i < this.length; i++) {
|
|
31
|
-
if (!CommandCooldownManager.checkOptions(options, this[i]))
|
|
32
|
-
continue;
|
|
33
|
-
if (options.expireTime && this[i].expireTime > Date.now())
|
|
34
|
-
continue;
|
|
35
|
-
if (limit && i >= limit)
|
|
36
|
-
continue;
|
|
37
|
-
removed.push(this[i]);
|
|
38
|
-
this.splice(Number(i));
|
|
39
|
-
}
|
|
40
|
-
return removed;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Check if the given user is cooled-down
|
|
44
|
-
* @param options Options to identify if user is on cooldown
|
|
45
|
-
*/
|
|
46
|
-
isCooledDown(options) {
|
|
47
|
-
const data = this.get(options);
|
|
48
|
-
if (!data)
|
|
49
|
-
return false;
|
|
50
|
-
this.remove({
|
|
51
|
-
...data,
|
|
52
|
-
channel: undefined,
|
|
53
|
-
guild: undefined,
|
|
54
|
-
type: undefined,
|
|
55
|
-
command: undefined,
|
|
56
|
-
});
|
|
57
|
-
if (data.expireTime < Date.now())
|
|
58
|
-
return false;
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Purge non cooled-down users from this array
|
|
63
|
-
* @param options Clean cooldown options
|
|
64
|
-
*/
|
|
65
|
-
clean(options) {
|
|
66
|
-
for (const index in this) {
|
|
67
|
-
if (options && !CommandCooldownManager.checkOptions(options, this[index]))
|
|
68
|
-
return;
|
|
69
|
-
if (this[index].expireTime > Date.now())
|
|
70
|
-
return;
|
|
71
|
-
this.slice(Number(index));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Get someone's cooldown data
|
|
76
|
-
* @param options Get cooldown data options
|
|
77
|
-
*/
|
|
78
|
-
get(options) {
|
|
79
|
-
return this.find(data => CommandCooldownManager.checkOptions(options, data));
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Check if the options are valid
|
|
83
|
-
* @param options Options to validated
|
|
84
|
-
* @param data Cooled-down user data
|
|
85
|
-
*/
|
|
86
|
-
static checkOptions(options, data) {
|
|
87
|
-
if (options?.user !== undefined && options.user.id !== data.user.id)
|
|
88
|
-
return false;
|
|
89
|
-
if (options?.guild !== undefined && options.guild?.id !== data.guild?.id)
|
|
90
|
-
return false;
|
|
91
|
-
if (options?.channel !== undefined && options.channel.id !== data.channel?.id)
|
|
92
|
-
return false;
|
|
93
|
-
if (options?.command !== undefined && options.command !== data.command)
|
|
94
|
-
return false;
|
|
95
|
-
if (options?.type !== undefined && options.type !== data.type)
|
|
96
|
-
return false;
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
exports.CommandCooldownManager = CommandCooldownManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandCooldownManager = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
/**
|
|
6
|
+
* cooled-down users manager
|
|
7
|
+
*/
|
|
8
|
+
class CommandCooldownManager extends Array {
|
|
9
|
+
constructor(...data) {
|
|
10
|
+
super(...(0, discord_js_1.normalizeArray)(data));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Alias for `CommandCooldownManager#push()`
|
|
14
|
+
* @param options Cooled-down user data
|
|
15
|
+
*/
|
|
16
|
+
add(...options) {
|
|
17
|
+
return this.push(...options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Remove cooldown from specific user, channel or guild
|
|
21
|
+
* @param options Remove cooldown data options
|
|
22
|
+
* @param limit Remove cooldown data limit
|
|
23
|
+
* @returns Returns the removed values
|
|
24
|
+
*/
|
|
25
|
+
remove(options, limit = 0) {
|
|
26
|
+
if (!Object.keys(options).length)
|
|
27
|
+
throw new TypeError('Provide atleast one option to remove cooldown data.');
|
|
28
|
+
const removed = [];
|
|
29
|
+
let i = 0;
|
|
30
|
+
for (let i = 0; i < this.length; i++) {
|
|
31
|
+
if (!CommandCooldownManager.checkOptions(options, this[i]))
|
|
32
|
+
continue;
|
|
33
|
+
if (options.expireTime && this[i].expireTime > Date.now())
|
|
34
|
+
continue;
|
|
35
|
+
if (limit && i >= limit)
|
|
36
|
+
continue;
|
|
37
|
+
removed.push(this[i]);
|
|
38
|
+
this.splice(Number(i));
|
|
39
|
+
}
|
|
40
|
+
return removed;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if the given user is cooled-down
|
|
44
|
+
* @param options Options to identify if user is on cooldown
|
|
45
|
+
*/
|
|
46
|
+
isCooledDown(options) {
|
|
47
|
+
const data = this.get(options);
|
|
48
|
+
if (!data)
|
|
49
|
+
return false;
|
|
50
|
+
this.remove({
|
|
51
|
+
...data,
|
|
52
|
+
channel: undefined,
|
|
53
|
+
guild: undefined,
|
|
54
|
+
type: undefined,
|
|
55
|
+
command: undefined,
|
|
56
|
+
});
|
|
57
|
+
if (data.expireTime < Date.now())
|
|
58
|
+
return false;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Purge non cooled-down users from this array
|
|
63
|
+
* @param options Clean cooldown options
|
|
64
|
+
*/
|
|
65
|
+
clean(options) {
|
|
66
|
+
for (const index in this) {
|
|
67
|
+
if (options && !CommandCooldownManager.checkOptions(options, this[index]))
|
|
68
|
+
return;
|
|
69
|
+
if (this[index].expireTime > Date.now())
|
|
70
|
+
return;
|
|
71
|
+
this.slice(Number(index));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get someone's cooldown data
|
|
76
|
+
* @param options Get cooldown data options
|
|
77
|
+
*/
|
|
78
|
+
get(options) {
|
|
79
|
+
return this.find(data => CommandCooldownManager.checkOptions(options, data));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if the options are valid
|
|
83
|
+
* @param options Options to validated
|
|
84
|
+
* @param data Cooled-down user data
|
|
85
|
+
*/
|
|
86
|
+
static checkOptions(options, data) {
|
|
87
|
+
if (options?.user !== undefined && options.user.id !== data.user.id)
|
|
88
|
+
return false;
|
|
89
|
+
if (options?.guild !== undefined && options.guild?.id !== data.guild?.id)
|
|
90
|
+
return false;
|
|
91
|
+
if (options?.channel !== undefined && options.channel.id !== data.channel?.id)
|
|
92
|
+
return false;
|
|
93
|
+
if (options?.command !== undefined && options.command !== data.command)
|
|
94
|
+
return false;
|
|
95
|
+
if (options?.type !== undefined && options.type !== data.type)
|
|
96
|
+
return false;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.CommandCooldownManager = CommandCooldownManager;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageCommandOptionManager = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
/**
|
|
6
|
-
* Validated message options manager
|
|
7
|
-
*/
|
|
8
|
-
class MessageCommandOptionManager extends Array {
|
|
9
|
-
constructor(...data) {
|
|
10
|
-
super(...(0, discord_js_1.normalizeArray)(data));
|
|
11
|
-
}
|
|
12
|
-
get(name, required) {
|
|
13
|
-
const option = this.find(o => o.name == name);
|
|
14
|
-
if (!option?.value == undefined && required)
|
|
15
|
-
throw new TypeError(`Can't find option named ${name}`);
|
|
16
|
-
return option ?? null;
|
|
17
|
-
}
|
|
18
|
-
getValue(name, requied) {
|
|
19
|
-
const option = this.get(name, requied);
|
|
20
|
-
if (!option?.value && requied)
|
|
21
|
-
throw new TypeError(`Value of option named ${name} is undefined`);
|
|
22
|
-
return option?.value ?? null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.MessageCommandOptionManager = MessageCommandOptionManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageCommandOptionManager = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
/**
|
|
6
|
+
* Validated message options manager
|
|
7
|
+
*/
|
|
8
|
+
class MessageCommandOptionManager extends Array {
|
|
9
|
+
constructor(...data) {
|
|
10
|
+
super(...(0, discord_js_1.normalizeArray)(data));
|
|
11
|
+
}
|
|
12
|
+
get(name, required) {
|
|
13
|
+
const option = this.find(o => o.name == name);
|
|
14
|
+
if (!option?.value == undefined && required)
|
|
15
|
+
throw new TypeError(`Can't find option named ${name}`);
|
|
16
|
+
return option ?? null;
|
|
17
|
+
}
|
|
18
|
+
getValue(name, requied) {
|
|
19
|
+
const option = this.get(name, requied);
|
|
20
|
+
if (!option?.value && requied)
|
|
21
|
+
throw new TypeError(`Value of option named ${name} is undefined`);
|
|
22
|
+
return option?.value ?? null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.MessageCommandOptionManager = MessageCommandOptionManager;
|