djs-builder 0.5.42 → 0.6.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/README.md +140 -303
- package/function/function.js +236 -0
- package/function/log.js +736 -0
- package/handler/helper.js +277 -0
- package/handler/starter.js +335 -0
- package/package.json +10 -42
- package/.tsbuildinfo +0 -1
- package/dist/discord/builder/components/Buttons.d.ts +0 -22
- package/dist/discord/builder/components/Buttons.d.ts.map +0 -1
- package/dist/discord/builder/components/Buttons.js +0 -91
- package/dist/discord/builder/components/Buttons.js.map +0 -1
- package/dist/discord/builder/components/Menus.d.ts +0 -31
- package/dist/discord/builder/components/Menus.d.ts.map +0 -1
- package/dist/discord/builder/components/Menus.js +0 -82
- package/dist/discord/builder/components/Menus.js.map +0 -1
- package/dist/discord/builder/permissions/perms.d.ts +0 -6
- package/dist/discord/builder/permissions/perms.d.ts.map +0 -1
- package/dist/discord/builder/permissions/perms.js +0 -66
- package/dist/discord/builder/permissions/perms.js.map +0 -1
- package/dist/discord/builder/system/Pagination.d.ts +0 -68
- package/dist/discord/builder/system/Pagination.d.ts.map +0 -1
- package/dist/discord/builder/system/Pagination.js +0 -256
- package/dist/discord/builder/system/Pagination.js.map +0 -1
- package/dist/discord/builder/system/collectors.d.ts +0 -27
- package/dist/discord/builder/system/collectors.d.ts.map +0 -1
- package/dist/discord/builder/system/collectors.js +0 -137
- package/dist/discord/builder/system/collectors.js.map +0 -1
- package/dist/discord/builder/utils.d.ts +0 -5
- package/dist/discord/builder/utils.d.ts.map +0 -1
- package/dist/discord/builder/utils.js +0 -10
- package/dist/discord/builder/utils.js.map +0 -1
- package/dist/discord/events-handler/eventLoader.d.ts +0 -13
- package/dist/discord/events-handler/eventLoader.d.ts.map +0 -1
- package/dist/discord/events-handler/eventLoader.js +0 -169
- package/dist/discord/events-handler/eventLoader.js.map +0 -1
- package/dist/discord/events-handler/events.d.ts +0 -8
- package/dist/discord/events-handler/events.d.ts.map +0 -1
- package/dist/discord/events-handler/events.js +0 -186
- package/dist/discord/events-handler/events.js.map +0 -1
- package/dist/discord/events-handler/login.d.ts +0 -9
- package/dist/discord/events-handler/login.d.ts.map +0 -1
- package/dist/discord/events-handler/login.js +0 -273
- package/dist/discord/events-handler/login.js.map +0 -1
- package/dist/discord/events-handler/prefix-register.d.ts +0 -23
- package/dist/discord/events-handler/prefix-register.d.ts.map +0 -1
- package/dist/discord/events-handler/prefix-register.js +0 -109
- package/dist/discord/events-handler/prefix-register.js.map +0 -1
- package/dist/discord/events-handler/prefix-responder.d.ts +0 -5
- package/dist/discord/events-handler/prefix-responder.d.ts.map +0 -1
- package/dist/discord/events-handler/prefix-responder.js +0 -155
- package/dist/discord/events-handler/prefix-responder.js.map +0 -1
- package/dist/discord/events-handler/prefixLoader.d.ts +0 -7
- package/dist/discord/events-handler/prefixLoader.d.ts.map +0 -1
- package/dist/discord/events-handler/prefixLoader.js +0 -74
- package/dist/discord/events-handler/prefixLoader.js.map +0 -1
- package/dist/discord/events-handler/slash-register.d.ts +0 -4
- package/dist/discord/events-handler/slash-register.d.ts.map +0 -1
- package/dist/discord/events-handler/slash-register.js +0 -85
- package/dist/discord/events-handler/slash-register.js.map +0 -1
- package/dist/discord/events-handler/slash-responder.d.ts +0 -3
- package/dist/discord/events-handler/slash-responder.d.ts.map +0 -1
- package/dist/discord/events-handler/slash-responder.js +0 -112
- package/dist/discord/events-handler/slash-responder.js.map +0 -1
- package/dist/discord/events-handler/slashLoader.d.ts +0 -7
- package/dist/discord/events-handler/slashLoader.d.ts.map +0 -1
- package/dist/discord/events-handler/slashLoader.js +0 -94
- package/dist/discord/events-handler/slashLoader.js.map +0 -1
- package/dist/discord/events-handler/starter.d.ts +0 -6
- package/dist/discord/events-handler/starter.d.ts.map +0 -1
- package/dist/discord/events-handler/starter.js +0 -85
- package/dist/discord/events-handler/starter.js.map +0 -1
- package/dist/discord/functions/anticrash.d.ts +0 -3
- package/dist/discord/functions/anticrash.d.ts.map +0 -1
- package/dist/discord/functions/anticrash.js +0 -55
- package/dist/discord/functions/anticrash.js.map +0 -1
- package/dist/discord/functions/devLogs.d.ts +0 -2
- package/dist/discord/functions/devLogs.d.ts.map +0 -1
- package/dist/discord/functions/devLogs.js +0 -137
- package/dist/discord/functions/devLogs.js.map +0 -1
- package/dist/discord/functions/logger.d.ts +0 -5
- package/dist/discord/functions/logger.d.ts.map +0 -1
- package/dist/discord/functions/logger.js +0 -57
- package/dist/discord/functions/logger.js.map +0 -1
- package/dist/discord/functions/mongoDb.d.ts +0 -4
- package/dist/discord/functions/mongoDb.d.ts.map +0 -1
- package/dist/discord/functions/mongoDb.js +0 -39
- package/dist/discord/functions/mongoDb.js.map +0 -1
- package/dist/discord/functions/similarity.d.ts +0 -3
- package/dist/discord/functions/similarity.d.ts.map +0 -1
- package/dist/discord/functions/similarity.js +0 -56
- package/dist/discord/functions/similarity.js.map +0 -1
- package/dist/discord/functions/terminal.d.ts +0 -2
- package/dist/discord/functions/terminal.d.ts.map +0 -1
- package/dist/discord/functions/terminal.js +0 -127
- package/dist/discord/functions/terminal.js.map +0 -1
- package/dist/discord/functions/utils.d.ts +0 -5
- package/dist/discord/functions/utils.d.ts.map +0 -1
- package/dist/discord/functions/utils.js +0 -11
- package/dist/discord/functions/utils.js.map +0 -1
- package/dist/discord/functions/versedb.d.ts +0 -3
- package/dist/discord/functions/versedb.d.ts.map +0 -1
- package/dist/discord/functions/versedb.js +0 -21
- package/dist/discord/functions/versedb.js.map +0 -1
- package/dist/discord/games/X-O.d.ts +0 -20
- package/dist/discord/games/X-O.d.ts.map +0 -1
- package/dist/discord/games/X-O.js +0 -166
- package/dist/discord/games/X-O.js.map +0 -1
- package/dist/discord/games/rps.d.ts +0 -21
- package/dist/discord/games/rps.d.ts.map +0 -1
- package/dist/discord/games/rps.js +0 -99
- package/dist/discord/games/rps.js.map +0 -1
- package/dist/discord/types/starter.d.ts +0 -144
- package/dist/discord/types/starter.d.ts.map +0 -1
- package/dist/discord/types/starter.js +0 -3
- package/dist/discord/types/starter.js.map +0 -1
- package/dist/discord/types/utils.d.ts +0 -3
- package/dist/discord/types/utils.d.ts.map +0 -1
- package/dist/discord/types/utils.js +0 -3
- package/dist/discord/types/utils.js.map +0 -1
- package/dist/discord/utils.d.ts +0 -15
- package/dist/discord/utils.d.ts.map +0 -1
- package/dist/discord/utils.js +0 -41
- package/dist/discord/utils.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -71
- package/dist/index.js.map +0 -1
- package/lib/discord/builder/components/Buttons.ts +0 -123
- package/lib/discord/builder/components/Menus.ts +0 -106
- package/lib/discord/builder/permissions/perms.ts +0 -66
- package/lib/discord/builder/system/Pagination.ts +0 -374
- package/lib/discord/builder/system/collectors.ts +0 -197
- package/lib/discord/builder/utils.ts +0 -9
- package/lib/discord/events-handler/eventLoader.ts +0 -166
- package/lib/discord/events-handler/events.ts +0 -160
- package/lib/discord/events-handler/login.ts +0 -265
- package/lib/discord/events-handler/prefix-register.ts +0 -117
- package/lib/discord/events-handler/prefix-responder.ts +0 -176
- package/lib/discord/events-handler/prefixLoader.ts +0 -83
- package/lib/discord/events-handler/slash-register.ts +0 -81
- package/lib/discord/events-handler/slash-responder.ts +0 -136
- package/lib/discord/events-handler/slashLoader.ts +0 -104
- package/lib/discord/events-handler/starter.ts +0 -85
- package/lib/discord/functions/anticrash.ts +0 -60
- package/lib/discord/functions/devLogs.ts +0 -128
- package/lib/discord/functions/logger.ts +0 -58
- package/lib/discord/functions/mongoDb.ts +0 -38
- package/lib/discord/functions/similarity.ts +0 -70
- package/lib/discord/functions/terminal.ts +0 -162
- package/lib/discord/functions/utils.ts +0 -4
- package/lib/discord/functions/versedb.ts +0 -17
- package/lib/discord/types/starter.ts +0 -158
- package/lib/discord/types/utils.ts +0 -2
- package/lib/discord/utils.ts +0 -17
- package/lib/index.ts +0 -37
- package/tsconfig.json +0 -21
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Client, Collection } 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 { resolve, extname } from 'path';
|
|
6
|
-
import { botData } from './login';
|
|
7
|
-
import { logError, logInfo } from '../functions/logger';
|
|
8
|
-
import { watch } from 'fs';
|
|
9
|
-
|
|
10
|
-
const validExtensions = ['.js', '.ts'];
|
|
11
|
-
|
|
12
|
-
export async function slashLoader(client: any): Promise<{ commands: Collection<string, any>; success: boolean }> {
|
|
13
|
-
try {
|
|
14
|
-
const slashPath = botData.get('slashCommandPath') as string;
|
|
15
|
-
const token = botData.get('botToken') as string;
|
|
16
|
-
|
|
17
|
-
const commandPath = resolve(process.cwd(), slashPath);
|
|
18
|
-
|
|
19
|
-
const getAllFiles = async (dirPath: string): Promise<string[]> => {
|
|
20
|
-
let files: string[] = [];
|
|
21
|
-
const dirents = await readdir(dirPath, { withFileTypes: true });
|
|
22
|
-
|
|
23
|
-
for (const dirent of dirents) {
|
|
24
|
-
const res = resolve(dirPath, dirent.name);
|
|
25
|
-
if (dirent.isDirectory()) {
|
|
26
|
-
files = files.concat(await getAllFiles(res));
|
|
27
|
-
} else if (validExtensions.includes(extname(dirent.name))) {
|
|
28
|
-
files.push(res);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return files;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const files = await getAllFiles(commandPath);
|
|
35
|
-
if (files.length === 0) {
|
|
36
|
-
logInfo(`No command files found in directory \`${commandPath}\`.`);
|
|
37
|
-
return { commands: new Collection<string, any>(), success: false };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
for (const file of files) {
|
|
41
|
-
delete require.cache[require.resolve(file)];
|
|
42
|
-
logInfo(`Unlinked cached module: ${file}`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const newCommands = new Collection<string, any>();
|
|
46
|
-
for (const file of files) {
|
|
47
|
-
try {
|
|
48
|
-
const command = require(file);
|
|
49
|
-
if (command.data) {
|
|
50
|
-
command.cooldown = command.cooldown || 0;
|
|
51
|
-
command.owner = command.owner || false;
|
|
52
|
-
command.developer = command.developer || false;
|
|
53
|
-
command.botPerms = command.botPerms || [];
|
|
54
|
-
command.userPerms = command.userPerms || [];
|
|
55
|
-
|
|
56
|
-
client.slashCommands.set(command.data.name, command);
|
|
57
|
-
newCommands.set(command.data.name, command);
|
|
58
|
-
}
|
|
59
|
-
} catch (error: any) {
|
|
60
|
-
logError(`Error re-importing file: ${file}`);
|
|
61
|
-
logError(error.message);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const rest = new REST({ version: '10' }).setToken(token);
|
|
66
|
-
const slashCommandArray = Array.from(newCommands.values()).map((command: any) => command.data.toJSON());
|
|
67
|
-
|
|
68
|
-
await rest.put(Routes.applicationCommands(client.user?.id || ''), { body: [] });
|
|
69
|
-
await rest.put(Routes.applicationCommands(client.user?.id || ''), { body: slashCommandArray });
|
|
70
|
-
|
|
71
|
-
return { commands: newCommands, success: true };
|
|
72
|
-
} catch (error: any) {
|
|
73
|
-
logError('Error reloading slash commands:');
|
|
74
|
-
logError(error.message, error);
|
|
75
|
-
return { commands: new Collection<string, any>(), success: false };
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function autoSlashLoader(client: Client, DEBOUNCE_DELAY: number = 10000) {
|
|
80
|
-
|
|
81
|
-
const slashPath = botData.get('slashCommandPath') as string;
|
|
82
|
-
const commandPath = resolve(process.cwd(), slashPath);
|
|
83
|
-
|
|
84
|
-
let debounceTimer: NodeJS.Timeout | null = null;
|
|
85
|
-
|
|
86
|
-
const handleReload = async () => {
|
|
87
|
-
if (debounceTimer) {
|
|
88
|
-
clearTimeout(debounceTimer);
|
|
89
|
-
}
|
|
90
|
-
debounceTimer = setTimeout(async () => {
|
|
91
|
-
await slashLoader(client);
|
|
92
|
-
logInfo('Slash commands successfully reloaded after debounce.');
|
|
93
|
-
}, DEBOUNCE_DELAY);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
watch(commandPath, { recursive: false }, (eventType: any, filename: any) => {
|
|
97
|
-
if (filename && validExtensions.includes(extname(filename))) {
|
|
98
|
-
logInfo(`Detected ${eventType} in ${filename}, waiting for debouncing...`);
|
|
99
|
-
handleReload();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
logInfo('Started watching for changes in slash commands...');
|
|
104
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { StarterOptions, StarterInterface, } from '../types/utils';
|
|
2
|
-
import { mongoConnect, getDb, verseConnect } from '../functions/utils';
|
|
3
|
-
const wait = require('node:timers/promises').setTimeout;
|
|
4
|
-
import { botData, login } from './login';
|
|
5
|
-
import { AntiCrash } from '../functions/anticrash';
|
|
6
|
-
import { loadEvents } from './events';
|
|
7
|
-
import { MessageCollector, InteractionCollector, ShardingManager, ShardClientUtil } from 'discord.js';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import fs from 'fs';
|
|
10
|
-
import { logError, logInfo, logSuccess } from '../utils';
|
|
11
|
-
|
|
12
|
-
export class Starter implements StarterInterface {
|
|
13
|
-
async start(djs: any, options: StarterOptions): Promise<any> {
|
|
14
|
-
let mongoDb;
|
|
15
|
-
let verseDb;
|
|
16
|
-
|
|
17
|
-
if (options.sharding?.enable) {
|
|
18
|
-
try {
|
|
19
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'));
|
|
20
|
-
const mainFile = packageJson.main || 'index.js';
|
|
21
|
-
|
|
22
|
-
const manager = new ShardingManager(path.join(process.cwd(), mainFile), {
|
|
23
|
-
totalShards: options.sharding.totalShards || 'auto',
|
|
24
|
-
mode: options.sharding.mode || 'process',
|
|
25
|
-
shardList: options.sharding.shardList || 'auto',
|
|
26
|
-
respawn: options.sharding.respawn !== undefined ? options.sharding.respawn : true,
|
|
27
|
-
silent: options.sharding.silent || false,
|
|
28
|
-
shardArgs: options.sharding.shardArgs || [],
|
|
29
|
-
token: options.sharding.token || options.bot?.token,
|
|
30
|
-
execArgv: options.sharding.execArgv || process.execArgv,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
manager.on('shardCreate', shard => logInfo(`Launched shard ${shard.id}`));
|
|
34
|
-
await manager.spawn();
|
|
35
|
-
djs.shard = manager;
|
|
36
|
-
djs.shardClient = ShardClientUtil.singleton(djs, options?.sharding?.mode || 'process');
|
|
37
|
-
logSuccess('Sharding setup complete and shards spawned.');
|
|
38
|
-
} catch (error: any) {
|
|
39
|
-
logError('Failed to setup sharding', error);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
if (options.bot?.Database?.mongo) {
|
|
44
|
-
await mongoConnect(options.bot.Database.mongo.mongoURI, options.bot.Database.mongo.dbName || 'djsbuilder');
|
|
45
|
-
mongoDb = await getDb();
|
|
46
|
-
}
|
|
47
|
-
if (options.bot?.Database?.verse) {
|
|
48
|
-
verseDb = await verseConnect(options.bot.Database.verse);
|
|
49
|
-
}
|
|
50
|
-
if (options.events) {
|
|
51
|
-
await loadEvents(djs, options.events);
|
|
52
|
-
botData.set('eventsPath', options.events.path);
|
|
53
|
-
}
|
|
54
|
-
if (options.bot) {
|
|
55
|
-
await login(djs, options);
|
|
56
|
-
}
|
|
57
|
-
if (options.anticrash?.enable) {
|
|
58
|
-
await AntiCrash(djs, options)
|
|
59
|
-
}
|
|
60
|
-
} catch (error: any) {
|
|
61
|
-
console.error('An error occurred during bot startup:', error.message);
|
|
62
|
-
await this.handleStartupError(error, djs, options);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
await wait(2_000)
|
|
66
|
-
return {
|
|
67
|
-
mongodb: mongoDb,
|
|
68
|
-
versedb: verseDb,
|
|
69
|
-
slashSize: djs.slashSize || 0,
|
|
70
|
-
prefixSize: djs.prefixSize || 0,
|
|
71
|
-
eventSize: djs.eventSize || 0,
|
|
72
|
-
client: djs
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async handleStartupError(error: any, djs: any, options: StarterOptions) {
|
|
77
|
-
console.error('Error during bot startup:', error);
|
|
78
|
-
setTimeout(() => {
|
|
79
|
-
this.start(djs, options);
|
|
80
|
-
}, 5000);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { WebhookClient, EmbedBuilder } from 'discord.js';
|
|
2
|
-
import { StarterOptions } from '../types/starter';
|
|
3
|
-
|
|
4
|
-
let uncaughtExceptionThrown = false;
|
|
5
|
-
let unhandledRejectionThrown = false;
|
|
6
|
-
|
|
7
|
-
export async function AntiCrash(djs: any, options: StarterOptions) {
|
|
8
|
-
try {
|
|
9
|
-
if (!options.anticrash?.webhookURL) {
|
|
10
|
-
throw new Error('Please provide a valid webhook URL.');
|
|
11
|
-
}
|
|
12
|
-
const webhookClient = new WebhookClient({ url: options.anticrash.webhookURL });
|
|
13
|
-
|
|
14
|
-
process.on('uncaughtException', async (error: any) => {
|
|
15
|
-
if (!uncaughtExceptionThrown) {
|
|
16
|
-
uncaughtExceptionThrown = true;
|
|
17
|
-
console.error('Uncaught Exception:');
|
|
18
|
-
console.error('⚠️ Error:', error.message);
|
|
19
|
-
if (error.stack) {
|
|
20
|
-
console.error('⚠️ Stack Trace:', error.stack);
|
|
21
|
-
const filenameMatch = error.stack.match(/\((.*?):\d+:\d+\)/);
|
|
22
|
-
const filename = filenameMatch ? filenameMatch[1] : 'Unknown File';
|
|
23
|
-
|
|
24
|
-
const embed = new EmbedBuilder()
|
|
25
|
-
.setTitle('🚨 Uncaught Exception')
|
|
26
|
-
.setDescription(`> 📂 **File:** \`${filename}\`\n> 💥 **Error:** \`${error.message}\`\n> 🔍 **Stack Trace:**\n\`\`\`${await error.stack}\`\`\``)
|
|
27
|
-
.setColor('#FF0000')
|
|
28
|
-
.setTimestamp();
|
|
29
|
-
|
|
30
|
-
webhookClient.send({ content: options.anticrash?.mention || '', embeds: [embed] });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
process.on('unhandledRejection', async (reason: any, promise: any) => {
|
|
36
|
-
if (!unhandledRejectionThrown) {
|
|
37
|
-
unhandledRejectionThrown = true;
|
|
38
|
-
console.error('Unhandled Rejection:');
|
|
39
|
-
console.error('⚠️ Reason:', reason);
|
|
40
|
-
if (promise) {
|
|
41
|
-
console.error('⚠️ Promise:', await promise);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const stackTrace = reason?.stack || '';
|
|
45
|
-
const filenameMatch = stackTrace.match(/at\s+(.+):(\d+):(\d+)/);
|
|
46
|
-
const filename = filenameMatch ? filenameMatch[1] : 'Unknown File';
|
|
47
|
-
|
|
48
|
-
const embed = new EmbedBuilder()
|
|
49
|
-
.setTitle('🚨 Unhandled Rejection')
|
|
50
|
-
.setDescription(`> 📂 **File:** \`${filename}\`\n> 💡 **Reason:** \`${reason}\`\n> 🔍 **Promise:**\n\`${await promise}\``)
|
|
51
|
-
.setColor('#FF0000')
|
|
52
|
-
.setTimestamp();
|
|
53
|
-
|
|
54
|
-
webhookClient.send({ content: options.anticrash?.mention || '', embeds: [embed] });
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
} catch (error: any) {
|
|
58
|
-
console.error('An error occurred in AntiCrash function:', error.message);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { WebhookClient, EmbedBuilder } from 'discord.js';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
|
|
5
|
-
export async function devLogger(devLogger: any): Promise<void> {
|
|
6
|
-
const webhook = new WebhookClient({ url: devLogger.webhookURL });
|
|
7
|
-
|
|
8
|
-
const watchedExtensions = ['.js', '.json', '.txt', '.md', '.ts', '.tsx', '.jsx', '.html', '.css', '.py', '.verse'];
|
|
9
|
-
|
|
10
|
-
const MAX_DESCRIPTION_LENGTH = 2048;
|
|
11
|
-
|
|
12
|
-
const watchDirectory = (directory: string) => {
|
|
13
|
-
fs.readdir(directory, (err, files) => {
|
|
14
|
-
if (err) {
|
|
15
|
-
console.error('Error reading directory:', err);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
for (const file of files) {
|
|
20
|
-
const filePath = path.join(directory, file);
|
|
21
|
-
fs.stat(filePath, (err, stats) => {
|
|
22
|
-
if (err) {
|
|
23
|
-
console.error('Error getting file stats:', err);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (stats.isDirectory()) {
|
|
28
|
-
watchDirectory(filePath);
|
|
29
|
-
} else {
|
|
30
|
-
if (watchedExtensions.some(ext => file.endsWith(ext))) {
|
|
31
|
-
watchFile(filePath);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const watchFile = (filePath: string) => {
|
|
40
|
-
fs.watchFile(filePath, { interval: 500 }, (curr, prev) => {
|
|
41
|
-
if (curr.mtime !== prev.mtime) {
|
|
42
|
-
readFile(filePath);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const readFile = (filePath: string) => {
|
|
48
|
-
fs.readFile(filePath, 'utf-8', (err, data) => {
|
|
49
|
-
if (err) {
|
|
50
|
-
console.error('Error reading file:', err);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const embeds = createEmbeds(filePath, data);
|
|
55
|
-
sendWebhooks(embeds);
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const createEmbeds = (filePath: string, data: string) => {
|
|
60
|
-
const fileType = getFileType(filePath);
|
|
61
|
-
const formattedData = '```' + fileType + '\n' + data + '\n```';
|
|
62
|
-
|
|
63
|
-
const chunks = chunkString(formattedData, MAX_DESCRIPTION_LENGTH);
|
|
64
|
-
const embeds: EmbedBuilder[] = [];
|
|
65
|
-
|
|
66
|
-
for (const chunk of chunks) {
|
|
67
|
-
const chunkLines = chunk.split('\n');
|
|
68
|
-
const fileTypeLine = chunkLines[0];
|
|
69
|
-
const codeLines = chunkLines.slice(1, chunkLines.length - 1); // Exclude first and last lines (```javascript and ```)
|
|
70
|
-
const code = codeLines.join('\n');
|
|
71
|
-
|
|
72
|
-
const embed = new EmbedBuilder()
|
|
73
|
-
.setColor('#3498db')
|
|
74
|
-
.setTitle('File Changed')
|
|
75
|
-
.setDescription(`File: \`${filePath}\`\n\`\`\`${fileTypeLine.split('```')[1]}\n${code}\n\`\`\``)
|
|
76
|
-
.setTimestamp();
|
|
77
|
-
|
|
78
|
-
embeds.push(embed);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return embeds;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const sendWebhooks = (embeds: EmbedBuilder[]) => {
|
|
85
|
-
for (const embed of embeds) {
|
|
86
|
-
webhook.send({ content: devLogger.mention || '', embeds: [embed] })
|
|
87
|
-
.then()
|
|
88
|
-
.catch((error) => console.error('Error Dev Logger Message', error));
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const getFileType = (filePath: string): string => {
|
|
93
|
-
const extension = path.extname(filePath);
|
|
94
|
-
switch (extension) {
|
|
95
|
-
case '.js':
|
|
96
|
-
case '.jsx':
|
|
97
|
-
return 'js';
|
|
98
|
-
case 'ts':
|
|
99
|
-
case 'tsx':
|
|
100
|
-
return 'ts';
|
|
101
|
-
case '.json':
|
|
102
|
-
return 'json';
|
|
103
|
-
case '.txt':
|
|
104
|
-
case '.md':
|
|
105
|
-
return 'plaintext';
|
|
106
|
-
case '.html':
|
|
107
|
-
return 'html';
|
|
108
|
-
case '.css':
|
|
109
|
-
return 'css';
|
|
110
|
-
case '.py':
|
|
111
|
-
return 'python';
|
|
112
|
-
case '.verse':
|
|
113
|
-
return 'verse';
|
|
114
|
-
default:
|
|
115
|
-
return 'unknown';
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const chunkString = (str: string, length: number) => {
|
|
120
|
-
const chunks = [];
|
|
121
|
-
for (let i = 0; i < str.length; i += length) {
|
|
122
|
-
chunks.push(str.substring(i, i + length));
|
|
123
|
-
}
|
|
124
|
-
return chunks;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
watchDirectory(devLogger.pathToWatch);
|
|
128
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const successEmoji = '✅';
|
|
2
|
-
const errorEmoji = '❌';
|
|
3
|
-
const infoEmoji = 'ℹ️';
|
|
4
|
-
const warningEmoji = '⚠️';
|
|
5
|
-
|
|
6
|
-
const green = '\x1b[32m';
|
|
7
|
-
const red = '\x1b[31m';
|
|
8
|
-
const cyan = '\x1b[36m';
|
|
9
|
-
const reset = '\x1b[0m';
|
|
10
|
-
const yellow = '\x1b[33m';
|
|
11
|
-
|
|
12
|
-
function getTimestamp(): string {
|
|
13
|
-
const now = new Date();
|
|
14
|
-
const year = now.getFullYear();
|
|
15
|
-
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
16
|
-
const day = String(now.getDate()).padStart(2, '0');
|
|
17
|
-
const hours = String(now.getHours()).padStart(2, '0');
|
|
18
|
-
const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
19
|
-
const seconds = String(now.getSeconds()).padStart(2, '0');
|
|
20
|
-
return `[${year}-${month}-${day} ${hours}:${minutes}:${seconds}]`;
|
|
21
|
-
}
|
|
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
|
-
|
|
36
|
-
export function logSuccess(message: string) {
|
|
37
|
-
console.log(`${getTimestamp()} ${green}${successEmoji}${reset} ${green}${message}${reset}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function logError(message: string, error?: Error) {
|
|
41
|
-
const timestamp = getTimestamp();
|
|
42
|
-
const baseMessage = `${timestamp} ${red}${errorEmoji}${reset} ${red}${message}${reset}`;
|
|
43
|
-
|
|
44
|
-
if (error && error.stack) {
|
|
45
|
-
const location = extractErrorLocation(error.stack);
|
|
46
|
-
console.error(`${baseMessage}\n${location}\n${error.stack}`);
|
|
47
|
-
} else {
|
|
48
|
-
console.error(baseMessage);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function logInfo(message: string) {
|
|
53
|
-
console.log(`${getTimestamp()} ${cyan}${infoEmoji}${reset} ${cyan}${message}${reset}`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function logWarning(message: string) {
|
|
57
|
-
console.warn(`${getTimestamp()} ${yellow}${warningEmoji}${reset} ${yellow}${message}${reset}`);
|
|
58
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { MongoClient, Db } from 'mongodb';
|
|
2
|
-
|
|
3
|
-
let db: Db | null = null;
|
|
4
|
-
let isInitialized = false;
|
|
5
|
-
let connectionPromise: Promise<MongoClient> | null = null;
|
|
6
|
-
|
|
7
|
-
async function initialize(uri: string, dbName: string): Promise<void> {
|
|
8
|
-
if (isInitialized || connectionPromise) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
const client = new MongoClient(uri);
|
|
14
|
-
connectionPromise = client.connect();
|
|
15
|
-
const connectedClient = await connectionPromise;
|
|
16
|
-
db = connectedClient.db(dbName || 'djsBuilder');
|
|
17
|
-
isInitialized = true;
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error('Error initializing MongoDB:', error);
|
|
20
|
-
} finally {
|
|
21
|
-
connectionPromise = null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function mongoConnect(uri: string, dbName: string): Promise<void> {
|
|
26
|
-
await initialize(uri, dbName);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export async function getDb(): Promise<Db> {
|
|
30
|
-
if (!isInitialized) {
|
|
31
|
-
throw new Error('MongoDB connection not initialized');
|
|
32
|
-
}
|
|
33
|
-
if (!db) {
|
|
34
|
-
throw new Error('MongoDB connection not established');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return db;
|
|
38
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Command } from '../types/starter';
|
|
2
|
-
|
|
3
|
-
export function getSimilarCommands(commandName: string, commands: Command[]): string[] {
|
|
4
|
-
const similarityThreshold = 0.6;
|
|
5
|
-
const partialMatches: string[] = [];
|
|
6
|
-
const similarCommands: { name: string; similarity: number }[] = [];
|
|
7
|
-
|
|
8
|
-
for (const command of commands) {
|
|
9
|
-
const cmdName = command.name;
|
|
10
|
-
|
|
11
|
-
if (cmdName.includes(commandName) || commandName.includes(cmdName)) {
|
|
12
|
-
partialMatches.push(cmdName);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const similarity = calculateSimilarity(commandName, cmdName);
|
|
16
|
-
if (similarity >= similarityThreshold) {
|
|
17
|
-
similarCommands.push({ name: cmdName, similarity });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (command.aliases && command.aliases.length > 0) {
|
|
21
|
-
for (const alias of command.aliases) {
|
|
22
|
-
if (alias.includes(commandName) || commandName.includes(alias)) {
|
|
23
|
-
partialMatches.push(alias);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const aliasSimilarity = calculateSimilarity(commandName, alias);
|
|
27
|
-
if (aliasSimilarity >= similarityThreshold) {
|
|
28
|
-
similarCommands.push({ name: alias, similarity: aliasSimilarity });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const combinedCommands = new Set([...partialMatches, ...similarCommands.map(cmd => cmd.name)]);
|
|
35
|
-
const uniqueCommands = Array.from(combinedCommands);
|
|
36
|
-
|
|
37
|
-
similarCommands.sort((a, b) => b.similarity - a.similarity);
|
|
38
|
-
|
|
39
|
-
return uniqueCommands.sort((a, b) => {
|
|
40
|
-
const aIndex = similarCommands.findIndex(cmd => cmd.name === a);
|
|
41
|
-
const bIndex = similarCommands.findIndex(cmd => cmd.name === b);
|
|
42
|
-
return bIndex - aIndex;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function calculateSimilarity(str1: string, str2: string): number {
|
|
47
|
-
const len1 = str1.length;
|
|
48
|
-
const len2 = str2.length;
|
|
49
|
-
const matrix = [];
|
|
50
|
-
|
|
51
|
-
for (let i = 0; i <= len1; i++) {
|
|
52
|
-
matrix[i] = [i];
|
|
53
|
-
}
|
|
54
|
-
for (let j = 0; j <= len2; j++) {
|
|
55
|
-
matrix[0][j] = j;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
for (let i = 1; i <= len1; i++) {
|
|
59
|
-
for (let j = 1; j <= len2; j++) {
|
|
60
|
-
const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;
|
|
61
|
-
matrix[i][j] = Math.min(
|
|
62
|
-
matrix[i - 1][j] + 1,
|
|
63
|
-
matrix[i][j - 1] + 1,
|
|
64
|
-
matrix[i - 1][j - 1] + cost
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return 1 - matrix[len1][len2] / Math.max(len1, len2);
|
|
70
|
-
}
|