reciple 6.0.0-dev.23 → 6.0.0-dev.25
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 +66 -65
- package/dist/lib/esm.mjs +1 -1
- package/dist/lib/index.js +33 -35
- package/dist/lib/reciple/classes/RecipleClient.js +296 -296
- 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 +309 -325
- package/dist/lib/reciple/classes/builders/MessageCommandOptionBuilder.js +126 -107
- package/dist/lib/reciple/classes/builders/SlashCommandBuilder.js +246 -246
- package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js +178 -178
- package/dist/lib/reciple/classes/managers/CommandCooldownManager.js +99 -100
- package/dist/lib/reciple/classes/managers/CommandManager.js +59 -59
- package/dist/lib/reciple/classes/managers/MessageCommandOptionManager.js +25 -25
- package/dist/lib/reciple/classes/managers/ModuleManager.js +176 -179
- 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 +69 -68
- 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 +17 -19
- package/dist/types/reciple/classes/RecipleClient.d.ts +104 -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 +189 -184
- package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +53 -51
- package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +98 -98
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +53 -53
- package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +70 -70
- package/dist/types/reciple/classes/managers/CommandManager.d.ts +34 -36
- package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts +22 -22
- package/dist/types/reciple/classes/managers/ModuleManager.d.ts +49 -49
- package/dist/types/reciple/flags.d.ts +17 -17
- package/dist/types/reciple/permissions.d.ts +15 -19
- package/dist/types/reciple/types/builders.d.ts +205 -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 +26 -23
- package/dist/types/reciple/version.d.ts +25 -25
- package/package.json +21 -20
- package/resource/reciple.yml +120 -120
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApplicationCommandManager = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
|
|
6
|
-
class ApplicationCommandManager {
|
|
7
|
-
constructor(client) {
|
|
8
|
-
this.client = client;
|
|
9
|
-
}
|
|
10
|
-
get commands() {
|
|
11
|
-
return [...this.client.commands.additionalApplicationCommands, ...this.client.commands.slashCommands.toJSON()];
|
|
12
|
-
}
|
|
13
|
-
get size() {
|
|
14
|
-
return this.commands.length;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Sets application commands globally or in guilds
|
|
18
|
-
* @param commands Application commands
|
|
19
|
-
* @param guilds set only to guilds
|
|
20
|
-
*/
|
|
21
|
-
async set(commands, ...guilds) {
|
|
22
|
-
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
23
|
-
if (!this.client.isReady())
|
|
24
|
-
throw new Error('Client is not ready');
|
|
25
|
-
if (guilds && guilds.length > 1) {
|
|
26
|
-
for (const guild of guilds) {
|
|
27
|
-
await this.set(commands, guild);
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
let guild = guilds?.shift();
|
|
32
|
-
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
33
|
-
if (!guild) {
|
|
34
|
-
await this.client.application.commands.set(commands);
|
|
35
|
-
if (!this.client.isClientLogsSilent)
|
|
36
|
-
this.client.logger.log(`Registered ${this.client.applicationCommands.size} application command(s) globally...`);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
await this.client.application.commands.set(commands, guild);
|
|
40
|
-
if (!this.client.isClientLogsSilent)
|
|
41
|
-
this.client.logger.log(`Registered ${this.client.applicationCommands.size} application command(s) to guild ${guild}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Add command globally or in guilds
|
|
46
|
-
* @param command Application command
|
|
47
|
-
* @param guilds add only in guilds
|
|
48
|
-
*/
|
|
49
|
-
async add(command, ...guilds) {
|
|
50
|
-
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
51
|
-
if (!this.client.isReady())
|
|
52
|
-
throw new Error('Client is not ready');
|
|
53
|
-
if (!command)
|
|
54
|
-
throw new Error('Command is undefined');
|
|
55
|
-
if (guilds && guilds.length > 1) {
|
|
56
|
-
for (const guild of guilds) {
|
|
57
|
-
await this.add(command, guild);
|
|
58
|
-
}
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
let guild = guilds?.shift();
|
|
62
|
-
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
63
|
-
if (!guild) {
|
|
64
|
-
await this.client.application.commands.create(command);
|
|
65
|
-
if (!this.client.isClientLogsSilent)
|
|
66
|
-
this.client.logger.log(`Created application command '${command.name}' globally`);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
await this.client.application.commands.create(command, guild);
|
|
70
|
-
if (!this.client.isClientLogsSilent)
|
|
71
|
-
this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Remove application command globally or in guilds
|
|
76
|
-
* @param command id of application commmand or ApplicationCommand class
|
|
77
|
-
* @param guilds Remove from guilds
|
|
78
|
-
*/
|
|
79
|
-
async remove(command, ...guilds) {
|
|
80
|
-
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
81
|
-
if (!this.client.isReady())
|
|
82
|
-
throw new Error('Client is not ready');
|
|
83
|
-
if (!command)
|
|
84
|
-
throw new Error('Command is undefined');
|
|
85
|
-
if (guilds && guilds.length > 1) {
|
|
86
|
-
for (const guild of guilds) {
|
|
87
|
-
await this.remove(command, guild);
|
|
88
|
-
}
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
let guild = guilds?.shift();
|
|
92
|
-
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
93
|
-
if (!guild) {
|
|
94
|
-
await this.client.application.commands.delete(command);
|
|
95
|
-
if (!this.client.isClientLogsSilent)
|
|
96
|
-
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
await this.client.application.commands.delete(command, guild);
|
|
100
|
-
if (!this.client.isClientLogsSilent)
|
|
101
|
-
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Edit application command globally or in guilds
|
|
106
|
-
* @param command id of application command or ApplicationCommand class
|
|
107
|
-
* @param newCommand new application command data
|
|
108
|
-
* @param guilds Edit only from guilds
|
|
109
|
-
*/
|
|
110
|
-
async edit(command, newCommand, ...guilds) {
|
|
111
|
-
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
112
|
-
if (!this.client.isReady())
|
|
113
|
-
throw new Error('Client is not ready');
|
|
114
|
-
if (!command)
|
|
115
|
-
throw new Error('Command is undefined');
|
|
116
|
-
if (guilds && guilds.length > 1) {
|
|
117
|
-
for (const guild of guilds) {
|
|
118
|
-
await this.edit(command, newCommand, guild);
|
|
119
|
-
}
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
let guild = guilds?.shift();
|
|
123
|
-
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
124
|
-
if (!guild) {
|
|
125
|
-
await this.client.application.commands.edit(command, newCommand);
|
|
126
|
-
if (!this.client.isClientLogsSilent)
|
|
127
|
-
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
await this.client.application.commands.edit(command, newCommand, guild);
|
|
131
|
-
if (!this.client.isClientLogsSilent)
|
|
132
|
-
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Get application command from cache by application command data, builder, id, or name globally or from guid
|
|
137
|
-
* @param command application command data, builder, id, or name
|
|
138
|
-
* @param guild get command from guild
|
|
139
|
-
*/
|
|
140
|
-
get(command, guild) {
|
|
141
|
-
const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
|
|
142
|
-
if (!commands)
|
|
143
|
-
throw new Error('Guild not found in cache');
|
|
144
|
-
return commands.find(cmd => (typeof command === 'string' ? cmd.id === command || cmd.name === command : cmd.name === command.name || (command instanceof discord_js_1.ApplicationCommand && cmd.id === command.id)));
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Fetch application command by id globally or from guild
|
|
148
|
-
* @param commandId command id
|
|
149
|
-
* @param guild fetch from guild
|
|
150
|
-
*/
|
|
151
|
-
async fetch(commandId, guild) {
|
|
152
|
-
const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
|
|
153
|
-
if (!manager)
|
|
154
|
-
throw new Error('Guild not found in cache');
|
|
155
|
-
return manager.fetch(commandId);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Parse application command builders to command data
|
|
159
|
-
* @param commands Application command builders
|
|
160
|
-
* @param setPermissions set slash commands permissions
|
|
161
|
-
*/
|
|
162
|
-
parseCommands(commands, setPermissions = true) {
|
|
163
|
-
return commands.map(cmd => {
|
|
164
|
-
if (cmd?.toJSON === undefined)
|
|
165
|
-
return cmd;
|
|
166
|
-
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && this.client.config.commands.slashCommand.setRequiredPermissions) {
|
|
167
|
-
const permissions = setPermissions || this.client.config.commands.slashCommand.permissions.enabled ? this.client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions : undefined;
|
|
168
|
-
if (permissions) {
|
|
169
|
-
cmd.setRequiredMemberPermissions(...permissions);
|
|
170
|
-
if (!this.client.isClientLogsSilent)
|
|
171
|
-
this.client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return cmd.toJSON();
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
exports.ApplicationCommandManager = ApplicationCommandManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationCommandManager = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
|
|
6
|
+
class ApplicationCommandManager {
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
get commands() {
|
|
11
|
+
return [...this.client.commands.additionalApplicationCommands, ...this.client.commands.slashCommands.toJSON()];
|
|
12
|
+
}
|
|
13
|
+
get size() {
|
|
14
|
+
return this.commands.length;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sets application commands globally or in guilds
|
|
18
|
+
* @param commands Application commands
|
|
19
|
+
* @param guilds set only to guilds
|
|
20
|
+
*/
|
|
21
|
+
async set(commands, ...guilds) {
|
|
22
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
23
|
+
if (!this.client.isReady())
|
|
24
|
+
throw new Error('Client is not ready');
|
|
25
|
+
if (guilds && guilds.length > 1) {
|
|
26
|
+
for (const guild of guilds) {
|
|
27
|
+
await this.set(commands, guild);
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let guild = guilds?.shift();
|
|
32
|
+
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
33
|
+
if (!guild) {
|
|
34
|
+
await this.client.application.commands.set(commands);
|
|
35
|
+
if (!this.client.isClientLogsSilent)
|
|
36
|
+
this.client.logger.log(`Registered ${this.client.applicationCommands.size} application command(s) globally...`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
await this.client.application.commands.set(commands, guild);
|
|
40
|
+
if (!this.client.isClientLogsSilent)
|
|
41
|
+
this.client.logger.log(`Registered ${this.client.applicationCommands.size} application command(s) to guild ${guild}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Add command globally or in guilds
|
|
46
|
+
* @param command Application command
|
|
47
|
+
* @param guilds add only in guilds
|
|
48
|
+
*/
|
|
49
|
+
async add(command, ...guilds) {
|
|
50
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
51
|
+
if (!this.client.isReady())
|
|
52
|
+
throw new Error('Client is not ready');
|
|
53
|
+
if (!command)
|
|
54
|
+
throw new Error('Command is undefined');
|
|
55
|
+
if (guilds && guilds.length > 1) {
|
|
56
|
+
for (const guild of guilds) {
|
|
57
|
+
await this.add(command, guild);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let guild = guilds?.shift();
|
|
62
|
+
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
63
|
+
if (!guild) {
|
|
64
|
+
await this.client.application.commands.create(command);
|
|
65
|
+
if (!this.client.isClientLogsSilent)
|
|
66
|
+
this.client.logger.log(`Created application command '${command.name}' globally`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
await this.client.application.commands.create(command, guild);
|
|
70
|
+
if (!this.client.isClientLogsSilent)
|
|
71
|
+
this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Remove application command globally or in guilds
|
|
76
|
+
* @param command id of application commmand or ApplicationCommand class
|
|
77
|
+
* @param guilds Remove from guilds
|
|
78
|
+
*/
|
|
79
|
+
async remove(command, ...guilds) {
|
|
80
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
81
|
+
if (!this.client.isReady())
|
|
82
|
+
throw new Error('Client is not ready');
|
|
83
|
+
if (!command)
|
|
84
|
+
throw new Error('Command is undefined');
|
|
85
|
+
if (guilds && guilds.length > 1) {
|
|
86
|
+
for (const guild of guilds) {
|
|
87
|
+
await this.remove(command, guild);
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let guild = guilds?.shift();
|
|
92
|
+
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
93
|
+
if (!guild) {
|
|
94
|
+
await this.client.application.commands.delete(command);
|
|
95
|
+
if (!this.client.isClientLogsSilent)
|
|
96
|
+
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
await this.client.application.commands.delete(command, guild);
|
|
100
|
+
if (!this.client.isClientLogsSilent)
|
|
101
|
+
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Edit application command globally or in guilds
|
|
106
|
+
* @param command id of application command or ApplicationCommand class
|
|
107
|
+
* @param newCommand new application command data
|
|
108
|
+
* @param guilds Edit only from guilds
|
|
109
|
+
*/
|
|
110
|
+
async edit(command, newCommand, ...guilds) {
|
|
111
|
+
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
112
|
+
if (!this.client.isReady())
|
|
113
|
+
throw new Error('Client is not ready');
|
|
114
|
+
if (!command)
|
|
115
|
+
throw new Error('Command is undefined');
|
|
116
|
+
if (guilds && guilds.length > 1) {
|
|
117
|
+
for (const guild of guilds) {
|
|
118
|
+
await this.edit(command, newCommand, guild);
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
let guild = guilds?.shift();
|
|
123
|
+
guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
|
|
124
|
+
if (!guild) {
|
|
125
|
+
await this.client.application.commands.edit(command, newCommand);
|
|
126
|
+
if (!this.client.isClientLogsSilent)
|
|
127
|
+
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
await this.client.application.commands.edit(command, newCommand, guild);
|
|
131
|
+
if (!this.client.isClientLogsSilent)
|
|
132
|
+
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get application command from cache by application command data, builder, id, or name globally or from guid
|
|
137
|
+
* @param command application command data, builder, id, or name
|
|
138
|
+
* @param guild get command from guild
|
|
139
|
+
*/
|
|
140
|
+
get(command, guild) {
|
|
141
|
+
const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
|
|
142
|
+
if (!commands)
|
|
143
|
+
throw new Error('Guild not found in cache');
|
|
144
|
+
return commands.find(cmd => (typeof command === 'string' ? cmd.id === command || cmd.name === command : cmd.name === command.name || (command instanceof discord_js_1.ApplicationCommand && cmd.id === command.id)));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Fetch application command by id globally or from guild
|
|
148
|
+
* @param commandId command id
|
|
149
|
+
* @param guild fetch from guild
|
|
150
|
+
*/
|
|
151
|
+
async fetch(commandId, guild) {
|
|
152
|
+
const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
|
|
153
|
+
if (!manager)
|
|
154
|
+
throw new Error('Guild not found in cache');
|
|
155
|
+
return manager.fetch(commandId);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Parse application command builders to command data
|
|
159
|
+
* @param commands Application command builders
|
|
160
|
+
* @param setPermissions set slash commands permissions
|
|
161
|
+
*/
|
|
162
|
+
parseCommands(commands, setPermissions = true) {
|
|
163
|
+
return commands.map(cmd => {
|
|
164
|
+
if (cmd?.toJSON === undefined)
|
|
165
|
+
return cmd;
|
|
166
|
+
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && this.client.config.commands.slashCommand.setRequiredPermissions) {
|
|
167
|
+
const permissions = setPermissions || this.client.config.commands.slashCommand.permissions.enabled ? this.client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions : undefined;
|
|
168
|
+
if (permissions) {
|
|
169
|
+
cmd.setRequiredMemberPermissions(...permissions);
|
|
170
|
+
if (!this.client.isClientLogsSilent)
|
|
171
|
+
this.client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return cmd.toJSON();
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.ApplicationCommandManager = ApplicationCommandManager;
|
|
@@ -1,100 +1,99 @@
|
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* Get
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*
|
|
83
|
-
* @param
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
+
for (let i = 0; i < this.length; i++) {
|
|
30
|
+
if (!CommandCooldownManager.checkOptions(options, this[i]))
|
|
31
|
+
continue;
|
|
32
|
+
if (options.expireTime && this[i].expireTime > Date.now())
|
|
33
|
+
continue;
|
|
34
|
+
if (limit && i >= limit)
|
|
35
|
+
continue;
|
|
36
|
+
removed.push(this[i]);
|
|
37
|
+
this.splice(Number(i));
|
|
38
|
+
}
|
|
39
|
+
return removed;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if the given user is cooled-down
|
|
43
|
+
* @param options Options to identify if user is on cooldown
|
|
44
|
+
*/
|
|
45
|
+
isCooledDown(options) {
|
|
46
|
+
const data = this.get(options);
|
|
47
|
+
if (!data)
|
|
48
|
+
return false;
|
|
49
|
+
this.remove({
|
|
50
|
+
...data,
|
|
51
|
+
channel: undefined,
|
|
52
|
+
guild: undefined,
|
|
53
|
+
type: undefined,
|
|
54
|
+
command: undefined,
|
|
55
|
+
});
|
|
56
|
+
if (data.expireTime < Date.now())
|
|
57
|
+
return false;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Purge non cooled-down users from this array
|
|
62
|
+
* @param options Clean cooldown options
|
|
63
|
+
*/
|
|
64
|
+
clean(options) {
|
|
65
|
+
for (const index in this) {
|
|
66
|
+
if (options && !CommandCooldownManager.checkOptions(options, this[index]))
|
|
67
|
+
return;
|
|
68
|
+
if (this[index].expireTime > Date.now())
|
|
69
|
+
return;
|
|
70
|
+
this.slice(Number(index));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get someone's cooldown data
|
|
75
|
+
* @param options Get cooldown data options
|
|
76
|
+
*/
|
|
77
|
+
get(options) {
|
|
78
|
+
return this.find(data => CommandCooldownManager.checkOptions(options, data));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Check if the options are valid
|
|
82
|
+
* @param options Options to validated
|
|
83
|
+
* @param data Cooled-down user data
|
|
84
|
+
*/
|
|
85
|
+
static checkOptions(options, data) {
|
|
86
|
+
if (options?.user !== undefined && options.user.id !== data.user.id)
|
|
87
|
+
return false;
|
|
88
|
+
if (options?.guild !== undefined && options.guild?.id !== data.guild?.id)
|
|
89
|
+
return false;
|
|
90
|
+
if (options?.channel !== undefined && options.channel.id !== data.channel?.id)
|
|
91
|
+
return false;
|
|
92
|
+
if (options?.command !== undefined && options.command !== data.command)
|
|
93
|
+
return false;
|
|
94
|
+
if (options?.type !== undefined && options.type !== data.type)
|
|
95
|
+
return false;
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.CommandCooldownManager = CommandCooldownManager;
|