djs-builder 0.5.42 → 0.6.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.
Files changed (156) hide show
  1. package/README.md +161 -339
  2. package/function/function.js +236 -0
  3. package/function/log.js +736 -0
  4. package/handler/helper.js +277 -0
  5. package/handler/starter.js +335 -0
  6. package/package.json +10 -42
  7. package/.tsbuildinfo +0 -1
  8. package/dist/discord/builder/components/Buttons.d.ts +0 -22
  9. package/dist/discord/builder/components/Buttons.d.ts.map +0 -1
  10. package/dist/discord/builder/components/Buttons.js +0 -91
  11. package/dist/discord/builder/components/Buttons.js.map +0 -1
  12. package/dist/discord/builder/components/Menus.d.ts +0 -31
  13. package/dist/discord/builder/components/Menus.d.ts.map +0 -1
  14. package/dist/discord/builder/components/Menus.js +0 -82
  15. package/dist/discord/builder/components/Menus.js.map +0 -1
  16. package/dist/discord/builder/permissions/perms.d.ts +0 -6
  17. package/dist/discord/builder/permissions/perms.d.ts.map +0 -1
  18. package/dist/discord/builder/permissions/perms.js +0 -66
  19. package/dist/discord/builder/permissions/perms.js.map +0 -1
  20. package/dist/discord/builder/system/Pagination.d.ts +0 -68
  21. package/dist/discord/builder/system/Pagination.d.ts.map +0 -1
  22. package/dist/discord/builder/system/Pagination.js +0 -256
  23. package/dist/discord/builder/system/Pagination.js.map +0 -1
  24. package/dist/discord/builder/system/collectors.d.ts +0 -27
  25. package/dist/discord/builder/system/collectors.d.ts.map +0 -1
  26. package/dist/discord/builder/system/collectors.js +0 -137
  27. package/dist/discord/builder/system/collectors.js.map +0 -1
  28. package/dist/discord/builder/utils.d.ts +0 -5
  29. package/dist/discord/builder/utils.d.ts.map +0 -1
  30. package/dist/discord/builder/utils.js +0 -10
  31. package/dist/discord/builder/utils.js.map +0 -1
  32. package/dist/discord/events-handler/eventLoader.d.ts +0 -13
  33. package/dist/discord/events-handler/eventLoader.d.ts.map +0 -1
  34. package/dist/discord/events-handler/eventLoader.js +0 -169
  35. package/dist/discord/events-handler/eventLoader.js.map +0 -1
  36. package/dist/discord/events-handler/events.d.ts +0 -8
  37. package/dist/discord/events-handler/events.d.ts.map +0 -1
  38. package/dist/discord/events-handler/events.js +0 -186
  39. package/dist/discord/events-handler/events.js.map +0 -1
  40. package/dist/discord/events-handler/login.d.ts +0 -9
  41. package/dist/discord/events-handler/login.d.ts.map +0 -1
  42. package/dist/discord/events-handler/login.js +0 -273
  43. package/dist/discord/events-handler/login.js.map +0 -1
  44. package/dist/discord/events-handler/prefix-register.d.ts +0 -23
  45. package/dist/discord/events-handler/prefix-register.d.ts.map +0 -1
  46. package/dist/discord/events-handler/prefix-register.js +0 -109
  47. package/dist/discord/events-handler/prefix-register.js.map +0 -1
  48. package/dist/discord/events-handler/prefix-responder.d.ts +0 -5
  49. package/dist/discord/events-handler/prefix-responder.d.ts.map +0 -1
  50. package/dist/discord/events-handler/prefix-responder.js +0 -155
  51. package/dist/discord/events-handler/prefix-responder.js.map +0 -1
  52. package/dist/discord/events-handler/prefixLoader.d.ts +0 -7
  53. package/dist/discord/events-handler/prefixLoader.d.ts.map +0 -1
  54. package/dist/discord/events-handler/prefixLoader.js +0 -74
  55. package/dist/discord/events-handler/prefixLoader.js.map +0 -1
  56. package/dist/discord/events-handler/slash-register.d.ts +0 -4
  57. package/dist/discord/events-handler/slash-register.d.ts.map +0 -1
  58. package/dist/discord/events-handler/slash-register.js +0 -85
  59. package/dist/discord/events-handler/slash-register.js.map +0 -1
  60. package/dist/discord/events-handler/slash-responder.d.ts +0 -3
  61. package/dist/discord/events-handler/slash-responder.d.ts.map +0 -1
  62. package/dist/discord/events-handler/slash-responder.js +0 -112
  63. package/dist/discord/events-handler/slash-responder.js.map +0 -1
  64. package/dist/discord/events-handler/slashLoader.d.ts +0 -7
  65. package/dist/discord/events-handler/slashLoader.d.ts.map +0 -1
  66. package/dist/discord/events-handler/slashLoader.js +0 -94
  67. package/dist/discord/events-handler/slashLoader.js.map +0 -1
  68. package/dist/discord/events-handler/starter.d.ts +0 -6
  69. package/dist/discord/events-handler/starter.d.ts.map +0 -1
  70. package/dist/discord/events-handler/starter.js +0 -85
  71. package/dist/discord/events-handler/starter.js.map +0 -1
  72. package/dist/discord/functions/anticrash.d.ts +0 -3
  73. package/dist/discord/functions/anticrash.d.ts.map +0 -1
  74. package/dist/discord/functions/anticrash.js +0 -55
  75. package/dist/discord/functions/anticrash.js.map +0 -1
  76. package/dist/discord/functions/devLogs.d.ts +0 -2
  77. package/dist/discord/functions/devLogs.d.ts.map +0 -1
  78. package/dist/discord/functions/devLogs.js +0 -137
  79. package/dist/discord/functions/devLogs.js.map +0 -1
  80. package/dist/discord/functions/logger.d.ts +0 -5
  81. package/dist/discord/functions/logger.d.ts.map +0 -1
  82. package/dist/discord/functions/logger.js +0 -57
  83. package/dist/discord/functions/logger.js.map +0 -1
  84. package/dist/discord/functions/mongoDb.d.ts +0 -4
  85. package/dist/discord/functions/mongoDb.d.ts.map +0 -1
  86. package/dist/discord/functions/mongoDb.js +0 -39
  87. package/dist/discord/functions/mongoDb.js.map +0 -1
  88. package/dist/discord/functions/similarity.d.ts +0 -3
  89. package/dist/discord/functions/similarity.d.ts.map +0 -1
  90. package/dist/discord/functions/similarity.js +0 -56
  91. package/dist/discord/functions/similarity.js.map +0 -1
  92. package/dist/discord/functions/terminal.d.ts +0 -2
  93. package/dist/discord/functions/terminal.d.ts.map +0 -1
  94. package/dist/discord/functions/terminal.js +0 -127
  95. package/dist/discord/functions/terminal.js.map +0 -1
  96. package/dist/discord/functions/utils.d.ts +0 -5
  97. package/dist/discord/functions/utils.d.ts.map +0 -1
  98. package/dist/discord/functions/utils.js +0 -11
  99. package/dist/discord/functions/utils.js.map +0 -1
  100. package/dist/discord/functions/versedb.d.ts +0 -3
  101. package/dist/discord/functions/versedb.d.ts.map +0 -1
  102. package/dist/discord/functions/versedb.js +0 -21
  103. package/dist/discord/functions/versedb.js.map +0 -1
  104. package/dist/discord/games/X-O.d.ts +0 -20
  105. package/dist/discord/games/X-O.d.ts.map +0 -1
  106. package/dist/discord/games/X-O.js +0 -166
  107. package/dist/discord/games/X-O.js.map +0 -1
  108. package/dist/discord/games/rps.d.ts +0 -21
  109. package/dist/discord/games/rps.d.ts.map +0 -1
  110. package/dist/discord/games/rps.js +0 -99
  111. package/dist/discord/games/rps.js.map +0 -1
  112. package/dist/discord/types/starter.d.ts +0 -144
  113. package/dist/discord/types/starter.d.ts.map +0 -1
  114. package/dist/discord/types/starter.js +0 -3
  115. package/dist/discord/types/starter.js.map +0 -1
  116. package/dist/discord/types/utils.d.ts +0 -3
  117. package/dist/discord/types/utils.d.ts.map +0 -1
  118. package/dist/discord/types/utils.js +0 -3
  119. package/dist/discord/types/utils.js.map +0 -1
  120. package/dist/discord/utils.d.ts +0 -15
  121. package/dist/discord/utils.d.ts.map +0 -1
  122. package/dist/discord/utils.js +0 -41
  123. package/dist/discord/utils.js.map +0 -1
  124. package/dist/index.d.ts +0 -4
  125. package/dist/index.d.ts.map +0 -1
  126. package/dist/index.js +0 -71
  127. package/dist/index.js.map +0 -1
  128. package/lib/discord/builder/components/Buttons.ts +0 -123
  129. package/lib/discord/builder/components/Menus.ts +0 -106
  130. package/lib/discord/builder/permissions/perms.ts +0 -66
  131. package/lib/discord/builder/system/Pagination.ts +0 -374
  132. package/lib/discord/builder/system/collectors.ts +0 -197
  133. package/lib/discord/builder/utils.ts +0 -9
  134. package/lib/discord/events-handler/eventLoader.ts +0 -166
  135. package/lib/discord/events-handler/events.ts +0 -160
  136. package/lib/discord/events-handler/login.ts +0 -265
  137. package/lib/discord/events-handler/prefix-register.ts +0 -117
  138. package/lib/discord/events-handler/prefix-responder.ts +0 -176
  139. package/lib/discord/events-handler/prefixLoader.ts +0 -83
  140. package/lib/discord/events-handler/slash-register.ts +0 -81
  141. package/lib/discord/events-handler/slash-responder.ts +0 -136
  142. package/lib/discord/events-handler/slashLoader.ts +0 -104
  143. package/lib/discord/events-handler/starter.ts +0 -85
  144. package/lib/discord/functions/anticrash.ts +0 -60
  145. package/lib/discord/functions/devLogs.ts +0 -128
  146. package/lib/discord/functions/logger.ts +0 -58
  147. package/lib/discord/functions/mongoDb.ts +0 -38
  148. package/lib/discord/functions/similarity.ts +0 -70
  149. package/lib/discord/functions/terminal.ts +0 -162
  150. package/lib/discord/functions/utils.ts +0 -4
  151. package/lib/discord/functions/versedb.ts +0 -17
  152. package/lib/discord/types/starter.ts +0 -158
  153. package/lib/discord/types/utils.ts +0 -2
  154. package/lib/discord/utils.ts +0 -17
  155. package/lib/index.ts +0 -37
  156. package/tsconfig.json +0 -21
@@ -1,117 +0,0 @@
1
- import { Collection } from 'discord.js';
2
- import { promises as fsPromises } from 'fs';
3
- import { join, resolve } from 'path';
4
- import { Command } from '../types/utils';
5
- import { logError } from '../functions/logger';
6
-
7
- export const commands = new Collection<string, Command>();
8
- export const aliases = new Collection<string, string>();
9
- export const commandNames = new Set<string>();
10
-
11
- export async function readCommands(client: any, prefix: { path: string }): Promise<Array<{
12
- name: string;
13
- usage: string | undefined;
14
- description: string | undefined;
15
- aliases: string[] | undefined;
16
- cooldown: number | undefined;
17
- developer: boolean | undefined;
18
- owner: boolean | undefined;
19
- fastUse: boolean | undefined;
20
- botPerms: string[] | undefined;
21
- userPerms: string[] | undefined;
22
- category: string | undefined;
23
- accessLevel: string | undefined;
24
- method?: (...args: any[]) => void;
25
- }>> {
26
- const commandDetails: Array<{
27
- name: string;
28
- usage: string | undefined;
29
- description: string | undefined;
30
- aliases: string[] | undefined;
31
- cooldown: number | undefined;
32
- developer: boolean | undefined;
33
- owner: boolean | undefined;
34
- fastUse: boolean | undefined;
35
- botPerms: string[] | undefined;
36
- userPerms: string[] | undefined;
37
- category: string | undefined;
38
- accessLevel: string | undefined;
39
- method?: (...args: any[]) => void;
40
- }> = [];
41
-
42
- try {
43
- const resolvedPath = resolve(process.cwd(), prefix.path);
44
- await fsPromises.access(resolvedPath);
45
- const files = await fsPromises.readdir(resolvedPath, { withFileTypes: true });
46
-
47
- for (const file of files) {
48
- const filePath = join(resolvedPath, file.name);
49
-
50
- if (file.isDirectory()) {
51
- const subCommandDetails = await readCommands(client, { path: filePath });
52
- commandDetails.push(...subCommandDetails);
53
- } else if (file.isFile()) {
54
- try {
55
- const commandModule = await import(filePath);
56
- const command: Command = commandModule.default || commandModule;
57
-
58
- if (command && (command.execute || command.run)) {
59
- const method = command.execute ? command.execute : command.run
60
- const defaultCommand: Command = {
61
- description: "No description provided.",
62
- cooldown: undefined,
63
- usage: "No usage information provided.",
64
- aliases: [],
65
- developer: false,
66
- owner: false,
67
- fastUse: false,
68
- botPerms: [],
69
- userPerms: [],
70
- category: "Uncategorized",
71
- accessLevel: undefined,
72
- ...command,
73
- method
74
- };
75
-
76
- commands.set(defaultCommand.name, defaultCommand);
77
- commandNames.add(defaultCommand.name);
78
-
79
- if (defaultCommand.aliases && Array.isArray(defaultCommand.aliases)) {
80
- defaultCommand.aliases.forEach(alias => {
81
- aliases.set(alias, defaultCommand.name);
82
- commandNames.add(alias);
83
- });
84
- }
85
-
86
- commandDetails.push({
87
- name: defaultCommand.name,
88
- usage: defaultCommand.usage || 'No usage information provided.',
89
- description: defaultCommand.description || 'No description provided.',
90
- aliases: defaultCommand.aliases || [],
91
- cooldown: defaultCommand.cooldown,
92
- developer: defaultCommand.developer,
93
- owner: defaultCommand.owner,
94
- fastUse: defaultCommand.fastUse,
95
- botPerms: defaultCommand.botPerms,
96
- userPerms: defaultCommand.userPerms,
97
- category: defaultCommand.category || 'Uncategorized',
98
- accessLevel: defaultCommand.accessLevel,
99
- method
100
- });
101
- }
102
- } catch (error: any) {
103
- logError(`Error in file: ${filePath}`);
104
- logError(error.message, error);
105
- }
106
- }
107
- }
108
-
109
- client.prefixCommands = commandDetails;
110
- client.prefixSize = commandDetails.length;
111
- return commandDetails;
112
- } catch (error: any) {
113
- logError(`⚠️ Error reading directory: ${prefix.path}`);
114
- logError(error.message, error);
115
- return [];
116
- }
117
- }
@@ -1,176 +0,0 @@
1
- import { Client, Message, Collection, EmbedBuilder, TextChannel, PermissionResolvable } from 'discord.js';
2
- import { getSimilarCommands } from '../functions/utils';
3
- import { botData } from './login';
4
- import { logError } from '../functions/logger';
5
- import { PrefixOptions } from '../types/starter';
6
-
7
- const cooldowns: Collection<string, Collection<string, number>> = new Collection();
8
-
9
- export async function handleMessageCreate(message: Message, prefixOptions: PrefixOptions): Promise<void> {
10
- if (message.author.bot) return;
11
-
12
- let botPrefix = prefixOptions.prefix || '!';
13
- const developers = botData.get('developers') as string[] | undefined;
14
- const ownerId = botData.get('ownerId') as string;
15
-
16
- if (message.guild) {
17
- const customPrefixEntry = prefixOptions.customPrefix?.find(entry => entry.serverId === message.guild?.id);
18
- if (customPrefixEntry) {
19
- botPrefix = customPrefixEntry.prefix;
20
- }
21
- }
22
-
23
- let args = [];
24
- let commandName: string | undefined;
25
-
26
- if (message.content.startsWith(botPrefix)) {
27
- args = message.content.slice(botPrefix.length).trim().split(/ +/);
28
- commandName = args.shift()?.toLowerCase();
29
- } else {
30
- commandName = message.content.split(/ +/)[0].toLowerCase();
31
- args = message.content.split(/ +/).slice(1);
32
- }
33
-
34
- if (!commandName) return;
35
-
36
- const command = (message.client as any).prefixCommands.find((cmd: any) => cmd.name === commandName)
37
- || (message.client as any).prefixCommands.find((cmd: any) => cmd.aliases.includes(commandName));
38
-
39
- if (!command) {
40
- if (message.content.startsWith(botPrefix) && prefixOptions.similarity) {
41
- const similarCommands = getSimilarCommands(commandName, (message.client as any).prefixCommands);
42
- if (similarCommands.length > 0) {
43
- await message.reply(`Command not found. Did you mean: ${similarCommands.join(', ')}?`);
44
- } else {
45
- await message.reply(`Command '${commandName}' doesn't exist.`);
46
- }
47
- }
48
- return;
49
- }
50
-
51
-
52
- if (command.owner && message.author.id !== ownerId) {
53
- await message.reply(`Only the bot owner can use this command.`);
54
- return;
55
- }
56
-
57
- if (command.developer && (!developers || !developers.includes(message.author.id)) && message.author.id !== ownerId) {
58
- await message.reply("You are not authorized to use this command.");
59
- return;
60
- }
61
-
62
- if (message.guild) {
63
- if (command.botPerms && command.botPerms.length > 0) {
64
- const missingBotPerms = command.botPerms.filter((perm: any) => !message.guild?.members.me?.permissions.has(perm as PermissionResolvable));
65
- if (missingBotPerms.length > 0) {
66
- await message.reply(`I'm missing the following permissions to execute this command: ${missingBotPerms.join(', ')}`);
67
- return;
68
- }
69
- }
70
-
71
- if (command.userPerms && command.userPerms.length > 0) {
72
- const member = message.guild.members.cache.get(message.author.id);
73
- if (member) {
74
- const missingUserPerms = command.userPerms.filter((perm: any) => !member.permissions.has(perm as PermissionResolvable));
75
- if (missingUserPerms.length > 0) {
76
- await message.reply(`You are missing the following permissions to use this command: ${missingUserPerms.join(', ')}`);
77
- return;
78
- }
79
- }
80
- }
81
-
82
- if (command.accessLevel) {
83
- const member = message.guild.members.cache.get(message.author.id);
84
- if (member) {
85
- const accessRole = message.guild.roles.cache.get(command.accessLevel);
86
- if (!accessRole) {
87
- await message.reply("The required role does not exist in this server.");
88
- return;
89
- }
90
-
91
- const hasRequiredRole = member.roles.cache.some(role => role.id === command.accessLevel || role.position > accessRole.position);
92
- if (!hasRequiredRole) {
93
- await message.reply("You do not have the required role or a role higher than it to use this command.");
94
- return;
95
- }
96
- }
97
- }
98
- }
99
-
100
- // Handle cooldowns
101
- const now = Date.now();
102
- const timestamps = cooldowns.get(command.name) || new Collection<string, number>();
103
- const cooldownAmount = (command.cooldown || 3) * 1000;
104
-
105
- if (timestamps.has(message.author.id)) {
106
- const expirationTime = timestamps.get(message.author.id) || 0;
107
- const timeLeft = (expirationTime - now) / 1000;
108
-
109
- if (now < expirationTime) {
110
- await message.reply(`Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
111
- return;
112
- }
113
- }
114
-
115
- timestamps.set(message.author.id, now);
116
- setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
117
- cooldowns.set(command.name, timestamps);
118
-
119
- try {
120
- if (command && command.fastUse && !message.content.startsWith(botPrefix)) {
121
- if (command.method) {
122
- command.method(message.client, message, args);
123
- } else {
124
- logError(`Error executing command ${command.name}`);
125
- }
126
- }
127
- else {
128
- if (command && command.method) {
129
- command.method(message.client, message, args);
130
- } else {
131
- logError(`Error executing command ${command.name}`);
132
- }
133
- }
134
- if (message.guild && prefixOptions.logsId && commandName) {
135
- const channel = message.guild.channels.cache.get(prefixOptions.logsId) as TextChannel;
136
- if (channel) {
137
- const userName = message.author.username;
138
- const userId = message.author.id;
139
- const serverName = message.guild.name || null;
140
- const serverId = message.guild.id || null;
141
- const messageLink = `https://discord.com/channels/${serverId}/${message.channel.id}/${message.id}`;
142
-
143
- const embedLog = new EmbedBuilder()
144
- .setColor("Blue")
145
- .setThumbnail(message.client.user?.displayAvatarURL())
146
- .setTitle("Use Prefix Command")
147
- .setTimestamp()
148
- .addFields(
149
- { name: "📧 Cmd:", value: `- ${commandName}`, inline: true },
150
- { name: "🤪 User:", value: `- ${userName} (<@${userId}>)`, inline: true },
151
- { name: "\u200B", value: "\u200B", inline: true },
152
- { name: "🏠 Server:", value: `- ${serverName}.\n- [\`${serverId}\`].`, inline: true },
153
- { name: "📩 Message:", value: `- [Link](${messageLink})`, inline: true },
154
- { name: "\u200B", value: "\u200B", inline: true },
155
- { name: "⏳ Date:", value: `- <t:${Math.floor(Date.now() / 1000)}:R>`, inline: true }
156
- );
157
-
158
- await channel.send({ embeds: [embedLog] });
159
- }
160
- }
161
- } catch (error: any) {
162
- logError(`Error executing command ${command.name}`, error);
163
- }
164
- }
165
-
166
- export async function loadPrefix(client: Client, prefix: PrefixOptions): Promise<void> {
167
- if (!prefix.prefix) {
168
- throw new Error("⚠️ No command prefix provided. Please provide a command prefix.");
169
- }
170
-
171
- try {
172
- client.on("messageCreate", async (message) => await handleMessageCreate(message, prefix));
173
- } catch (error: any) {
174
- logError("An error occurred while loading prefix.", error);
175
- }
176
- }
@@ -1,83 +0,0 @@
1
- import { Client, Collection } from 'discord.js';
2
- import { readdir } from 'fs/promises';
3
- import { join, resolve, extname } from 'path';
4
- import { commands, aliases, commandNames } from './prefix-register';
5
- import { readCommands } from './prefix-register';
6
- import { logError, logInfo } from '../functions/logger';
7
- import { botData } from './login';
8
- import { watch } from 'fs';
9
- const validExtensions = ['.js', '.ts'];
10
-
11
- export async function prefixLoader(client: any): Promise<{ commands: Collection<string, any>; success: boolean }> {
12
- try {
13
-
14
- const prefixPath = botData.get('prefixPath') as string;
15
-
16
- commands.clear();
17
- aliases.clear();
18
- commandNames.clear();
19
- client.prefixCommands = [];
20
- client.prefixSize = 0;
21
-
22
- const resolvedPath = resolve(process.cwd(), prefixPath);
23
- const dirents = await readdir(resolvedPath, { withFileTypes: true });
24
-
25
- const filePaths: string[] = [];
26
- for (const dirent of dirents) {
27
- if (dirent.isDirectory()) {
28
- const folderPath = join(resolvedPath, dirent.name);
29
- const files = await readdir(folderPath);
30
- for (const file of files) {
31
- if (validExtensions.includes(extname(file))) {
32
- filePaths.push(join(folderPath, file));
33
- }
34
- }
35
- } else if (validExtensions.includes(extname(dirent.name))) {
36
- filePaths.push(join(resolvedPath, dirent.name));
37
- }
38
- }
39
-
40
- for (const filePath of filePaths) {
41
- delete require.cache[require.resolve(filePath)];
42
- }
43
-
44
- const commandDetails = await readCommands(client, { path: prefixPath });
45
- client.prefixCommands = commandDetails;
46
- client.prefixSize = commandDetails.length;
47
-
48
- return { commands: commands, success: true };
49
- } catch (error: any) {
50
- logError('Error reloading commands:');
51
- logError(error.message, error);
52
-
53
- return { commands: new Collection(), success: false };
54
- }
55
- }
56
-
57
-
58
- export function autoPrefixLoader(client: Client, DEBOUNCE_DELAY: number = 10000) {
59
-
60
- const slashPath = botData.get('slashCommandPath') as string;
61
- const commandPath = resolve(process.cwd(), slashPath);
62
-
63
- let debounceTimer: NodeJS.Timeout | null = null;
64
-
65
- const handleReload = async () => {
66
- if (debounceTimer) {
67
- clearTimeout(debounceTimer);
68
- }
69
- debounceTimer = setTimeout(async () => {
70
- await prefixLoader(client);
71
- logInfo('Slash commands successfully reloaded after debounce.');
72
- }, DEBOUNCE_DELAY);
73
- };
74
-
75
- watch(commandPath, { recursive: false }, (eventType: any, filename: any) => {
76
- if (filename && validExtensions.includes(extname(filename))) {
77
- logInfo(`Detected ${eventType} in ${filename}, waiting for debouncing...`);
78
- handleReload();
79
- }
80
- });
81
-
82
- logInfo('Started watching for changes in slash commands...');
83
- }
@@ -1,81 +0,0 @@
1
- import { Collection, Guild } from 'discord.js';
2
- import { REST } from '@discordjs/rest';
3
- import { Routes } from 'discord-api-types/v10';
4
- import { readdir } from 'fs/promises';
5
- import path from 'path';
6
- import { SlashOptions } from '../types/starter';
7
- import { logError } from '../functions/logger';
8
-
9
- async function loadCommand(filePath: string) {
10
- try {
11
- const command = require(filePath);
12
- if (command.data) {
13
- command.data.cooldown = command.cooldown && !isNaN(command.cooldown) ? command.cooldown : 0;
14
- command.data.botPerms = command.botPerms || [];
15
- command.data.userPerms = command.userPerms || [];
16
- command.data.owner = command.owner || false;
17
- command.data.developer = command.developer || false;
18
- command.data.category = command.category || 'Uncategorized';
19
- return command;
20
- }
21
- } catch (error: any) {
22
- logError(`Error loading command from file: ${filePath}`);
23
- logError(error.message);
24
- }
25
- return null;
26
- }
27
-
28
- export async function registerSlashCommands(client: any, token: string, slash: SlashOptions): Promise<Collection<string, any>> {
29
- if (!token) {
30
- throw new Error("⚠️ Please provide valid bot token to register slash commands.");
31
- }
32
-
33
- const slashCommands = new Collection<string, any>();
34
- const rest = new REST({ version: '10' }).setToken(token);
35
-
36
- try {
37
- const resolvedPath = path.join(process.cwd(), slash.path);
38
- const dirents = await readdir(resolvedPath, { withFileTypes: true });
39
-
40
- for (const dirent of dirents) {
41
- const folderPath = path.join(resolvedPath, dirent.name);
42
- if (dirent.isDirectory()) {
43
- const files = await readdir(folderPath);
44
- for (const file of files) {
45
- const command = await loadCommand(path.join(folderPath, file));
46
- if (command) {
47
- slashCommands.set(command.data.name, command);
48
- }
49
- }
50
- } else {
51
- const command = await loadCommand(path.join(resolvedPath, dirent.name));
52
- if (command) {
53
- slashCommands.set(command.data.name, command);
54
- }
55
- }
56
- }
57
-
58
- const slashCommandArray = Array.from(slashCommands.values()).map(command => command.data.toJSON());
59
-
60
- if (slash.global && !slash.serverId) {
61
- await rest.put(Routes.applicationCommands(client.user?.id || ''), { body: slashCommandArray });
62
- } else if (!slash.global && slash.serverId) {
63
- const guild = client.guilds.cache.get(slash.serverId) as Guild | undefined;
64
- if (guild) {
65
- await rest.put(Routes.applicationGuildCommands(client.user?.id || '', guild.id), { body: slashCommandArray });
66
- } else {
67
- logError(`Guild with ID ${slash.serverId} not found.`);
68
- }
69
- } else {
70
- await rest.put(Routes.applicationCommands(client.user?.id || ''), { body: slashCommandArray });
71
- }
72
- } catch (error: any) {
73
- logError('Error registering slash commands:');
74
- logError(error.message);
75
- console.error(error);
76
- }
77
-
78
- client.slashCommands = slashCommands;
79
- client.slashSize = slashCommands.size;
80
- return slashCommands;
81
- }
@@ -1,136 +0,0 @@
1
- import {
2
- Collection,
3
- Interaction,
4
- EmbedBuilder,
5
- Snowflake,
6
- PermissionResolvable,
7
- TextChannel
8
- } from 'discord.js';
9
- import { registerSlashCommands } from './slash-register';
10
- import { SlashOptions } from '../types/starter';
11
- import { logWarning, logError, logInfo } from '../functions/logger';
12
-
13
- export async function loadSlash(client: any, token: string, options: SlashOptions): Promise<void> {
14
- const slashCommands = await registerSlashCommands(client, token, options);
15
-
16
- if (!slashCommands || slashCommands.size === 0) {
17
- logWarning('No registered slash commands. SlashHandler won\'t work.');
18
- return;
19
- }
20
-
21
- const interactionCooldowns: Collection<Snowflake, Collection<string, number>> = new Collection();
22
-
23
- client.on('interactionCreate', async (interaction: Interaction) => {
24
- // Ensure we are handling the correct type of interaction
25
- if (!interaction.isCommand() && !interaction.isChatInputCommand() && !interaction.isContextMenuCommand()) {
26
- return;
27
- }
28
-
29
- const guild = interaction.guild; // Get the guild once for better readability
30
- const user = interaction.user;
31
-
32
- if (guild) {
33
- const botData = new Collection<string, string | string[]>();
34
- const permissionsArray = botData.get('permissions') as string[] | undefined;
35
-
36
- // Check if bot has permission to send messages
37
- if (!guild.members.me?.permissions.has('SendMessages')) {
38
- try {
39
- await user.send({ content: "I'm sorry, but I don't have permission to send messages in this server." });
40
- } catch (error) {
41
- return; // Ignore errors when sending the message
42
- }
43
- }
44
-
45
- // Check for missing permissions
46
- if (permissionsArray && permissionsArray.length > 0) {
47
- const missingPermissions = permissionsArray.filter(permission => !guild.members.me?.permissions.has(permission as PermissionResolvable));
48
-
49
- if (missingPermissions.length > 0) {
50
- try {
51
- await user.send({ content: `I'm sorry, but I don't have permission(s): ${missingPermissions.join(', ')} in this server.` });
52
- } catch (error) {
53
- return; // Ignore errors when sending the message
54
- }
55
- }
56
- }
57
- }
58
-
59
- const commandName = interaction.commandName;
60
- const command = slashCommands.get(commandName);
61
-
62
- if (!command) return;
63
-
64
- // Handle command cooldowns
65
- if (command.cooldown && !isNaN(command.cooldown)) {
66
- const userCooldowns = interactionCooldowns.get(interaction.user.id) || new Collection<string, number>();
67
- const cooldownExpiration = userCooldowns.get(command.data.name);
68
- if (cooldownExpiration && cooldownExpiration > Date.now()) {
69
- const remainingCooldown = (cooldownExpiration - Date.now()) / 1000;
70
- await interaction.reply(`Command is on cooldown. Please wait ${remainingCooldown.toFixed(1)} seconds.`);
71
- return;
72
- }
73
- userCooldowns.set(command.data.name, Date.now() + command.cooldown * 1000);
74
- interactionCooldowns.set(interaction.user.id, userCooldowns);
75
- }
76
-
77
- const startExecutionTime = Date.now();
78
-
79
- try {
80
- if (command.run) {
81
- await command.run.length === 2 ? command.run(interaction, client) : command.run(interaction);
82
- } else if (command.execute) {
83
- await command.execute.length === 2 ? command.execute(interaction, client) : command.execute(interaction);
84
- } else {
85
- logWarning(`Command "${command.data.name}" has neither run nor execute method.`);
86
- }
87
-
88
- // Logging command usage
89
- if (options.logsId && guild) {
90
- const channel = guild.channels.cache.get(options.logsId as string) as TextChannel;
91
- if (channel) {
92
- const userName = user.username;
93
- const userId = user.id;
94
- const serverName = guild.name || 'Unknown Server';
95
- const serverId = guild.id || 'Unknown ID';
96
- let messageLink = '';
97
-
98
- if (interaction.channel) {
99
- messageLink = `https://discord.com/channels/${serverId}/${interaction.channel.id}/${interaction.id}`;
100
- } else {
101
- messageLink = 'Unknown';
102
- }
103
-
104
- const embedLog = new EmbedBuilder()
105
- .setColor("Blue")
106
- .setThumbnail(interaction.client.user?.displayAvatarURL())
107
- .setTitle("Use Slash Command")
108
- .setTimestamp()
109
- .addFields(
110
- { name: "📧 Cmd:", value: `- ${command.data.name}`, inline: true },
111
- { name: "🤪 User:", value: `- ${userName} (<@${userId}>)`, inline: true },
112
- { name: "\u200B", value: "\u200B", inline: true },
113
- { name: "🏠 Server:", value: `- ${serverName}.\n- [\`${serverId}\`].`, inline: true },
114
- { name: "📩 Message:", value: `- [Link](${messageLink})`, inline: true },
115
- { name: "\u200B", value: "\u200B", inline: true },
116
- { name: "⏳ Date:", value: `- <t:${Math.floor(Date.now() / 1000)}:R>`, inline: true }
117
- );
118
-
119
- await channel.send({ embeds: [embedLog] });
120
- }
121
- }
122
-
123
- const executionTime = Date.now() - startExecutionTime;
124
- if (executionTime > 3000) {
125
- logInfo(`Command "${command.data.name}" took ${executionTime}ms to execute.`);
126
- }
127
- } catch (error: any) {
128
- logError(`Error executing command "${command.data.name}":`);
129
- logError(error.message);
130
- console.error(error);
131
- if (interaction.channel) {
132
- await interaction.channel.send({ content: 'An error occurred while executing the command.' });
133
- }
134
- }
135
- });
136
- }