djs-builder 0.2.0 → 0.2.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.
- package/lib/discord/events-handler/events.ts +5 -5
- package/lib/discord/events-handler/login.ts +6 -6
- package/lib/discord/events-handler/prefix-register.ts +1 -1
- package/lib/discord/events-handler/prefix-responder.ts +2 -2
- package/lib/discord/events-handler/slash-register.ts +5 -5
- package/lib/discord/events-handler/slash-responder.ts +4 -4
- package/lib/discord/functions/anticrash.ts +10 -10
- package/lib/discord/functions/terminal.ts +10 -10
- package/package.json +1 -1
|
@@ -32,7 +32,7 @@ async function processEventFile(client: any, eventsOptions: EventsOptions, fileP
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
} catch (error) {
|
|
35
|
-
console.error(
|
|
35
|
+
console.error(`⚠️ Error in event file: ${filePath}`);
|
|
36
36
|
console.error(error);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -50,7 +50,7 @@ async function processDirectory(client: any, eventsOptions: EventsOptions, direc
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
} catch (error) {
|
|
53
|
-
console.error(
|
|
53
|
+
console.error(`⚠️ Error while processing directory: ${directoryPath}`);
|
|
54
54
|
console.error(error);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -66,13 +66,13 @@ export async function loadEvents(client: any, eventsOptions: EventsOptions) {
|
|
|
66
66
|
} else if (stats.isFile()) {
|
|
67
67
|
await processEventFile(client, eventsOptions, eventsOptions.path);
|
|
68
68
|
} else {
|
|
69
|
-
console.log(
|
|
69
|
+
console.log(`⚠️ Invalid file or directory: ${resolvedPath}`);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const eventCount = await countEventFiles(eventsOptions.path, eventsOptions);
|
|
73
73
|
client.eventSize = eventCount;
|
|
74
74
|
} catch (error) {
|
|
75
|
-
console.error(
|
|
75
|
+
console.error(`⚠️ Error while loading events from path: ${eventsOptions.path}`);
|
|
76
76
|
console.error(error);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -100,7 +100,7 @@ async function countEventFiles(filePath: string, eventsOptions: EventsOptions):
|
|
|
100
100
|
count++;
|
|
101
101
|
}
|
|
102
102
|
} catch (error) {
|
|
103
|
-
console.error(
|
|
103
|
+
console.error(`⚠️ Error counting event files in directory: ${filePath}`);
|
|
104
104
|
console.error(error);
|
|
105
105
|
}
|
|
106
106
|
return count;
|
|
@@ -11,13 +11,13 @@ export async function login(djs: Client, options: StarterOptions) {
|
|
|
11
11
|
const botData = new Collection<string, string | string[]>();
|
|
12
12
|
|
|
13
13
|
if (!djs) {
|
|
14
|
-
throw new Error("\x1b[31mMissing client parameter. Please provide a valid Discord client.\x1b[0m");
|
|
14
|
+
throw new Error("⚠️ \x1b[31mMissing client parameter. Please provide a valid Discord client.\x1b[0m");
|
|
15
15
|
}
|
|
16
16
|
if (options.bot.token) {
|
|
17
17
|
try {
|
|
18
18
|
await djs.login(options.bot.token);
|
|
19
19
|
} catch (error) {
|
|
20
|
-
console.error("\x1b[31mInvalid token provided. Please provide a valid bot token\x1b[0m");
|
|
20
|
+
console.error("⚠️ \x1b[31mInvalid token provided. Please provide a valid bot token\x1b[0m");
|
|
21
21
|
process.exit(1);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -80,7 +80,7 @@ export async function login(djs: Client, options: StarterOptions) {
|
|
|
80
80
|
url: 'https://www.twitch.tv/discord'
|
|
81
81
|
});
|
|
82
82
|
} else {
|
|
83
|
-
throw new Error('\x1b[
|
|
83
|
+
throw new Error('⚠️ \x1b[31mInvalid bot Status.\x1b[0m');
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -88,7 +88,7 @@ export async function login(djs: Client, options: StarterOptions) {
|
|
|
88
88
|
let delay = 60000;
|
|
89
89
|
if (options.bot.Status.delay !== undefined) {
|
|
90
90
|
if (options.bot.Status.delay < 60000) {
|
|
91
|
-
|
|
91
|
+
console.warn('⚠️ \x1b[31mDelay must be at least 1 minute.\x1b[0m');
|
|
92
92
|
}
|
|
93
93
|
delay = options.bot.Status.delay;
|
|
94
94
|
}
|
|
@@ -114,7 +114,7 @@ export async function login(djs: Client, options: StarterOptions) {
|
|
|
114
114
|
}, delay);
|
|
115
115
|
}
|
|
116
116
|
} else if (options.bot.Status?.activities !== undefined){
|
|
117
|
-
throw new Error('\x1b[
|
|
117
|
+
throw new Error('⚠️ \x1b[31mActivities array must be provided.\x1b[0m');
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
|
|
@@ -130,4 +130,4 @@ export async function login(djs: Client, options: StarterOptions) {
|
|
|
130
130
|
|
|
131
131
|
(djs as any).botData = botData;
|
|
132
132
|
});
|
|
133
|
-
}
|
|
133
|
+
}
|
|
@@ -56,7 +56,7 @@ export async function readCommands(client: any, prefix: { path: string }): Promi
|
|
|
56
56
|
client.prefixSize = prefixCommandCount;
|
|
57
57
|
return prefixCommandCount;
|
|
58
58
|
} catch (error: any) {
|
|
59
|
-
console.error(
|
|
59
|
+
console.error(`⚠️ Error reading directory: ${prefix.path}`);
|
|
60
60
|
console.error(error.message);
|
|
61
61
|
return 0;
|
|
62
62
|
}
|
|
@@ -119,14 +119,14 @@ async function handleMessageCreate(message: Message, prefix: PrefixOptions): Pro
|
|
|
119
119
|
await channel.send({ embeds: [embedLog] });
|
|
120
120
|
}
|
|
121
121
|
} catch (error) {
|
|
122
|
-
console.error(
|
|
122
|
+
console.error(`⚠️ Error executing command ${command.name}:`, error);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
export async function loadPrefix(client: Client, prefix: PrefixOptions): Promise<void> {
|
|
128
128
|
if (!prefix.prefix) {
|
|
129
|
-
throw new Error("\x1b[33m%
|
|
129
|
+
throw new Error("⚠️ \x1b[33m%s No command prefix provided. Please provide a command prefix.\x1b[0m");
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
client.on("messageCreate", async message => await handleMessageCreate(message, prefix));
|
|
@@ -8,7 +8,7 @@ import { SlashOptions } from '../types/starter';
|
|
|
8
8
|
export async function registerSlashCommands(client: any, token: string, slash: SlashOptions): Promise<Collection<string, any>> {
|
|
9
9
|
|
|
10
10
|
if (!token) {
|
|
11
|
-
throw new Error("\x1b[33m%sPlease provide valid bot token to register slash commands.\x1b[0m");
|
|
11
|
+
throw new Error("⚠️ \x1b[33m%sPlease provide valid bot token to register slash commands.\x1b[0m");
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const slashCommands = new Collection<string, any>();
|
|
@@ -33,7 +33,7 @@ export async function registerSlashCommands(client: any, token: string, slash: S
|
|
|
33
33
|
slashCommands.set(command.data.name, command);
|
|
34
34
|
}
|
|
35
35
|
} catch (error: any) {
|
|
36
|
-
console.error(
|
|
36
|
+
console.error(`⚠️ Error in file: ${path.join(folderPath, file)}`);
|
|
37
37
|
console.error(error.message);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -47,7 +47,7 @@ export async function registerSlashCommands(client: any, token: string, slash: S
|
|
|
47
47
|
slashCommands.set(command.data.name, command);
|
|
48
48
|
}
|
|
49
49
|
} catch (error: any) {
|
|
50
|
-
console.error(
|
|
50
|
+
console.error(`⚠️ Error in file: ${path.join(resolvedPath, dirent.name)}`);
|
|
51
51
|
console.error(error.message);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -62,14 +62,14 @@ export async function registerSlashCommands(client: any, token: string, slash: S
|
|
|
62
62
|
const slashCommandArray = Array.from(slashCommands.values()).map(command => command.data.toJSON());
|
|
63
63
|
await rest.put(Routes.applicationGuildCommands((client.user?.id || ''), guild.id), { body: slashCommandArray, headers: { Authorization: `Bot ${token}` } });
|
|
64
64
|
} else {
|
|
65
|
-
console.error(
|
|
65
|
+
console.error(`⚠️ Guild with ID ${slash.serverId} not found.`);
|
|
66
66
|
}
|
|
67
67
|
} else {
|
|
68
68
|
const slashCommandArray = Array.from(slashCommands.values()).map(command => command.data.toJSON());
|
|
69
69
|
await rest.put(Routes.applicationCommands((client.user?.id || '')), { body: slashCommandArray, headers: { Authorization: `Bot ${token}` } });
|
|
70
70
|
}
|
|
71
71
|
} catch (error: any) {
|
|
72
|
-
console.error('Error registering slash commands:', error.message);
|
|
72
|
+
console.error('⚠️ Error registering slash commands:', error.message);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
client.slashSize = slashCommands.size;
|
|
@@ -6,7 +6,7 @@ export async function loadSlash(client: Client, token: string, options: SlashOpt
|
|
|
6
6
|
const slashCommands = await registerSlashCommands(client, token, options);
|
|
7
7
|
|
|
8
8
|
if (!slashCommands || slashCommands.size === 0) {
|
|
9
|
-
console.
|
|
9
|
+
console.warn('\x1b[33m%s\x1b[0m', '⚠️ No registered slash commands. SlachHandler won\'t work.');
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -65,7 +65,7 @@ export async function loadSlash(client: Client, token: string, options: SlashOpt
|
|
|
65
65
|
} else if (command.execute) {
|
|
66
66
|
await command.execute(client, interaction);
|
|
67
67
|
} else {
|
|
68
|
-
console.
|
|
68
|
+
console.warn('⚠️ \x1b[33m%s\x1b[0m', `Command "${command.data.name}" has neither run nor execute method.`);
|
|
69
69
|
}
|
|
70
70
|
const startExecutionTime = Date.now();
|
|
71
71
|
|
|
@@ -103,10 +103,10 @@ export async function loadSlash(client: Client, token: string, options: SlashOpt
|
|
|
103
103
|
|
|
104
104
|
const executionTime = Date.now() - startExecutionTime;
|
|
105
105
|
if (executionTime > 3000) {
|
|
106
|
-
console.log('\x1b[33m%s\x1b[0m', `Command "${command.data.name}" took ${executionTime}ms to execute.`);
|
|
106
|
+
console.log('⚠️ \x1b[33m%s\x1b[0m', `Command "${command.data.name}" took ${executionTime}ms to execute.`);
|
|
107
107
|
}
|
|
108
108
|
} catch (error) {
|
|
109
|
-
console.error('\x1b[31m%s\x1b[0m',
|
|
109
|
+
console.error('\x1b[31m%s\x1b[0m', `⚠️ Error executing command "${command.data.name}":`, error);
|
|
110
110
|
if (interaction.channel) {
|
|
111
111
|
await interaction.channel.send({ content: 'An error occurred while executing the command.' });
|
|
112
112
|
}
|
|
@@ -8,16 +8,16 @@ export async function AntiCrash(djs: any, options: StarterOptions) {
|
|
|
8
8
|
}
|
|
9
9
|
const webhookClient = new WebhookClient({ url: options.anticrash.webhookURL });
|
|
10
10
|
|
|
11
|
-
process.on('uncaughtException', (error: any) => {
|
|
11
|
+
process.on('uncaughtException', async (error: any) => {
|
|
12
12
|
console.error('Uncaught Exception:');
|
|
13
|
-
console.error('Error:', error.message);
|
|
13
|
+
console.error('⚠️ Error:', error.message);
|
|
14
14
|
if (error.stack) {
|
|
15
|
-
console.error('Stack Trace:', error.stack);
|
|
15
|
+
console.error('⚠️ Stack Trace:', error.stack);
|
|
16
16
|
const filenameMatch = error.stack.match(/\((.*?):\d+:\d+\)/);
|
|
17
17
|
const filename = filenameMatch ? filenameMatch[1] : 'Unknown File';
|
|
18
18
|
|
|
19
19
|
const embed = new EmbedBuilder()
|
|
20
|
-
.setTitle('Uncaught Exception')
|
|
20
|
+
.setTitle('🚨 Uncaught Exception')
|
|
21
21
|
.setDescription(`**File:** \`${filename}\`\n**Error:** \`${error.message}\`\n**Stack Trace:** \`\`\`${error.stack}\`\`\``)
|
|
22
22
|
.setColor('#FF0000')
|
|
23
23
|
.setTimestamp();
|
|
@@ -26,11 +26,11 @@ export async function AntiCrash(djs: any, options: StarterOptions) {
|
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
process.on('unhandledRejection', (reason: any, promise: any) => {
|
|
29
|
+
process.on('unhandledRejection', async (reason: any, promise: any) => {
|
|
30
30
|
console.error('Unhandled Rejection:');
|
|
31
|
-
console.error('Reason:', reason);
|
|
31
|
+
console.error('⚠️ Reason:', reason);
|
|
32
32
|
if (promise) {
|
|
33
|
-
console.error('Promise:', promise);
|
|
33
|
+
console.error('⚠️ Promise:', await promise);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const stackTrace = reason?.stack || '';
|
|
@@ -38,8 +38,8 @@ export async function AntiCrash(djs: any, options: StarterOptions) {
|
|
|
38
38
|
const filename = filenameMatch ? filenameMatch[1] : 'Unknown File';
|
|
39
39
|
|
|
40
40
|
const embed = new EmbedBuilder()
|
|
41
|
-
.setTitle('Unhandled Rejection')
|
|
42
|
-
.setDescription(`**File:** \`${filename}\`\n**Reason:** \`${reason}\`\n**Promise:** \`${promise}\``)
|
|
41
|
+
.setTitle('🚨 Unhandled Rejection')
|
|
42
|
+
.setDescription(`**File:** \`${filename}\`\n**Reason:** \`${reason}\`\n**Promise:** \`${await promise}\``)
|
|
43
43
|
.setColor('#FF0000')
|
|
44
44
|
.setTimestamp();
|
|
45
45
|
|
|
@@ -49,4 +49,4 @@ export async function AntiCrash(djs: any, options: StarterOptions) {
|
|
|
49
49
|
} catch (error: any) {
|
|
50
50
|
console.error('An error occurred in AntiCrash function:', error.message);
|
|
51
51
|
}
|
|
52
|
-
}
|
|
52
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { blue, cyan, green, magenta, red } from 'colorette';
|
|
1
|
+
import { blue, cyan, green, magenta, red, black, yellow, white, cyanBright, gray, redBright, greenBright, yellowBright } from 'colorette';
|
|
2
2
|
import { BotOptions } from '../types/starter';
|
|
3
3
|
import Table from 'cli-table';
|
|
4
4
|
import fs from 'fs';
|
|
@@ -54,7 +54,7 @@ export async function terminalLogs(client: any, bot: BotOptions): Promise<void>
|
|
|
54
54
|
[green('Prefix Count'), prefixSize],
|
|
55
55
|
[red('Slash Command Count'), slashSize],
|
|
56
56
|
[cyan('Total Commands'), totalCommands],
|
|
57
|
-
[
|
|
57
|
+
[black('Event Count'), eventSize]
|
|
58
58
|
);
|
|
59
59
|
|
|
60
60
|
const botInfoTable = new Table({
|
|
@@ -62,33 +62,33 @@ export async function terminalLogs(client: any, bot: BotOptions): Promise<void>
|
|
|
62
62
|
colWidths: [30, 25]
|
|
63
63
|
});
|
|
64
64
|
if (client.presence?.Status) {
|
|
65
|
-
botInfoTable.push([
|
|
65
|
+
botInfoTable.push([yellow('Status'), client.presence.Status]);
|
|
66
66
|
}
|
|
67
67
|
if (bot.Status?.activities && bot.Status.activities.length > 0) {
|
|
68
|
-
botInfoTable.push([
|
|
68
|
+
botInfoTable.push([white('Activity'), bot.Status.activities[0]]);
|
|
69
69
|
}
|
|
70
70
|
if (bot.BotInfo?.botInvite) {
|
|
71
|
-
botInfoTable.push([
|
|
71
|
+
botInfoTable.push([cyanBright('Bot Invite'), bot.BotInfo.botInvite]);
|
|
72
72
|
}
|
|
73
73
|
botInfoTable.push(
|
|
74
74
|
[red('Guilds Count'), totalGuilds],
|
|
75
75
|
[cyan('Members Count'), totalMembers]
|
|
76
76
|
);
|
|
77
77
|
if (bot.Database?.verse) {
|
|
78
|
-
botInfoTable.push([
|
|
78
|
+
botInfoTable.push([gray('Bot Database'), 'VerseDb']);
|
|
79
79
|
} else if (bot.Database?.mongo) {
|
|
80
80
|
botInfoTable.push([magenta('Bot Database'), 'MongoDb']);
|
|
81
81
|
}
|
|
82
|
-
botInfoTable.push([
|
|
82
|
+
botInfoTable.push([redBright('Bot Size'), `${(projectSize / (1024 * 1024)).toFixed(2)} MB`]);
|
|
83
83
|
if (client.user?.displayAvatarURL()) {
|
|
84
|
-
botInfoTable.push([
|
|
84
|
+
botInfoTable.push([greenBright('AvatarURL'), client.user.displayAvatarURL()]);
|
|
85
85
|
}
|
|
86
86
|
if (bot.BotInfo?.ownerId) {
|
|
87
|
-
botInfoTable.push([
|
|
87
|
+
botInfoTable.push([cyan('Owner'), bot.BotInfo.ownerId]);
|
|
88
88
|
}
|
|
89
89
|
if (client.readyTimestamp) {
|
|
90
90
|
const loggedInAt = new Date(client.readyTimestamp).toLocaleString();
|
|
91
|
-
botInfoTable.push([
|
|
91
|
+
botInfoTable.push([yellowBright('Logged In At'), loggedInAt]);
|
|
92
92
|
}
|
|
93
93
|
console.log(botStatesTable.toString());
|
|
94
94
|
console.log(botInfoTable.toString());
|