djs-builder 0.5.1 → 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.
Files changed (38) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/dist/discord/events-handler/login.d.ts +2 -2
  3. package/dist/discord/events-handler/login.d.ts.map +1 -1
  4. package/dist/discord/events-handler/login.js +30 -20
  5. package/dist/discord/events-handler/login.js.map +1 -1
  6. package/dist/discord/events-handler/prefix-responder.js +15 -15
  7. package/dist/discord/events-handler/prefix-responder.js.map +1 -1
  8. package/dist/discord/events-handler/prefixLoader.js +1 -1
  9. package/dist/discord/events-handler/prefixLoader.js.map +1 -1
  10. package/dist/discord/events-handler/slash-register.d.ts.map +1 -1
  11. package/dist/discord/events-handler/slash-register.js +10 -0
  12. package/dist/discord/events-handler/slash-register.js.map +1 -1
  13. package/dist/discord/events-handler/slash-responder.d.ts.map +1 -1
  14. package/dist/discord/events-handler/slash-responder.js +22 -20
  15. package/dist/discord/events-handler/slash-responder.js.map +1 -1
  16. package/dist/discord/events-handler/slashLoader.d.ts.map +1 -1
  17. package/dist/discord/events-handler/slashLoader.js +6 -2
  18. package/dist/discord/events-handler/slashLoader.js.map +1 -1
  19. package/dist/discord/functions/logger.d.ts.map +1 -1
  20. package/dist/discord/functions/logger.js +13 -1
  21. package/dist/discord/functions/logger.js.map +1 -1
  22. package/dist/discord/functions/similarity.d.ts.map +1 -1
  23. package/dist/discord/functions/similarity.js +11 -2
  24. package/dist/discord/functions/similarity.js.map +1 -1
  25. package/dist/discord/functions/terminal.d.ts +1 -2
  26. package/dist/discord/functions/terminal.d.ts.map +1 -1
  27. package/dist/discord/functions/terminal.js +19 -6
  28. package/dist/discord/functions/terminal.js.map +1 -1
  29. package/lib/discord/events-handler/login.ts +35 -17
  30. package/lib/discord/events-handler/prefix-responder.ts +25 -25
  31. package/lib/discord/events-handler/prefixLoader.ts +1 -1
  32. package/lib/discord/events-handler/slash-register.ts +14 -0
  33. package/lib/discord/events-handler/slash-responder.ts +33 -31
  34. package/lib/discord/events-handler/slashLoader.ts +7 -2
  35. package/lib/discord/functions/logger.ts +15 -4
  36. package/lib/discord/functions/similarity.ts +17 -5
  37. package/lib/discord/functions/terminal.ts +27 -14
  38. package/package.json +3 -1
@@ -9,7 +9,6 @@ const cyan = '\x1b[36m';
9
9
  const reset = '\x1b[0m';
10
10
  const yellow = '\x1b[33m';
11
11
 
12
-
13
12
  function getTimestamp(): string {
14
13
  const now = new Date();
15
14
  const year = now.getFullYear();
@@ -21,6 +20,19 @@ function getTimestamp(): string {
21
20
  return `[${year}-${month}-${day} ${hours}:${minutes}:${seconds}]`;
22
21
  }
23
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
+
24
36
  export function logSuccess(message: string) {
25
37
  console.log(`${getTimestamp()} ${green}${successEmoji}${reset} ${green}${message}${reset}`);
26
38
  }
@@ -30,18 +42,17 @@ export function logError(message: string, error?: Error) {
30
42
  const baseMessage = `${timestamp} ${red}${errorEmoji}${reset} ${red}${message}${reset}`;
31
43
 
32
44
  if (error && error.stack) {
33
- console.error(`${baseMessage}\n${error.stack}`);
45
+ const location = extractErrorLocation(error.stack);
46
+ console.error(`${baseMessage}\n${location}\n${error.stack}`);
34
47
  } else {
35
48
  console.error(baseMessage);
36
49
  }
37
50
  }
38
51
 
39
-
40
52
  export function logInfo(message: string) {
41
53
  console.log(`${getTimestamp()} ${cyan}${infoEmoji}${reset} ${cyan}${message}${reset}`);
42
54
  }
43
55
 
44
-
45
56
  export function logWarning(message: string) {
46
57
  console.warn(`${getTimestamp()} ${yellow}${warningEmoji}${reset} ${yellow}${message}${reset}`);
47
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 similarCommands.map(cmd => cmd.name);
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, cyan, blueBright, magentaBright, red, yellow, cyanBright, gray, redBright, greenBright, yellowBright } from 'colorette';
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
- interface Client {
8
- user: { username: string };
9
- prefixSize?: number;
10
- slashSize?: number;
11
- eventSize?: number;
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
- export async function terminalLogs(client: any, bot: BotOptions): Promise<void> {
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, 20]
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, 25]
73
+ colWidths: [30, 50],
74
+ style: { 'padding-left': 1, 'padding-right': 1 }
63
75
  });
64
- if (client.presence?.Status) {
65
- botInfoTable.push([yellow('Status'), client.presence.Status]);
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
- console.log(botStatesTable.toString());
94
- console.log(botInfoTable.toString());
105
+
106
+ console.log(`\n${blueBright('Bot States')}\n${botStatesTable.toString()}\n`);
107
+ console.log(`${blueBright('Bot Info')}\n${botInfoTable.toString()}\n`);
95
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "djs-builder",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Discord.js bot builder. Supports Ts and Js.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -30,10 +30,12 @@
30
30
  "mongodb"
31
31
  ],
32
32
  "dependencies": {
33
+ "@types/figlet": "^1.5.8",
33
34
  "cli-table": "^0.3.11",
34
35
  "colorette": "^2.0.20",
35
36
  "discord.js": "^14.15.3",
36
37
  "djs-builder": "^0.4.10",
38
+ "figlet": "^1.7.0",
37
39
  "mongodb": "^6.5.0",
38
40
  "verse.db": "^2.0.4"
39
41
  },