djs-builder 0.5.41 → 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.
Files changed (156) hide show
  1. package/README.md +140 -303
  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 -70
  21. package/dist/discord/builder/system/Pagination.d.ts.map +0 -1
  22. package/dist/discord/builder/system/Pagination.js +0 -227
  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 -323
  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,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
- }
@@ -1,162 +0,0 @@
1
- import { blue, cyanBright, greenBright, red, yellowBright, redBright, green, magentaBright, cyan, yellow, blueBright, gray } from 'colorette';
2
- import Table from 'cli-table';
3
- import fs from 'fs';
4
- import path from 'path';
5
- import figlet from 'figlet';
6
-
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');
19
- }
20
-
21
- export async function terminalLogs(client: any, bot: any): Promise<void> {
22
- const { user, prefixSize = 0, slashSize = 0, eventSize = 0 } = client;
23
-
24
- const totalCommands = slashSize + prefixSize;
25
- const totalGuilds = client.guilds.cache.size;
26
- const totalMembers = client.guilds.cache.reduce((acc: any, guild: any) => acc + guild.memberCount, 0);
27
-
28
- function getProjectSize(dir: string): number {
29
- let size = 0;
30
- const files = fs.readdirSync(dir, { withFileTypes: true });
31
-
32
- files.forEach(file => {
33
- const filePath = path.join(dir, file.name);
34
- if (file.isDirectory() && file.name !== 'node_modules') {
35
- size += getProjectSize(filePath);
36
- } else if (file.isFile()) {
37
- size += fs.statSync(filePath).size;
38
- }
39
- });
40
-
41
- return size;
42
- }
43
-
44
- function findProjectRoot(): string {
45
- let currentDir = __dirname;
46
- while (!fs.existsSync(path.join(currentDir, 'package.json'))) {
47
- currentDir = path.dirname(currentDir);
48
- }
49
- return currentDir;
50
- }
51
-
52
- const projectPath = findProjectRoot();
53
- const projectSize = getProjectSize(projectPath);
54
-
55
- await showLoadingBar(3000);
56
-
57
-
58
-
59
- const colors: string[] = [
60
- '\x1b[34m', // Navy Blue
61
- '\x1b[36m', // Light Blue
62
- '\x1b[90m', // Dark Gray
63
- '\x1b[35m' // Magenta
64
- ];
65
-
66
- const reset: string = '\x1b[0m'; // Reset color code
67
-
68
- function printFigletText(
69
- text: string,
70
- font: string,
71
- colorArray: string[],
72
- width: number,
73
- padding: number = 0,
74
- verticalPadding: number = 0
75
- ): void {
76
- // @ts-ignore
77
- figlet.text(text, { font, width }, (err, data) => {
78
- if (err) {
79
- console.log('Something went wrong...');
80
- console.dir(err);
81
- return;
82
- }
83
-
84
- const lines: string[] | undefined = data?.split('\n');
85
-
86
- const coloredLines: string[] | undefined = lines?.map((line, index) => {
87
- const color: string = colorArray[index % colorArray.length];
88
- const paddedLine: string = ' '.repeat(padding) + line;
89
- return `${color}${paddedLine}${reset}`;
90
- });
91
-
92
- const validVerticalPadding: number = Math.max(verticalPadding, 0);
93
- const outputLines: string = Array(validVerticalPadding).fill('').concat(coloredLines).join('\n');
94
-
95
- console.log(outputLines);
96
- });
97
- }
98
-
99
-
100
- const secondText: string = 'djs-builder';
101
- const secondFont: string = 'Small Slant';
102
- const secondColor: string = colors[2];
103
- const horizontalPadding: number = 50;
104
- const verticalPadding: number = 2000;
105
- if (bot.logs.waterMark) {
106
- printFigletText(secondText, secondFont, [secondColor], 50, horizontalPadding, -verticalPadding);
107
- printFigletText(user.username, '3D-ASCII', colors, 100);
108
- }
109
-
110
- await new Promise(resolve => setTimeout(resolve, 2000));
111
-
112
- const botStatesTable = new Table({
113
- head: [blue('# Bot States')],
114
- colWidths: [30, 40],
115
- style: { 'padding-left': 1, 'padding-right': 1 }
116
- });
117
- botStatesTable.push(
118
- [yellowBright('Bot Name'), user.username],
119
- [greenBright('Prefix Count'), prefixSize],
120
- [red('Slash Command Count'), slashSize],
121
- [cyanBright('Total Commands'), totalCommands],
122
- [magentaBright('Event Count'), eventSize]
123
- );
124
-
125
- const botInfoTable = new Table({
126
- head: [blue('# Bot Info')],
127
- colWidths: [30, 50],
128
- style: { 'padding-left': 1, 'padding-right': 1 }
129
- });
130
- if (client.presence?.status) {
131
- botInfoTable.push([yellowBright('Status'), client.presence.status]);
132
- }
133
- if (bot.Status?.activities && bot.Status.activities.length > 0) {
134
- botInfoTable.push([cyanBright('Activity'), bot.Status.activities[0]]);
135
- }
136
- if (bot.BotInfo?.botInvite) {
137
- botInfoTable.push([cyanBright('Bot Invite'), bot.BotInfo.botInvite]);
138
- }
139
- botInfoTable.push(
140
- [red('Guilds Count'), totalGuilds],
141
- [redBright('Members Count'), totalMembers]
142
- );
143
- if (bot.Database?.verse) {
144
- botInfoTable.push([gray('Bot Database'), 'VerseDb']);
145
- } else if (bot.Database?.mongo) {
146
- botInfoTable.push([greenBright('Bot Database'), 'MongoDb']);
147
- }
148
- botInfoTable.push([redBright('Bot Size'), `${(projectSize / (1024 * 1024)).toFixed(2)} MB`]);
149
- if (client.user?.displayAvatarURL()) {
150
- botInfoTable.push([blueBright('AvatarURL'), client.user.displayAvatarURL()]);
151
- }
152
- if (bot.BotInfo?.ownerId) {
153
- botInfoTable.push([cyan('Owner'), bot.BotInfo.ownerId]);
154
- }
155
- if (client.readyTimestamp) {
156
- const loggedInAt = new Date(client.readyTimestamp).toLocaleString();
157
- botInfoTable.push([yellowBright('Logged In At'), loggedInAt]);
158
- }
159
-
160
- console.log(`\n${blueBright('Bot States')}\n${botStatesTable.toString()}\n`);
161
- console.log(`${blueBright('Bot Info')}\n${botInfoTable.toString()}\n`);
162
- }
@@ -1,4 +0,0 @@
1
- import { getSimilarCommands } from './similarity';
2
- import { mongoConnect, getDb } from './mongoDb';
3
- import { verseConnect } from './versedb'
4
- export { getSimilarCommands, mongoConnect, getDb, verseConnect }
@@ -1,17 +0,0 @@
1
- import versedb from "verse.db";
2
- import { LocalDb } from "../types/starter";
3
-
4
- export async function verseConnect(options: LocalDb) {
5
- const connection = {
6
- adapter: options.adapterType,
7
- dataPath: options.path,
8
- secure: { enable: options.secure?.enable, secret: options.secure?.secret || 'djs-builder' },
9
- devLogs: {
10
- enable: options.dev.enable,
11
- path: options.dev.logsPath || ''
12
- }
13
- };
14
-
15
- const db = new versedb.connect(connection)
16
- return db;
17
- }
@@ -1,158 +0,0 @@
1
- import { Client } from 'discord.js'
2
-
3
- export interface BotOptions {
4
- token?: string;
5
- logs?: {
6
- devLogs?: {
7
- enable: boolean;
8
- pathToWatch: any;
9
- webhookURL: string;
10
- mention?: string;
11
- };
12
- terminal?: boolean;
13
- waterMark?: boolean;
14
- };
15
- name?: string;
16
- avatar?: string;
17
- banner?: string;
18
- BotInfo?: {
19
- perms?: string[];
20
- serverId?: string;
21
- botInvite?: string;
22
- serverInvite?: string;
23
- ownerId?: string;
24
- partners?: string[];
25
- developers?: string[];
26
- };
27
- Status?: {
28
- state: 'online' | 'dnd' | 'idle' | 'invisible' | 'Streaming' | any;
29
- activities?: string[] | undefined;
30
- type?: number;
31
- delay?: number;
32
- };
33
- Database?: {
34
- mongo?: MongoDbOptions;
35
- verse?: LocalDb;
36
- }
37
- }
38
-
39
- export interface SlashOptions {
40
- path: string;
41
- global?: boolean;
42
- serverId?: string;
43
- logsId?: string;
44
- autoLoader?: {
45
- enable?: boolean;
46
- DEBOUNCE_DELAY?: number;
47
- }
48
- }
49
-
50
- export interface PrefixOptions {
51
- path: string;
52
- prefix: string;
53
- global?: boolean;
54
- serverIds?: string[];
55
- customPrefix?: {
56
- serverId: string;
57
- prefix: string;
58
- }[];
59
- similarity?: boolean;
60
- logsId?: string;
61
- autoLoader?: {
62
- enable?: boolean;
63
- DEBOUNCE_DELAY?: number;
64
- }
65
- }
66
-
67
- export interface MongoDbOptions{
68
- mongoURI: string;
69
- dbName?: string;
70
- }
71
-
72
- export interface LocalDb {
73
- adapterType: string | 'json' | 'sql' | 'yaml';
74
- path: string;
75
- dev: {
76
- enable: boolean;
77
- logsPath?: string;
78
- };
79
- secure: {
80
- enable: boolean;
81
- secret: string;
82
- };
83
- }
84
-
85
-
86
- export interface AntiCrash{
87
- enable: boolean;
88
- webhookURL: string;
89
- mention?: string;
90
- }
91
-
92
- export interface EventsOptions {
93
- path: string;
94
- logsId?: string;
95
- recursive?: boolean;
96
- eventBlacklist?: string[];
97
- autoLoader?: {
98
- enable?: boolean;
99
- DEBOUNCE_DELAY?: number;
100
- }
101
- }
102
-
103
- export interface Event {
104
- name: string;
105
- once: boolean;
106
- execute(...args: any[]): Promise<void>;
107
- initializer?: number;
108
- interval?: number;
109
- intervalId?: NodeJS.Timeout;
110
- maxExecution?: number;
111
- retryAttempts?: number;
112
- }
113
-
114
- export interface Command {
115
- name: string;
116
- description?: string;
117
- execute?: (...args: any[]) => void;
118
- run?: (...args: any[]) => void;
119
- aliases?: string[];
120
- cooldown?: number;
121
- usage?: string;
122
- developer?: boolean;
123
- category?: string;
124
- fastUse?: boolean;
125
- botPerms?: string[];
126
- userPerms?: string[];
127
- owner?: boolean;
128
- accessLevel?: string;
129
- method?: (...args: any[]) => void;
130
- }
131
-
132
- export type ShardingManagerMode = 'process' | 'worker';
133
-
134
- export interface ShardingManagerOptions {
135
- enable?: boolean;
136
- totalShards?: number | 'auto';
137
- shardList?: readonly number[] | 'auto';
138
- mode?: ShardingManagerMode;
139
- respawn?: boolean;
140
- silent?: boolean;
141
- shardArgs?: readonly string[];
142
- token?: string;
143
- execArgv?: readonly string[];
144
- }
145
-
146
- export interface StarterOptions {
147
- bot: BotOptions;
148
- sharding?: ShardingManagerOptions;
149
- slash?: SlashOptions;
150
- prefix?: PrefixOptions;
151
- events?: EventsOptions;
152
- anticrash?: AntiCrash;
153
- }
154
-
155
- export interface StarterInterface {
156
- start(djs: Client, options: StarterOptions): Promise<any>;
157
- }
158
-