djs-builder 0.5.0 → 0.5.2
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/.tsbuildinfo +1 -1
- package/dist/discord/events-handler/login.d.ts +2 -2
- package/dist/discord/events-handler/login.d.ts.map +1 -1
- package/dist/discord/events-handler/login.js +30 -20
- package/dist/discord/events-handler/login.js.map +1 -1
- package/dist/discord/events-handler/prefix-register.d.ts +5 -0
- package/dist/discord/events-handler/prefix-register.d.ts.map +1 -1
- package/dist/discord/events-handler/prefix-register.js +10 -0
- package/dist/discord/events-handler/prefix-register.js.map +1 -1
- package/dist/discord/events-handler/prefix-responder.d.ts.map +1 -1
- package/dist/discord/events-handler/prefix-responder.js +122 -61
- package/dist/discord/events-handler/prefix-responder.js.map +1 -1
- package/dist/discord/events-handler/prefixLoader.js +1 -1
- package/dist/discord/events-handler/prefixLoader.js.map +1 -1
- package/dist/discord/events-handler/slash-register.d.ts.map +1 -1
- package/dist/discord/events-handler/slash-register.js +10 -0
- package/dist/discord/events-handler/slash-register.js.map +1 -1
- package/dist/discord/events-handler/slash-responder.d.ts.map +1 -1
- package/dist/discord/events-handler/slash-responder.js +22 -20
- package/dist/discord/events-handler/slash-responder.js.map +1 -1
- package/dist/discord/events-handler/slashLoader.d.ts.map +1 -1
- package/dist/discord/events-handler/slashLoader.js +6 -2
- package/dist/discord/events-handler/slashLoader.js.map +1 -1
- package/dist/discord/functions/logger.d.ts.map +1 -1
- package/dist/discord/functions/logger.js +13 -1
- package/dist/discord/functions/logger.js.map +1 -1
- package/dist/discord/functions/similarity.d.ts.map +1 -1
- package/dist/discord/functions/similarity.js +11 -2
- package/dist/discord/functions/similarity.js.map +1 -1
- package/dist/discord/functions/terminal.d.ts +1 -2
- package/dist/discord/functions/terminal.d.ts.map +1 -1
- package/dist/discord/functions/terminal.js +19 -6
- package/dist/discord/functions/terminal.js.map +1 -1
- package/dist/discord/types/starter.d.ts +4 -1
- package/dist/discord/types/starter.d.ts.map +1 -1
- package/dist/discord/utils.d.ts +2 -1
- package/dist/discord/utils.d.ts.map +1 -1
- package/dist/discord/utils.js +6 -1
- package/dist/discord/utils.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/lib/discord/events-handler/login.ts +35 -17
- package/lib/discord/events-handler/prefix-register.ts +38 -2
- package/lib/discord/events-handler/prefix-responder.ts +146 -68
- package/lib/discord/events-handler/prefixLoader.ts +1 -1
- package/lib/discord/events-handler/slash-register.ts +14 -0
- package/lib/discord/events-handler/slash-responder.ts +33 -31
- package/lib/discord/events-handler/slashLoader.ts +7 -2
- package/lib/discord/functions/logger.ts +15 -6
- package/lib/discord/functions/similarity.ts +17 -5
- package/lib/discord/functions/terminal.ts +27 -14
- package/lib/discord/types/starter.ts +4 -1
- package/lib/discord/utils.ts +2 -1
- package/lib/index.ts +3 -3
- package/package.json +3 -1
|
@@ -4,6 +4,7 @@ import { PrefixOptions } from '../types/utils';
|
|
|
4
4
|
import { getSimilarCommands } from '../functions/utils';
|
|
5
5
|
import { botData } from './login';
|
|
6
6
|
import { logError } from '../functions/logger';
|
|
7
|
+
|
|
7
8
|
const cooldowns: Collection<string, Collection<string, number>> = new Collection();
|
|
8
9
|
|
|
9
10
|
export async function handleMessageCreate(message: Message, prefixOptions: PrefixOptions): Promise<void> {
|
|
@@ -17,88 +18,106 @@ export async function handleMessageCreate(message: Message, prefixOptions: Prefi
|
|
|
17
18
|
botPrefix = customPrefixEntry.prefix;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
if (message.guild && message.guild.members.me) {
|
|
21
23
|
const user = message.author;
|
|
22
|
-
const
|
|
23
|
-
const permissionsArray = botData.get('permissions') as string[] | undefined;
|
|
24
|
+
const botPermissions = message.guild.members.me.permissions;
|
|
24
25
|
|
|
25
|
-
if (!
|
|
26
|
+
if (!botPermissions.has('SendMessages')) {
|
|
26
27
|
try {
|
|
27
|
-
user.send(
|
|
28
|
+
await user.send("I'm sorry, but I don't have permission to send messages in this server.");
|
|
28
29
|
} catch (error: any) {
|
|
29
30
|
logError("Failed to send permission error message to user.", error);
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
const permissionsArray = botData.get('permissions') as string[] | undefined;
|
|
34
36
|
if (permissionsArray && permissionsArray.length > 0) {
|
|
35
|
-
const missingPermissions = permissionsArray.filter(permission => !
|
|
37
|
+
const missingPermissions = permissionsArray.filter(permission => !botPermissions.has(permission as PermissionResolvable));
|
|
36
38
|
|
|
37
39
|
if (missingPermissions.length > 0) {
|
|
38
40
|
try {
|
|
39
|
-
user.send(
|
|
41
|
+
await user.send(`I'm sorry, but I don't have permission(s): ${missingPermissions.join(', ')} in this server.`);
|
|
40
42
|
} catch (error: any) {
|
|
41
|
-
logError("Failed to send missing permissions message to user.", error);
|
|
43
|
+
logError("Failed to send missing permissions message to user.", error);
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
let args = [];
|
|
51
|
+
let commandName: string | undefined;
|
|
49
52
|
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
if (message.content.startsWith(botPrefix)) {
|
|
54
|
+
args = message.content.slice(botPrefix.length).trim().split(/ +/);
|
|
55
|
+
commandName = args.shift()?.toLowerCase();
|
|
53
56
|
} else {
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
commandName = message.content.split(/ +/)[0].toLowerCase();
|
|
58
|
+
args = message.content.split(/ +/).slice(1);
|
|
59
|
+
}
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
if (!commandName) return;
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
const command = commands.get(commandName) || commands.get(aliases.get(commandName) || '');
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return;
|
|
65
|
+
if (!command) {
|
|
66
|
+
const similarCommands = getSimilarCommands(commandName, commands);
|
|
67
|
+
if (similarCommands.length > 0) {
|
|
68
|
+
await message.reply(`Command not found. Did you mean: ${similarCommands.join(', ')}?`);
|
|
69
|
+
} else {
|
|
70
|
+
await message.reply(`Command '${commandName}' doesn't exist.`);
|
|
69
71
|
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (command.owner && message.author.id !== ownerId) {
|
|
76
|
+
await message.reply(`Only the bot owner can use this command.`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
70
79
|
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
if (command.developer) {
|
|
81
|
+
if (developers && !developers.includes(message.author.id)) {
|
|
82
|
+
if (message.author.id === ownerId) return;
|
|
83
|
+
await message.reply("You are not authorized to use this command.");
|
|
73
84
|
return;
|
|
74
85
|
}
|
|
86
|
+
}
|
|
75
87
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
if (message.guild) {
|
|
89
|
+
if (command.botPerms && command.botPerms.length > 0) {
|
|
90
|
+
const missingBotPerms = command.botPerms.filter(perm => !message.guild?.members.me?.permissions.has(perm as PermissionResolvable));
|
|
91
|
+
if (missingBotPerms.length > 0) {
|
|
92
|
+
await message.reply(`I'm missing the following permissions to execute this command: ${missingBotPerms.join(', ')}`);
|
|
80
93
|
return;
|
|
81
94
|
}
|
|
82
95
|
}
|
|
83
96
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (now < expirationTime) {
|
|
93
|
-
await message.reply(`Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
|
|
94
|
-
return;
|
|
97
|
+
if (command.userPerms && command.userPerms.length > 0) {
|
|
98
|
+
const member = message.guild.members.cache.get(message.author.id);
|
|
99
|
+
if (member) {
|
|
100
|
+
const missingUserPerms = command.userPerms.filter(perm => !member.permissions.has(perm as PermissionResolvable));
|
|
101
|
+
if (missingUserPerms.length > 0) {
|
|
102
|
+
await message.reply(`You are missing the following permissions to use this command: ${missingUserPerms.join(', ')}`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
108
|
+
if (command.accessLevel) {
|
|
109
|
+
const member = message.guild.members.cache.get(message.author.id);
|
|
110
|
+
if (member) {
|
|
111
|
+
const highestRole = member.roles.highest;
|
|
112
|
+
if (highestRole.id !== command.accessLevel) {
|
|
113
|
+
await message.reply("You do not have the required role to use this command.");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
101
119
|
|
|
120
|
+
if (command.fastUse && !message.content.startsWith(botPrefix)) {
|
|
102
121
|
try {
|
|
103
122
|
if (command.run) {
|
|
104
123
|
await command.run(message.client, message, args);
|
|
@@ -106,34 +125,93 @@ export async function handleMessageCreate(message: Message, prefixOptions: Prefi
|
|
|
106
125
|
await command.execute(message.client, message, args);
|
|
107
126
|
}
|
|
108
127
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
if (message.guild) {
|
|
129
|
+
const channel = message.guild.channels.cache.get(prefixOptions.logsId || '') as TextChannel | undefined;
|
|
130
|
+
const userName = message.author.username;
|
|
131
|
+
const userId = message.author.id;
|
|
132
|
+
const serverName = message.guild.name || null;
|
|
133
|
+
const serverId = message.guild.id || null;
|
|
134
|
+
const messageLink = `https://discord.com/channels/${serverId}/${message.channel.id}/${message.id}`;
|
|
135
|
+
|
|
136
|
+
const embedLog = new EmbedBuilder()
|
|
137
|
+
.setColor("Blue")
|
|
138
|
+
.setThumbnail(message.client.user?.displayAvatarURL())
|
|
139
|
+
.setTitle("Use Prefix Command")
|
|
140
|
+
.setTimestamp()
|
|
141
|
+
.addFields(
|
|
142
|
+
{ name: "📧 Cmd:", value: `- ${command.name}`, inline: true },
|
|
143
|
+
{ name: "🤪 User:", value: `- ${userName} (<@${userId}>)`, inline: true },
|
|
144
|
+
{ name: "\u200B", value: "\u200B", inline: true },
|
|
145
|
+
{ name: "🏠 Server:", value: `- ${serverName}.\n- [\`${serverId}\`].`, inline: true },
|
|
146
|
+
{ name: "📩 Message:", value: `- [Link](${messageLink})`, inline: true },
|
|
147
|
+
{ name: "\u200B", value: "\u200B", inline: true },
|
|
148
|
+
{ name: "⏳ Date:", value: `- <t:${Math.floor(Date.now() / 1000)}:R>`, inline: true }
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (prefixOptions.logsId && channel) {
|
|
152
|
+
await channel.send({ embeds: [embedLog] });
|
|
153
|
+
}
|
|
133
154
|
}
|
|
134
155
|
} catch (error: any) {
|
|
135
156
|
logError(`Error executing command ${command.name}`, error);
|
|
136
157
|
}
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const now = Date.now();
|
|
162
|
+
const timestamps = cooldowns.get(command.name) || new Collection<string, number>();
|
|
163
|
+
const cooldownAmount = (command.cooldown || 3) * 1000;
|
|
164
|
+
|
|
165
|
+
if (timestamps.has(message.author.id)) {
|
|
166
|
+
const expirationTime = timestamps.get(message.author.id) || 0;
|
|
167
|
+
const timeLeft = (expirationTime - now) / 1000;
|
|
168
|
+
|
|
169
|
+
if (now < expirationTime) {
|
|
170
|
+
await message.reply(`Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
timestamps.set(message.author.id, now);
|
|
176
|
+
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
|
|
177
|
+
cooldowns.set(command.name, timestamps);
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
if (command.run) {
|
|
181
|
+
await command.run(message.client, message, args);
|
|
182
|
+
} else if (command.execute) {
|
|
183
|
+
await command.execute(message.client, message, args);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (message.guild && prefixOptions.logsId) {
|
|
187
|
+
const channel = message.guild.channels.cache.get(prefixOptions.logsId as string) as TextChannel;
|
|
188
|
+
if (channel) {
|
|
189
|
+
const userName = message.author.username;
|
|
190
|
+
const userId = message.author.id;
|
|
191
|
+
const serverName = message.guild.name || null;
|
|
192
|
+
const serverId = message.guild.id || null;
|
|
193
|
+
const messageLink = `https://discord.com/channels/${serverId}/${message.channel.id}/${message.id}`;
|
|
194
|
+
|
|
195
|
+
const embedLog = new EmbedBuilder()
|
|
196
|
+
.setColor("Blue")
|
|
197
|
+
.setThumbnail(message.client.user?.displayAvatarURL())
|
|
198
|
+
.setTitle("Use Prefix Command")
|
|
199
|
+
.setTimestamp()
|
|
200
|
+
.addFields(
|
|
201
|
+
{ name: "📧 Cmd:", value: `- ${command.name}`, inline: true },
|
|
202
|
+
{ name: "🤪 User:", value: `- ${userName} (<@${userId}>)`, inline: true },
|
|
203
|
+
{ name: "\u200B", value: "\u200B", inline: true },
|
|
204
|
+
{ name: "🏠 Server:", value: `- ${serverName}.\n- [\`${serverId}\`].`, inline: true },
|
|
205
|
+
{ name: "📩 Message:", value: `- [Link](${messageLink})`, inline: true },
|
|
206
|
+
{ name: "\u200B", value: "\u200B", inline: true },
|
|
207
|
+
{ name: "⏳ Date:", value: `- <t:${Math.floor(Date.now() / 1000)}:R>`, inline: true }
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
await channel.send({ embeds: [embedLog] });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} catch (error: any) {
|
|
214
|
+
logError(`Error executing command ${command.name}`, error);
|
|
137
215
|
}
|
|
138
216
|
}
|
|
139
217
|
|
|
@@ -47,7 +47,7 @@ export async function prefixLoader(client: any): Promise<{ commands: Collection<
|
|
|
47
47
|
return { commands: commands, success: true };
|
|
48
48
|
} catch (error: any) {
|
|
49
49
|
logError('Error reloading commands:');
|
|
50
|
-
logError(error.message);
|
|
50
|
+
logError(error.message, error);
|
|
51
51
|
|
|
52
52
|
return { commands: new Collection(), success: false };
|
|
53
53
|
}
|
|
@@ -30,6 +30,13 @@ export async function registerSlashCommands(client: any, token: string, slash: S
|
|
|
30
30
|
if (command.cooldown && !isNaN(command.cooldown)) {
|
|
31
31
|
command.data.cooldown = command.cooldown || 0;
|
|
32
32
|
}
|
|
33
|
+
command.data.botPerms = command.botPerms || [];
|
|
34
|
+
command.data.userPerms = command.userPerms || [];
|
|
35
|
+
command.data.owner = command.owner || false;
|
|
36
|
+
command.data.developer = command.developer || false;
|
|
37
|
+
command.data.category = command.category || 'Uncategorized';
|
|
38
|
+
|
|
39
|
+
|
|
33
40
|
slashCommands.set(command.data.name, command);
|
|
34
41
|
}
|
|
35
42
|
} catch (error: any) {
|
|
@@ -44,6 +51,13 @@ export async function registerSlashCommands(client: any, token: string, slash: S
|
|
|
44
51
|
if (command.cooldown && !isNaN(command.cooldown)) {
|
|
45
52
|
command.data.cooldown = command.cooldown || 0;
|
|
46
53
|
}
|
|
54
|
+
command.data.botPerms = command.botPerms || [];
|
|
55
|
+
command.data.userPerms = command.userPerms || [];
|
|
56
|
+
command.data.owner = command.owner || false;
|
|
57
|
+
command.data.developer = command.developer || false;
|
|
58
|
+
command.data.category = command.category || 'Uncategorized';
|
|
59
|
+
|
|
60
|
+
|
|
47
61
|
slashCommands.set(command.data.name, command);
|
|
48
62
|
}
|
|
49
63
|
} catch (error: any) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, Collection, Interaction, EmbedBuilder, Snowflake, PermissionResolvable } from 'discord.js';
|
|
1
|
+
import { Client, Collection, Interaction, EmbedBuilder, Snowflake, PermissionResolvable, TextChannel } from 'discord.js';
|
|
2
2
|
import { registerSlashCommands } from './slash-register';
|
|
3
3
|
import { SlashOptions } from '../types/starter';
|
|
4
4
|
import { logWarning, logError, logInfo } from '../functions/logger';
|
|
@@ -79,36 +79,38 @@ export async function loadSlash(client: Client, token: string, options: SlashOpt
|
|
|
79
79
|
logWarning(`Command "${command.data.name}" has neither run nor execute method.`);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
82
|
+
if (options.logsId) {
|
|
83
|
+
const channel = interaction.guild.channels.cache.get(options.logsId as string) as TextChannel;
|
|
84
|
+
if(channel) {
|
|
85
|
+
const userName = interaction.user.username;
|
|
86
|
+
const userId = interaction.user.id;
|
|
87
|
+
const serverName = interaction.guild.name || 'Unknown Server';
|
|
88
|
+
const serverId = interaction.guild.id || 'Unknown ID';
|
|
89
|
+
let messageLink = '';
|
|
90
|
+
|
|
91
|
+
if (interaction.channel) {
|
|
92
|
+
messageLink = `https://discord.com/channels/${serverId}/${interaction.channel.id}/${interaction.id}`;
|
|
93
|
+
} else {
|
|
94
|
+
messageLink = 'Unknown';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const embedLog = new EmbedBuilder()
|
|
98
|
+
.setColor("Blue")
|
|
99
|
+
.setThumbnail(interaction.client.user?.displayAvatarURL())
|
|
100
|
+
.setTitle("Use Slash Command")
|
|
101
|
+
.setTimestamp()
|
|
102
|
+
.addFields(
|
|
103
|
+
{ name: "📧 Cmd:", value: `- ${command.data.name}`, inline: true },
|
|
104
|
+
{ name: "🤪 User:", value: `- ${userName} (<@${userId}>)`, inline: true },
|
|
105
|
+
{ name: "\u200B", value: "\u200B", inline: true },
|
|
106
|
+
{ name: "🏠 Server:", value: `- ${serverName}.\n- [\`${serverId}\`].`, inline: true },
|
|
107
|
+
{ name: "📩 Message:", value: `- [Link](${messageLink})`, inline: true },
|
|
108
|
+
{ name: "\u200B", value: "\u200B", inline: true },
|
|
109
|
+
{ name: "⏳ Date:", value: `- <t:${Math.floor(Date.now() / 1000)}:R>`, inline: true }
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
await channel.send({ embeds: [embedLog] });
|
|
113
|
+
}
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
const executionTime = Date.now() - startExecutionTime;
|
|
@@ -46,6 +46,12 @@ export async function slashLoader(client: any): Promise<{ commands: Collection<s
|
|
|
46
46
|
try {
|
|
47
47
|
const command = require(file);
|
|
48
48
|
if (command.data) {
|
|
49
|
+
command.cooldown = command.cooldown || 0;
|
|
50
|
+
command.owner = command.owner || false;
|
|
51
|
+
command.developer = command.developer || false;
|
|
52
|
+
command.botPerms = command.botPerms || [];
|
|
53
|
+
command.userPerms = command.userPerms || [];
|
|
54
|
+
|
|
49
55
|
client.slashCommands.set(command.data.name, command);
|
|
50
56
|
newCommands.set(command.data.name, command);
|
|
51
57
|
}
|
|
@@ -64,8 +70,7 @@ export async function slashLoader(client: any): Promise<{ commands: Collection<s
|
|
|
64
70
|
return { commands: newCommands, success: true };
|
|
65
71
|
} catch (error: any) {
|
|
66
72
|
logError('Error reloading slash commands:');
|
|
67
|
-
logError(error.message);
|
|
68
|
-
console.error(error);
|
|
73
|
+
logError(error.message, error);
|
|
69
74
|
return { commands: new Collection<string, any>(), success: false };
|
|
70
75
|
}
|
|
71
76
|
}
|
|
@@ -9,9 +9,6 @@ const cyan = '\x1b[36m';
|
|
|
9
9
|
const reset = '\x1b[0m';
|
|
10
10
|
const yellow = '\x1b[33m';
|
|
11
11
|
|
|
12
|
-
import { inspect } from 'util';
|
|
13
|
-
|
|
14
|
-
|
|
15
12
|
function getTimestamp(): string {
|
|
16
13
|
const now = new Date();
|
|
17
14
|
const year = now.getFullYear();
|
|
@@ -23,6 +20,19 @@ function getTimestamp(): string {
|
|
|
23
20
|
return `[${year}-${month}-${day} ${hours}:${minutes}:${seconds}]`;
|
|
24
21
|
}
|
|
25
22
|
|
|
23
|
+
function extractErrorLocation(stack: string): string {
|
|
24
|
+
const lines = stack.split('\n');
|
|
25
|
+
const locationLine = lines[1] || lines[0];
|
|
26
|
+
|
|
27
|
+
const match = locationLine.match(/\((.*):(\d+):(\d+)\)/);
|
|
28
|
+
if (match) {
|
|
29
|
+
const file = match[1];
|
|
30
|
+
const line = match[2];
|
|
31
|
+
return `File: ${file}, Line: ${line}`;
|
|
32
|
+
}
|
|
33
|
+
return 'Unknown location';
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
export function logSuccess(message: string) {
|
|
27
37
|
console.log(`${getTimestamp()} ${green}${successEmoji}${reset} ${green}${message}${reset}`);
|
|
28
38
|
}
|
|
@@ -32,18 +42,17 @@ export function logError(message: string, error?: Error) {
|
|
|
32
42
|
const baseMessage = `${timestamp} ${red}${errorEmoji}${reset} ${red}${message}${reset}`;
|
|
33
43
|
|
|
34
44
|
if (error && error.stack) {
|
|
35
|
-
|
|
45
|
+
const location = extractErrorLocation(error.stack);
|
|
46
|
+
console.error(`${baseMessage}\n${location}\n${error.stack}`);
|
|
36
47
|
} else {
|
|
37
48
|
console.error(baseMessage);
|
|
38
49
|
}
|
|
39
50
|
}
|
|
40
51
|
|
|
41
|
-
|
|
42
52
|
export function logInfo(message: string) {
|
|
43
53
|
console.log(`${getTimestamp()} ${cyan}${infoEmoji}${reset} ${cyan}${message}${reset}`);
|
|
44
54
|
}
|
|
45
55
|
|
|
46
|
-
|
|
47
56
|
export function logWarning(message: string) {
|
|
48
57
|
console.warn(`${getTimestamp()} ${yellow}${warningEmoji}${reset} ${yellow}${message}${reset}`);
|
|
49
58
|
}
|
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
import { Collection } from 'discord.js'
|
|
1
|
+
import { Collection } from 'discord.js';
|
|
2
2
|
import { Command } from '../types/starter';
|
|
3
|
+
|
|
3
4
|
export function getSimilarCommands(commandName: string, commands: Collection<string, Command>): string[] {
|
|
4
|
-
const similarityThreshold = 0.6;
|
|
5
|
+
const similarityThreshold = 0.6;
|
|
6
|
+
const partialMatches: string[] = [];
|
|
5
7
|
const similarCommands: { name: string; similarity: number }[] = [];
|
|
6
8
|
|
|
7
9
|
commands.forEach((_, cmdName) => {
|
|
10
|
+
if (cmdName.includes(commandName) || commandName.includes(cmdName)) {
|
|
11
|
+
partialMatches.push(cmdName);
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
const similarity = calculateSimilarity(commandName, cmdName);
|
|
9
15
|
if (similarity >= similarityThreshold) {
|
|
10
16
|
similarCommands.push({ name: cmdName, similarity });
|
|
11
17
|
}
|
|
12
18
|
});
|
|
13
19
|
|
|
20
|
+
const combinedCommands = new Set([...partialMatches, ...similarCommands.map(cmd => cmd.name)]);
|
|
21
|
+
const uniqueCommands = Array.from(combinedCommands);
|
|
22
|
+
|
|
14
23
|
similarCommands.sort((a, b) => b.similarity - a.similarity);
|
|
15
24
|
|
|
16
|
-
return
|
|
25
|
+
return uniqueCommands.sort((a, b) => {
|
|
26
|
+
const aIndex = similarCommands.findIndex(cmd => cmd.name === a);
|
|
27
|
+
const bIndex = similarCommands.findIndex(cmd => cmd.name === b);
|
|
28
|
+
return bIndex - aIndex;
|
|
29
|
+
});
|
|
17
30
|
}
|
|
18
31
|
|
|
19
32
|
function calculateSimilarity(str1: string, str2: string): number {
|
|
@@ -21,7 +34,6 @@ function calculateSimilarity(str1: string, str2: string): number {
|
|
|
21
34
|
const len2 = str2.length;
|
|
22
35
|
const matrix = [];
|
|
23
36
|
|
|
24
|
-
// Initialize the matrix
|
|
25
37
|
for (let i = 0; i <= len1; i++) {
|
|
26
38
|
matrix[i] = [i];
|
|
27
39
|
}
|
|
@@ -35,7 +47,7 @@ function calculateSimilarity(str1: string, str2: string): number {
|
|
|
35
47
|
matrix[i][j] = Math.min(
|
|
36
48
|
matrix[i - 1][j] + 1,
|
|
37
49
|
matrix[i][j - 1] + 1,
|
|
38
|
-
matrix[i - 1][j - 1] + cost
|
|
50
|
+
matrix[i - 1][j - 1] + cost
|
|
39
51
|
);
|
|
40
52
|
}
|
|
41
53
|
}
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import { blue,
|
|
2
|
-
import { BotOptions } from '../types/starter';
|
|
1
|
+
import { blue, cyanBright, greenBright, red, yellowBright, redBright, green, magentaBright, cyan, yellow, blueBright, gray } from 'colorette';
|
|
3
2
|
import Table from 'cli-table';
|
|
4
3
|
import fs from 'fs';
|
|
5
4
|
import path from 'path';
|
|
5
|
+
import figlet from 'figlet';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async function showLoadingBar(duration: number) {
|
|
10
|
+
const steps = [15, 30, 70, 85, 95, 100];
|
|
11
|
+
const interval = duration / steps.length;
|
|
12
|
+
|
|
13
|
+
for (const step of steps) {
|
|
14
|
+
process.stdout.write(`\r${cyanBright('Loading... ')}${'█'.repeat(step / 10)}${'░'.repeat(10 - step / 10)} ${step}%`);
|
|
15
|
+
await new Promise(resolve => setTimeout(resolve, interval));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
process.stdout.write('\r'.padEnd(50) + '\r');
|
|
12
19
|
}
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
// Main function to show terminal logs
|
|
22
|
+
export async function terminalLogs(client: any, bot: any): Promise<void> {
|
|
15
23
|
const { user, prefixSize = 0, slashSize = 0, eventSize = 0 } = client;
|
|
16
24
|
|
|
17
25
|
const totalCommands = slashSize + prefixSize;
|
|
@@ -45,9 +53,12 @@ export async function terminalLogs(client: any, bot: BotOptions): Promise<void>
|
|
|
45
53
|
const projectPath = findProjectRoot();
|
|
46
54
|
const projectSize = getProjectSize(projectPath);
|
|
47
55
|
|
|
56
|
+
await showLoadingBar(3000);
|
|
57
|
+
|
|
48
58
|
const botStatesTable = new Table({
|
|
49
59
|
head: [blue('# Bot States')],
|
|
50
|
-
colWidths: [30,
|
|
60
|
+
colWidths: [30, 40],
|
|
61
|
+
style: { 'padding-left': 1, 'padding-right': 1 }
|
|
51
62
|
});
|
|
52
63
|
botStatesTable.push(
|
|
53
64
|
[yellowBright('Bot Name'), user.username],
|
|
@@ -59,10 +70,11 @@ export async function terminalLogs(client: any, bot: BotOptions): Promise<void>
|
|
|
59
70
|
|
|
60
71
|
const botInfoTable = new Table({
|
|
61
72
|
head: [blue('# Bot Info')],
|
|
62
|
-
colWidths: [30,
|
|
73
|
+
colWidths: [30, 50],
|
|
74
|
+
style: { 'padding-left': 1, 'padding-right': 1 }
|
|
63
75
|
});
|
|
64
|
-
if (client.presence?.
|
|
65
|
-
botInfoTable.push([
|
|
76
|
+
if (client.presence?.status) {
|
|
77
|
+
botInfoTable.push([yellowBright('Status'), client.presence.status]);
|
|
66
78
|
}
|
|
67
79
|
if (bot.Status?.activities && bot.Status.activities.length > 0) {
|
|
68
80
|
botInfoTable.push([cyanBright('Activity'), bot.Status.activities[0]]);
|
|
@@ -90,6 +102,7 @@ export async function terminalLogs(client: any, bot: BotOptions): Promise<void>
|
|
|
90
102
|
const loggedInAt = new Date(client.readyTimestamp).toLocaleString();
|
|
91
103
|
botInfoTable.push([yellowBright('Logged In At'), loggedInAt]);
|
|
92
104
|
}
|
|
93
|
-
|
|
94
|
-
console.log(
|
|
105
|
+
|
|
106
|
+
console.log(`\n${blueBright('Bot States')}\n${botStatesTable.toString()}\n`);
|
|
107
|
+
console.log(`${blueBright('Bot Info')}\n${botInfoTable.toString()}\n`);
|
|
95
108
|
}
|
|
@@ -106,9 +106,12 @@ export interface Command {
|
|
|
106
106
|
cooldown?: number;
|
|
107
107
|
usage?: string;
|
|
108
108
|
developer?: boolean;
|
|
109
|
-
prefix?: boolean;
|
|
110
109
|
category?: string;
|
|
110
|
+
fastUse?: boolean;
|
|
111
|
+
botPerms?: string[];
|
|
112
|
+
userPerms?: string[];
|
|
111
113
|
owner?: boolean;
|
|
114
|
+
accessLevel?: string;
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
export interface StarterOptions {
|
package/lib/discord/utils.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { readCommands } from "./events-handler/prefix-register";
|
|
|
7
7
|
import { loadPrefix, handleMessageCreate } from "./events-handler/prefix-responder";
|
|
8
8
|
import { registerSlashCommands } from "./events-handler/slash-register";
|
|
9
9
|
import { loadSlash } from "./events-handler/slash-responder";
|
|
10
|
+
import { logError, logInfo, logSuccess, logWarning } from "./functions/logger";
|
|
10
11
|
import { loadEvents, withRetry, processEventFile, processDirectory, limitConcurrency, countEventFiles } from "./events-handler/events";
|
|
11
12
|
export { Starter, ButtonManager, MenuManager, PermissionChecker, slashLoader, prefixLoader, eventLoader, readCommands, loadEvents,
|
|
12
13
|
loadSlash, loadPrefix, handleMessageCreate, processDirectory, countEventFiles, limitConcurrency, withRetry, registerSlashCommands,
|
|
13
|
-
processEventFile }
|
|
14
|
+
processEventFile, logError, logInfo, logSuccess, logWarning }
|
package/lib/index.ts
CHANGED
|
@@ -29,12 +29,12 @@ fetch("https://registry.npmjs.com/-/v1/search?text=djs-builder")
|
|
|
29
29
|
|
|
30
30
|
import { Starter, ButtonManager, MenuManager, PermissionChecker, slashLoader, prefixLoader, eventLoader, readCommands, loadEvents,
|
|
31
31
|
loadSlash, loadPrefix, handleMessageCreate, processDirectory, countEventFiles, limitConcurrency, withRetry, registerSlashCommands,
|
|
32
|
-
processEventFile } from "./discord/utils";
|
|
32
|
+
processEventFile, logError, logInfo, logSuccess, logWarning } from "./discord/utils";
|
|
33
33
|
|
|
34
34
|
export { Starter, ButtonManager, MenuManager, PermissionChecker, slashLoader, prefixLoader, eventLoader, readCommands, loadEvents,
|
|
35
35
|
loadSlash, loadPrefix, handleMessageCreate, processDirectory, countEventFiles, limitConcurrency, withRetry, registerSlashCommands,
|
|
36
|
-
processEventFile };
|
|
36
|
+
processEventFile , logError, logInfo, logSuccess, logWarning};
|
|
37
37
|
export default { Starter, ButtonManager, MenuManager, PermissionChecker, slashLoader, prefixLoader, eventLoader, readCommands, loadEvents,
|
|
38
38
|
loadSlash, loadPrefix, handleMessageCreate, processDirectory, countEventFiles, limitConcurrency, withRetry, registerSlashCommands,
|
|
39
|
-
processEventFile };
|
|
39
|
+
processEventFile, logError, logInfo, logSuccess, logWarning };
|
|
40
40
|
export * from './discord/types/starter';
|