xernerx 2.4.3 → 2.5.0

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/models/Client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const Discord = require('discord.js');
2
2
  const { s } = require('@sapphire/shapeshift');
3
- const { color, config } = require('./data/Functions.js');
3
+ const { color, config } = require('./utils/Functions.js');
4
4
  const { CommandHandler } = require('./handlers/CommandHandler.js');
5
5
  const { EventHandler } = require('./handlers/EventHandler.js');
6
6
  const { LanguageHandler } = require('./handlers/LanguageHandler.js');
@@ -29,7 +29,6 @@ class Client extends Discord.Client {
29
29
  ownerId: s.array(s.string).optional,
30
30
  ignoreOwner: s.boolean.optional,
31
31
  defaultCooldown: s.number.optional,
32
- logging: s.array(s.string).optional,
33
32
  cacheTime: s.number.optional,
34
33
  userPermissions: s.array(s.string).optional,
35
34
  clientPermissions: s.array(s.string).optional,
@@ -57,9 +57,11 @@ class ContextMenuCommand {
57
57
  }
58
58
 
59
59
  types(str) {
60
- if (String(str)?.toLowerCase() == "message") str = 3
61
- if (String(str)?.toLowerCase() == "user") str = 2
62
- return str
60
+ if (String(str)?.toLowerCase() == "message") str = 3;
61
+
62
+ if (String(str)?.toLowerCase() == "user") str = 2;
63
+
64
+ return str;
63
65
  }
64
66
  }
65
67
 
@@ -1,8 +1,8 @@
1
1
  const { Event } = require('../commands/Event.js');
2
- const { interactionArgs } = require('./../data/Arguments.js');
2
+ const { interactionArgs } = require('./../utils/Arguments.js');
3
3
  const { InteractionType } = require('discord.js')
4
- const commandValidation = require('./../data/CommandValidation.js');
5
- const { interactionUtil } = require('./../data/Util.js');
4
+ const { commandValidation } = require('./../utils/CommandValidation.js');
5
+ const { interactionUtil } = require('./../utils/Util.js');
6
6
  /**
7
7
  * @returns interaction command executor.
8
8
  */
@@ -1,7 +1,7 @@
1
1
  const { Event } = require('../commands/Event.js');
2
- const { messageArgs } = require("./../data/Arguments.js");
3
- const commandValidation = require('./../data/CommandValidation.js');
4
- const { messageUtil } = require('../data/Util.js');
2
+ const { messageArgs } = require("./../utils/Arguments.js");
3
+ const { commandValidation } = require('./../utils/CommandValidation.js');
4
+ const { messageUtil } = require('../utils/Util.js');
5
5
 
6
6
  /**
7
7
  * @returns message command executor.
@@ -1,7 +1,7 @@
1
1
  const { Event } = require('../commands/Event.js');
2
- const { messageArgs } = require("./../data/Arguments.js");
3
- const commandValidation = require('./../data/CommandValidation.js');
4
- const { messageUtil } = require('../data/Util.js');
2
+ const { messageArgs } = require("./../utils/Arguments.js");
3
+ const { commandValidation } = require('./../utils/CommandValidation.js');
4
+ const { messageUtil } = require('../utils/Util.js');
5
5
 
6
6
  /**
7
7
  * @returns message command executor.
@@ -13,9 +13,9 @@ class BuildInReadyOnceEvent extends Event {
13
13
  }
14
14
 
15
15
  async run(client) {
16
- if (client.logging) console.log(logStyle(`${client.user.tag} is online in ${(await client.guilds.fetch()).size} server(s).`, "text", "green"))
16
+ if (client.settings.logging) console.info(logStyle(`${client.user.tag} is online in ${(await client.guilds.fetch()).size} servers.`, "text", "cyan"));
17
17
 
18
- if (client.settings.logging) {
18
+ if (Array.isArray(client.settings.logging)) {
19
19
  let loaded = [];
20
20
 
21
21
  for (const [type, commands] of Object.entries(client.commands)) {
@@ -29,15 +29,22 @@ class BuildInReadyOnceEvent extends Event {
29
29
  if (!loaded.includes(command)) loaded.push(command);
30
30
  }
31
31
  }
32
+
32
33
  for (const [id, event] of [...client.events]) {
33
- event.runType = 'event'
34
+ event.runType = 'event';
34
35
 
35
- loaded.push(event)
36
+ loaded.push(event);
36
37
  }
37
38
 
38
39
  console.table(loaded, client.settings.logging);
39
40
  }
41
+ else {
42
+ Object.entries(client.commands).map(([type, commands]) => {
43
+ console.info(logStyle(`Loaded ${type} commands: ${commands.map(command => command?.data?.name || command?.name || command?.id).join(', ')}`, "text", "cyan"));
44
+ })
45
+ }
40
46
  }
47
+
41
48
  };
42
49
 
43
50
  module.exports = BuildInReadyOnceEvent;
@@ -23,17 +23,22 @@ class Loader {
23
23
  const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'))
24
24
 
25
25
  for (const file of commandFiles) {
26
- let filepath = `${require("path").resolve(path)}/${file}`
26
+ try {
27
+ let filepath = `${require("path").resolve(path)}/${file}`
27
28
 
28
- let command = require(filepath);
29
+ let command = require(filepath);
29
30
 
30
- command = new command;
31
+ command = new command;
31
32
 
32
- command.filepath = filepath;
33
+ command.filepath = filepath;
33
34
 
34
- this.commands.push(command.data.toJSON());
35
+ this.commands.push(command.data.toJSON());
35
36
 
36
- this.client.commands.interaction.set(command.data.name, command);
37
+ this.client.commands.interaction.set(command.data.name, command);
38
+ }
39
+ catch (error) {
40
+ console.error(logStyle(`Couldn't load ${file} because of <${error.message}>!`, "text", "red"));
41
+ }
37
42
  }
38
43
 
39
44
  this.#deployCommands("interaction commands", logging);
@@ -67,17 +72,22 @@ class Loader {
67
72
  const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'));
68
73
 
69
74
  for (const file of commandFiles) {
70
- let filepath = `${require("path").resolve(path)}/${file}`
75
+ try {
76
+ let filepath = `${require("path").resolve(path)}/${file}`
71
77
 
72
- let command = require(filepath);
78
+ let command = require(filepath);
73
79
 
74
- command = new command;
80
+ command = new command;
75
81
 
76
- command.filepath = filepath;
82
+ command.filepath = filepath;
77
83
 
78
- this.commands.push(command.data.toJSON());
84
+ this.commands.push(command.data.toJSON());
79
85
 
80
- this.client.commands.contextMenu.set(command.data.name, command);
86
+ this.client.commands.contextMenu.set(command.data.name, command);
87
+ }
88
+ catch (error) {
89
+ console.error(logStyle(`Couldn't load ${file} because of <${error.message}>!`, "text", "red"));
90
+ }
81
91
  }
82
92
 
83
93
  this.#deployCommands("context menu commands", logging);
@@ -111,19 +121,24 @@ class Loader {
111
121
  const commandFiles = fs.readdirSync(path).filter(file => file.endsWith('.js'));
112
122
 
113
123
  for (const file of commandFiles) {
114
- let filepath = `${require("path").resolve(path)}/${file}`
124
+ try {
125
+ let filepath = `${require("path").resolve(path)}/${file}`
115
126
 
116
- let command = require(filepath);
127
+ let command = require(filepath);
117
128
 
118
- command = new command;
129
+ command = new command;
119
130
 
120
- command.filepath = filepath;
131
+ command.filepath = filepath;
121
132
 
122
- command.aliases.forEach((alias) => {
123
- if (this.client.commands.message.has(alias)) throw new Error('Cannot have duplicated aliases.');
133
+ command.aliases.forEach((alias) => {
134
+ if (this.client.commands.message.has(alias)) throw new Error('Cannot have duplicated aliases.');
124
135
 
125
- this.client.commands.message.set(alias, command);
126
- });
136
+ this.client.commands.message.set(alias, command);
137
+ });
138
+ }
139
+ catch (error) {
140
+ console.error(logStyle(`Couldn't load ${file} because of <${error.message}>!`, "text", "red"));
141
+ }
127
142
  }
128
143
  }
129
144
 
@@ -154,8 +169,6 @@ class Loader {
154
169
  const rest = new REST({ version: GatewayVersion }).setToken(client.token);
155
170
 
156
171
  (async () => {
157
- if (type === "interaction commands" && client.settings.logging) console.log(logStyle(`${client.user.tag} is online in ${(await client.guilds.fetch()).size} servers.`, "text", "cyan"));
158
-
159
172
  try {
160
173
  if (client.settings.global == true) {
161
174
  if (logging || this.client.settings.logging) console.info(logStyle(`Loaded ${type} in ${(await client.guilds.fetch()).size} server(s) globally.`, 'text', 'purple'));
@@ -1,4 +1,4 @@
1
- class Arguments {
1
+ module.exports = new class Arguments {
2
2
  /**
3
3
  *
4
4
  * @param {object} interaction - Interaction event.
@@ -98,11 +98,4 @@ class Arguments {
98
98
 
99
99
  return args;
100
100
  }
101
- }
102
-
103
- args = new Arguments()
104
-
105
- module.exports = {
106
- interactionArgs: args.interactionArgs,
107
- messageArgs: args.messageArgs
108
101
  }
@@ -3,7 +3,7 @@ const { toPascalCase } = require('dumfunctions');
3
3
 
4
4
  const Cooldown = {};
5
5
 
6
- class CommandValidation {
6
+ module.exports = new class CommandValidation {
7
7
  commandValidation(event, command, res = false) {
8
8
  function emit(reason, extra) {
9
9
  return event.client.emit('commandBlocked', event, reason, extra);
@@ -95,6 +95,4 @@ class CommandValidation {
95
95
 
96
96
  return res;
97
97
  }
98
- }
99
-
100
- module.exports = new CommandValidation().commandValidation;
98
+ }
@@ -0,0 +1,258 @@
1
+ const colors = require('../data/colors.json');
2
+ const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder, Embed, ButtonBuilder, ButtonStyle } = require('discord.js');
3
+ const opts = require('../data/options.json');
4
+
5
+ function reply(interaction, text) {
6
+ return (interaction.replied || interaction.deferred) ? interaction.editReply(text) : interaction.reply(text);
7
+ }
8
+
9
+ /**
10
+ * @param {object} Functions - Build in functions of the bot hidden away in the handlers/setters.
11
+ */
12
+ module.exports = new class Functions {
13
+ /**
14
+ *
15
+ * @param {object} client - Client object.
16
+ * @param {object} options - Client options.
17
+ * @returns an object of default colors and custom colors to be imported anywhere without having to import them.
18
+ */
19
+ color({ client: client, options: options }) {
20
+ client.color = { FLAGS: colors }
21
+
22
+ if (options.color) {
23
+ for (const [name, color] of Object.entries(options.color)) {
24
+ client.color[name] = color;
25
+ }
26
+ }
27
+
28
+ return client.color;
29
+ }
30
+
31
+ /**
32
+ *
33
+ * @param {object} client - Client object.
34
+ * @param {object} options - Client options.
35
+ * @returns custom config settings for the bot.
36
+ */
37
+ config({ client: client, options: options }) {
38
+ client.config = {}
39
+
40
+ if (options.config) {
41
+ for (const [key, value] of Object.entries(options.config)) {
42
+ client.config[key] = value;
43
+ }
44
+ }
45
+
46
+ return client.config;
47
+ }
48
+
49
+ reply(interaction, text) {
50
+ return (interaction.replied || interaction.deferred) ? interaction.editReply(text) : interaction.reply(text);
51
+ }
52
+
53
+ selectMenuPaginator(interaction, embeds, options = {}) {
54
+ if (!embeds) return interaction.client.emit('error', interaction, "no embeds");
55
+
56
+ if (!Array.isArray(embeds)) return interaction.client.emit('error', interaction, "no array of embeds")
57
+
58
+ if (!options.index) {
59
+ options.index = new EmbedBuilder()
60
+ .setTitle(`${embeds.length} pages`)
61
+
62
+ embeds.map((embed, i = 0) => options.index.addFields([{ name: embed?.data?.title || embed?.data?.author?.name || "No name", value: embed?.data?.description || `Page ${i + 1}` }]))
63
+ }
64
+
65
+ if (!options.row) {
66
+ options.row = new ActionRowBuilder();
67
+
68
+ if (!options.id) options.id = `${interaction.id}-menu`;
69
+
70
+ options.comp = new SelectMenuBuilder()
71
+ .setCustomId(options.id)
72
+ .setMaxValues(1)
73
+ .setMinValues(1)
74
+ .setPlaceholder('Select a page.')
75
+ .addOptions({ label: 'Index', description: 'Index Page', value: 'index' })
76
+
77
+ embeds.map((embed, i = 0) => options.comp.addOptions({ label: embed?.data?.title || embed?.data?.author?.name, description: embed?.data?.description?.slice(0, 100) || `Page ${i + 1}`, value: opts[embeds.indexOf(embed)] }))
78
+
79
+ options.row.addComponents(options.comp);
80
+ }
81
+
82
+ if (!options.id) options.id = options.row.components[0].data.custom_id;
83
+
84
+ (async () => {
85
+ let embed = options.index;
86
+
87
+ let m = options.send ? await interaction.channel.send({ embeds: [embed], components: [options.row] }) : await reply(interaction, { embeds: [embed], components: [options.row] })
88
+
89
+ interaction.channel.createMessageComponentCollector({ filter: options.filter, time: options.time || 300000 })
90
+
91
+ .on('collect', async (a) => {
92
+ if (a.customId != options.id) return;
93
+
94
+ let chosen = a.values[0];
95
+
96
+ if (chosen === options.row.components[0]?.options[0]?.data?.value) embed = options.index;
97
+
98
+ else embed = embeds[opts.indexOf(chosen)];
99
+
100
+ a.update({ embeds: [embed] });
101
+ })
102
+
103
+ .on('end', async () => {
104
+ if (interaction.editReply) interaction.editReply({ components: [] });
105
+
106
+ if (interaction.edit) await m.edit({ components: [] });
107
+ })
108
+ })();
109
+ }
110
+
111
+ commandName(interaction, cmd) {
112
+ if (cmd) {
113
+ let cmds = [];
114
+
115
+ for (const commands of Object.values(interaction.client.commands)) {
116
+ let commandInfo = {};
117
+
118
+ if (commands.has(cmd)) {
119
+ const command = commands.get(cmd);
120
+
121
+ if (command?.data?.options?.length > 0) {
122
+ command?.data?.options?.map(option => {
123
+ if (!option?.type) {
124
+ if (option?.options?.length > 0) {
125
+ option?.options?.map(opt => {
126
+ if (!opt.type) {
127
+ commandInfo = {
128
+ name: command?.data?.name + " " + option?.name + " " + opt?.name,
129
+ description: opt.description,
130
+ category: command.category
131
+ }
132
+ }
133
+
134
+ else {
135
+ commandInfo = {
136
+ name: command?.data?.name + " " + option?.name,
137
+ description: option?.description,
138
+ category: command.category
139
+ }
140
+ }
141
+ })
142
+ }
143
+
144
+ else {
145
+ commandInfo = {
146
+ name: command?.data?.name + " " + option?.name,
147
+ description: option?.description,
148
+ category: command.category
149
+ }
150
+ }
151
+ }
152
+
153
+ else {
154
+ commandInfo = {
155
+ name: command?.data?.name || command?.id,
156
+ description: command?.data?.description || command?.description,
157
+ category: command.category
158
+ }
159
+ }
160
+ })
161
+ }
162
+
163
+ else {
164
+ commandInfo = {
165
+ name: command?.data?.name || command?.id,
166
+ description: command?.data?.description || command?.description,
167
+ category: command.category
168
+ }
169
+ }
170
+
171
+ cmds.push(commandInfo);
172
+ }
173
+
174
+ }
175
+ return cmds;
176
+ }
177
+
178
+ if (!cmd) return [interaction?.commandName || interaction.content?.replace(interaction.client.settings.prefix.find(p => interaction.content.startsWith(p)), "").split(/ +/)[0], interaction?.options?._group, interaction?.options?._subcommand].join(' ').replace(/ +/g, " ").trim();
179
+ }
180
+
181
+ buttonPaginator(interaction, embeds, options = {}) {
182
+ if (!options.buttons) options.buttons = ["⏪", "◀️", "⏹️", "▶️", "⏩"];
183
+
184
+ if (options.buttons.length <= 4 || options.buttons.length > 5) throw new Error('Must specify 5 emotes.');
185
+
186
+ options.row = new ActionRowBuilder();
187
+
188
+ for (const button of options.buttons) {
189
+ options.row
190
+ .addComponents(
191
+ new ButtonBuilder()
192
+ .setCustomId(`${interaction.id}-${opts[options.buttons.indexOf(button)]}`)
193
+ .setStyle(ButtonStyle[options.style || 'Primary'])
194
+ .setEmoji(button)
195
+ )
196
+ };
197
+
198
+ (async () => {
199
+ let embed = embeds[options.index || 0];
200
+
201
+ let m = options.send ? await interaction.channel.send({ embeds: [embed], components: [options.row] }) : await reply(interaction, { embeds: [embed], components: [options.row] });
202
+
203
+ const collector = interaction.channel.createMessageComponentCollector({ filter: options.filter, time: options.time || 300000 })
204
+
205
+ .on('collect', async (a) => {
206
+ if (a.customId == `${interaction.id}-one`) {
207
+ embed = embeds[0];
208
+ a.update({ embeds: [embed] });
209
+ }
210
+
211
+ if (a.customId == `${interaction.id}-two`) {
212
+ embed = embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
213
+ a.update({ embeds: [embed] });
214
+ }
215
+
216
+ if (a.customId == `${interaction.id}-three`) {
217
+ a.update({ components: [] });
218
+ collector.stop();
219
+ }
220
+
221
+ if (a.customId == `${interaction.id}-four`) {
222
+ embed = embeds[embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1];
223
+ a.update({ embeds: [embed] });
224
+ }
225
+
226
+ if (a.customId == `${interaction.id}-five`) {
227
+ embed = embeds[embeds.length - 1];
228
+ a.update({ embeds: [embed] });
229
+ }
230
+ })
231
+
232
+ .on('end', async () => {
233
+ if (interaction.editReply) interaction.editReply({ components: [] });
234
+
235
+ if (interaction.edit) await m.edit({ components: [] });
236
+ })
237
+ })();
238
+ }
239
+
240
+ uptime(interaction, timestamp) {
241
+ if (!timestamp) timestamp = interaction.client.uptime;
242
+ let totalSeconds = timestamp / 1000;
243
+ let years = Math.floor(totalSeconds / 31536000);
244
+ totalSeconds %= 31536000;
245
+ let days = Math.floor(totalSeconds / 86400);
246
+ totalSeconds %= 86400;
247
+ let hours = Math.floor(totalSeconds / 3600);
248
+ totalSeconds %= 3600;
249
+ let minutes = Math.floor(totalSeconds / 60);
250
+ let seconds = Math.floor(totalSeconds % 60);
251
+
252
+ if (years >= 1) return `${years}y ${days}d ${hours}h ${minutes}m`
253
+ else if (days >= 1) return `${days}d ${hours}h ${minutes}m`;
254
+ else if (hours >= 1) return `${hours}h ${minutes}m`;
255
+ else if (minutes >= 1) return `${minutes}m ${seconds}s`;
256
+ else return `${seconds}s`;
257
+ }
258
+ }
@@ -0,0 +1,96 @@
1
+ const { selectMenuPaginator, buttonPaginator, commandName, uptime, reply } = require('./Functions.js');
2
+
3
+ module.exports = new class Util {
4
+ async messageUtil(message, type) {
5
+ setTimeout(() => {
6
+ if (message.client.messages[message.id] === null || message.client.messages[message.id]) delete message.client.messages[message.id];
7
+
8
+ if (message.channel.messages.cache.has(message.id)) message.channel.messages.cache.delete(message.id);
9
+ }, message.client.settings.cacheTime);
10
+
11
+ message.util = {
12
+ selectMenuPaginator: (embeds, options) => selectMenuPaginator(message, embeds, options),
13
+ buttonPaginator: (embeds, options) => buttonPaginator(message, embeds, options),
14
+ commandName: (command) => commandName(message, command),
15
+ uptime: (timestamp) => uptime(message, timestamp)
16
+ }
17
+
18
+ if (type == "create") {
19
+ message.client.messages[message.id] = null;
20
+
21
+ message.util.send = async (e) => {
22
+ const msg = await message.channel.send(e);
23
+
24
+ message.client.messages[message.id] = msg.id;
25
+
26
+ return msg;
27
+ }
28
+
29
+ message.util.reply = async (e) => {
30
+ const msg = await message.reply(e);
31
+
32
+ message.client.messages[message.id] = msg.id;
33
+
34
+ return msg;
35
+ }
36
+
37
+ return;
38
+ }
39
+
40
+ if (type == 'edit') {
41
+ if (message.client.messages[message.id] === null) {
42
+ message.util.send = async (e) => {
43
+ const msg = await message.channel.send(e);
44
+
45
+ message.client.messages[message.id] = msg.id;
46
+
47
+ return msg;
48
+ }
49
+
50
+ message.util.reply = async (e) => {
51
+ const msg = await message.reply(e);
52
+
53
+ message.client.messages[message.id] = msg.id;
54
+
55
+ return msg;
56
+ }
57
+
58
+ return;
59
+ }
60
+
61
+ else if (message.client.messages[message.id] !== null) {
62
+ const msg = await message.channel.messages.fetch(message.client.messages[message.id]);
63
+
64
+ message.util.send = async (e) => {
65
+ try {
66
+ return await msg.edit(e);
67
+ }
68
+ catch {
69
+ message.channel.send(e);
70
+ }
71
+ }
72
+
73
+ message.util.reply = async (e) => {
74
+ try {
75
+ return await msg.edit(e);
76
+ }
77
+ catch {
78
+ message.reply(e);
79
+ }
80
+ }
81
+
82
+ return;
83
+ }
84
+ }
85
+ }
86
+
87
+ interactionUtil(interaction) {
88
+ interaction.util = {
89
+ reply: (text) => reply(interaction, text),
90
+ selectMenuPaginator: (embeds, options) => selectMenuPaginator(interaction, embeds, options),
91
+ buttonPaginator: (embeds, options) => buttonPaginator(interaction, embeds, options),
92
+ commandName: (command) => commandName(interaction, command),
93
+ uptime: (timestamp) => uptime(interaction, timestamp)
94
+ }
95
+ }
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xernerx",
3
- "version": "2.4.3",
3
+ "version": "2.5.0",
4
4
  "description": "A bot framework for discord.js. [BETA]",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -1,44 +0,0 @@
1
- const colors = require('./colors.json');
2
-
3
- /**
4
- * @param {object} Functions - Build in functions of the bot hidden away in the handlers/setters.
5
- */
6
- class Functions {
7
- /**
8
- *
9
- * @param {object} client - Client object.
10
- * @param {object} options - Client options.
11
- * @returns an object of default colors and custom colors to be imported anywhere without having to import them.
12
- */
13
- color({ client: client, options: options }) {
14
- client.color = { FLAGS: colors }
15
-
16
- if (options.color) {
17
- for (const [name, color] of Object.entries(options.color)) {
18
- client.color[name] = color;
19
- }
20
- }
21
-
22
- return client.color;
23
- }
24
-
25
- /**
26
- *
27
- * @param {object} client - Client object.
28
- * @param {object} options - Client options.
29
- * @returns custom config settings for the bot.
30
- */
31
- config({ client: client, options: options }) {
32
- client.config = {}
33
-
34
- if (options.config) {
35
- for (const [key, value] of Object.entries(options.config)) {
36
- client.config[key] = value;
37
- }
38
- }
39
-
40
- return client.config;
41
- }
42
- }
43
-
44
- module.exports = new Functions();
@@ -1,318 +0,0 @@
1
- const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder, Embed, ButtonBuilder, ButtonStyle } = require('discord.js');
2
- const opts = require('./options.json');
3
-
4
- function reply(interaction, text) {
5
- return (interaction.replied || interaction.deferred) ? interaction.editReply(text) : interaction.reply(text);
6
- }
7
-
8
- function selectMenuPaginator(interaction, embeds, options = {}) {
9
- if (!embeds) return interaction.client.emit('error', interaction, "no embeds");
10
-
11
- if (!Array.isArray(embeds)) return interaction.client.emit('error', interaction, "no array of embeds")
12
-
13
- if (!options.index) {
14
- options.index = new EmbedBuilder()
15
- .setTitle(`${embeds.length} pages`)
16
-
17
- embeds.map((embed, i = 0) => options.index.addFields([{ name: embed?.data?.title || embed?.data?.author?.name || "No name", value: embed?.data?.description || `Page ${i + 1}` }]))
18
- }
19
-
20
- if (!options.row) {
21
- options.row = new ActionRowBuilder();
22
-
23
- if (!options.id) options.id = `${interaction.id}-menu`;
24
-
25
- options.comp = new SelectMenuBuilder()
26
- .setCustomId(options.id)
27
- .setMaxValues(1)
28
- .setMinValues(1)
29
- .setPlaceholder('Select a page.')
30
- .addOptions({ label: 'Index', description: 'Index Page', value: 'index' })
31
-
32
- embeds.map((embed, i = 0) => options.comp.addOptions({ label: embed?.data?.title || embed?.data?.author?.name, description: embed?.data?.description?.slice(0, 100) || `Page ${i + 1}`, value: opts[embeds.indexOf(embed)] }))
33
-
34
- options.row.addComponents(options.comp);
35
- }
36
-
37
- if (!options.id) options.id = options.row.components[0].data.custom_id;
38
-
39
- (async () => {
40
- let embed = options.index;
41
-
42
- let m = options.send ? await interaction.channel.send({ embeds: [embed], components: [options.row] }) : await reply(interaction, { embeds: [embed], components: [options.row] })
43
-
44
- interaction.channel.createMessageComponentCollector({ filter: options.filter, time: options.time || 300000 })
45
-
46
- .on('collect', async (a) => {
47
- if (a.customId != options.id) return;
48
-
49
- let chosen = a.values[0];
50
-
51
- if (chosen === options.row.components[0]?.options[0]?.data?.value) embed = options.index;
52
-
53
- else embed = embeds[opts.indexOf(chosen)];
54
-
55
- a.update({ embeds: [embed] });
56
- })
57
-
58
- .on('end', async () => {
59
- if (interaction.editReply) interaction.editReply({ components: [] });
60
-
61
- if (interaction.edit) await m.edit({ components: [] });
62
- })
63
- })();
64
- }
65
-
66
- function commandName(interaction, cmd) {
67
- if (cmd) {
68
- cmds = [];
69
-
70
- for (const commands of Object.values(interaction.client.commands)) {
71
- let commandInfo = {};
72
-
73
- if (commands.has(cmd)) {
74
- const command = commands.get(cmd);
75
-
76
- if (command?.data?.options?.length > 0) {
77
- command?.data?.options?.map(option => {
78
- if (!option?.type) {
79
- if (option?.options?.length > 0) {
80
- option?.options?.map(opt => {
81
- if (!opt.type) {
82
- commandInfo = {
83
- name: command?.data?.name + " " + option?.name + " " + opt?.name,
84
- description: opt.description,
85
- category: command.category
86
- }
87
- }
88
-
89
- else {
90
- commandInfo = {
91
- name: command?.data?.name + " " + option?.name,
92
- description: option?.description,
93
- category: command.category
94
- }
95
- }
96
- })
97
- }
98
-
99
- else {
100
- commandInfo = {
101
- name: command?.data?.name + " " + option?.name,
102
- description: option?.description,
103
- category: command.category
104
- }
105
- }
106
- }
107
-
108
- else {
109
- commandInfo = {
110
- name: command?.data?.name || command?.id,
111
- description: command?.data?.description || command?.description,
112
- category: command.category
113
- }
114
- }
115
- })
116
- }
117
-
118
- else {
119
- commandInfo.name = command?.data?.name || command?.id;
120
-
121
- commandInfo.description = command?.data?.description || command?.description;
122
- }
123
-
124
- cmds.push(commandInfo);
125
- }
126
-
127
- }
128
- return cmds;
129
- }
130
-
131
- if (!cmd) return [interaction?.commandName || interaction.content?.replace(interaction.client.settings.prefix.find(p => interaction.content.startsWith(p)), "").split(/ +/)[0], interaction?.options?._group, interaction?.options?._subcommand].join(' ').replace(/ +/g, " ").trim();
132
- }
133
-
134
- function buttonPaginator(interaction, embeds, options = {}) {
135
- if (!options.buttons) options.buttons = ["⏪", "◀️", "⏹️", "▶️", "⏩"];
136
-
137
- if (options.buttons.length <= 4 || options.buttons.length > 5) throw new Error('Must specify 5 emotes.');
138
-
139
- options.row = new ActionRowBuilder();
140
-
141
- for (const button of options.buttons) {
142
- options.row
143
- .addComponents(
144
- new ButtonBuilder()
145
- .setCustomId(`${interaction.id}-${opts[options.buttons.indexOf(button)]}`)
146
- .setStyle(ButtonStyle[options.style || 'Primary'])
147
- .setEmoji(button)
148
- )
149
- };
150
-
151
- (async () => {
152
- let embed = embeds[options.index || 0];
153
-
154
- let m = options.send ? await interaction.channel.send({ embeds: [embed], components: [options.row] }) : await reply(interaction, { embeds: [embed], components: [options.row] });
155
-
156
- interaction.channel.createMessageComponentCollector({ filter: options.filter, time: options.time || 300000 })
157
-
158
- .on('collect', async (a) => {
159
- if (a.customId == `${interaction.id}-one`) {
160
- embed = embeds[0];
161
- a.update({ embeds: [embed] });
162
- }
163
-
164
- if (a.customId == `${interaction.id}-two`) {
165
- embed = embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
166
- a.update({ embeds: [embed] });
167
- }
168
-
169
- if (a.customId == `${interaction.id}-three`) {
170
- a.update({ components: [] });
171
- }
172
-
173
- if (a.customId == `${interaction.id}-four`) {
174
- embed = embeds[embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1];
175
- a.update({ embeds: [embed] });
176
- }
177
-
178
- if (a.customId == `${interaction.id}-five`) {
179
- embed = embeds[embeds.length - 1];
180
- a.update({ embeds: [embed] });
181
- }
182
- })
183
-
184
- .on('end', async () => {
185
- if (interaction.editReply) interaction.editReply({ components: [] });
186
-
187
- if (interaction.edit) await m.edit({ components: [] });
188
- })
189
- })();
190
- }
191
-
192
- function uptime(interaction, timestamp) {
193
- if (!timestamp) timestamp = interaction.client.uptime;
194
- let totalSeconds = timestamp / 1000;
195
- let years = Math.floor(totalSeconds / 31536000);
196
- totalSeconds %= 31536000;
197
- let days = Math.floor(totalSeconds / 86400);
198
- totalSeconds %= 86400;
199
- let hours = Math.floor(totalSeconds / 3600);
200
- totalSeconds %= 3600;
201
- let minutes = Math.floor(totalSeconds / 60);
202
- let seconds = Math.floor(totalSeconds % 60);
203
-
204
- if (years >= 1) return `${years}y ${days}d ${hours}h ${minutes}m`
205
- else if (days >= 1) return `${days}d ${hours}h ${minutes}m`;
206
- else if (hours >= 1) return `${hours}h ${minutes}m`;
207
- else if (minutes >= 1) return `${minutes}m ${seconds}s`;
208
- else return `${seconds}s`;
209
- }
210
-
211
- class Util {
212
- async messageUtil(message, type) {
213
- setTimeout(() => {
214
- if (message.client.messages[message.id] === null || message.client.messages[message.id]) delete message.client.messages[message.id];
215
-
216
- if (message.channel.messages.cache.has(message.id)) message.channel.messages.cache.delete(message.id);
217
- }, message.client.settings.cacheTime);
218
-
219
- message.util = {};
220
-
221
- message.util.selectMenuPaginator = (embeds, options) => selectMenuPaginator(message, embeds, options);
222
-
223
- message.util.buttonPaginator = (embeds, options) => buttonPaginator(message, embeds, options);
224
-
225
- message.util.commandName = (command) => commandName(message, command);
226
-
227
- message.util.uptime = (timestamp) => uptime(message, timestamp);
228
-
229
- if (type == "create") {
230
- message.client.messages[message.id] = null;
231
-
232
- message.util.send = async (e) => {
233
- const msg = await message.channel.send(e);
234
-
235
- message.client.messages[message.id] = msg.id;
236
-
237
- return msg;
238
- }
239
-
240
- message.util.reply = async (e) => {
241
- const msg = await message.reply(e);
242
-
243
- message.client.messages[message.id] = msg.id;
244
-
245
- return msg;
246
- }
247
-
248
- return;
249
- }
250
-
251
- if (type == 'edit') {
252
- if (message.client.messages[message.id] === null) {
253
- message.util.send = async (e) => {
254
- const msg = await message.channel.send(e);
255
-
256
- message.client.messages[message.id] = msg.id;
257
-
258
- return msg;
259
- }
260
-
261
- message.util.reply = async (e) => {
262
- const msg = await message.reply(e);
263
-
264
- message.client.messages[message.id] = msg.id;
265
-
266
- return msg;
267
- }
268
-
269
- return;
270
- }
271
-
272
- else if (message.client.messages[message.id] !== null) {
273
- const msg = await message.channel.messages.fetch(message.client.messages[message.id]);
274
-
275
- message.util.send = async (e) => {
276
- try {
277
- return await msg.edit(e);
278
- }
279
- catch {
280
- message.channel.send(e);
281
- }
282
- }
283
-
284
- message.util.reply = async (e) => {
285
- try {
286
- return await msg.edit(e);
287
- }
288
- catch {
289
- message.reply(e);
290
- }
291
- }
292
-
293
- return;
294
- }
295
- }
296
- }
297
-
298
- interactionUtil(interaction) {
299
- interaction.util = {}
300
-
301
- interaction.util.reply = (text) => reply(interaction, text);
302
-
303
- interaction.util.selectMenuPaginator = (embeds, options) => selectMenuPaginator(interaction, embeds, options);
304
-
305
- interaction.util.buttonPaginator = (embeds, options) => buttonPaginator(interaction, embeds, options);
306
-
307
- interaction.util.commandName = (command) => commandName(interaction, command);
308
-
309
- interaction.util.uptime = (timestamp) => uptime(interaction, timestamp);
310
- }
311
- }
312
-
313
- u = new Util;
314
-
315
- module.exports = {
316
- messageUtil: u.messageUtil,
317
- interactionUtil: u.interactionUtil
318
- };