djs-builder 0.1.5 → 0.2.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 (39) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/README.md +15 -14
  3. package/dist/discord/builder/components/Menus.d.ts +1 -1
  4. package/dist/discord/events-handler/events.js +6 -6
  5. package/dist/discord/events-handler/events.js.map +1 -1
  6. package/dist/discord/events-handler/login.d.ts +2 -2
  7. package/dist/discord/events-handler/login.d.ts.map +1 -1
  8. package/dist/discord/events-handler/login.js +64 -50
  9. package/dist/discord/events-handler/login.js.map +1 -1
  10. package/dist/discord/events-handler/prefix-register.d.ts +0 -1
  11. package/dist/discord/events-handler/prefix-register.d.ts.map +1 -1
  12. package/dist/discord/events-handler/prefix-register.js +4 -4
  13. package/dist/discord/events-handler/prefix-register.js.map +1 -1
  14. package/dist/discord/events-handler/prefix-responder.js +1 -1
  15. package/dist/discord/events-handler/prefix-responder.js.map +1 -1
  16. package/dist/discord/events-handler/slash-register.js +4 -4
  17. package/dist/discord/events-handler/slash-register.js.map +1 -1
  18. package/dist/discord/events-handler/starter.d.ts.map +1 -1
  19. package/dist/discord/events-handler/starter.js +7 -19
  20. package/dist/discord/events-handler/starter.js.map +1 -1
  21. package/dist/discord/functions/anticrash.d.ts +2 -1
  22. package/dist/discord/functions/anticrash.d.ts.map +1 -1
  23. package/dist/discord/functions/anticrash.js +5 -4
  24. package/dist/discord/functions/anticrash.js.map +1 -1
  25. package/dist/discord/functions/devLogs.d.ts.map +1 -1
  26. package/dist/discord/functions/devLogs.js +29 -23
  27. package/dist/discord/functions/devLogs.js.map +1 -1
  28. package/dist/discord/types/starter.d.ts +0 -3
  29. package/dist/discord/types/starter.d.ts.map +1 -1
  30. package/lib/discord/events-handler/events.ts +6 -6
  31. package/lib/discord/events-handler/login.ts +63 -47
  32. package/lib/discord/events-handler/prefix-register.ts +7 -7
  33. package/lib/discord/events-handler/prefix-responder.ts +1 -1
  34. package/lib/discord/events-handler/slash-register.ts +6 -6
  35. package/lib/discord/events-handler/starter.ts +3 -16
  36. package/lib/discord/functions/anticrash.ts +6 -5
  37. package/lib/discord/functions/devLogs.ts +31 -26
  38. package/lib/discord/types/starter.ts +0 -3
  39. package/package.json +1 -1
@@ -34,14 +34,12 @@ export interface BotOptions {
34
34
  }
35
35
  export interface SlashOptions {
36
36
  path: string;
37
- baseDir: any;
38
37
  global?: boolean;
39
38
  serverId?: string;
40
39
  logsId?: string;
41
40
  }
42
41
  export interface PrefixOptions {
43
42
  path: string;
44
- baseDir: any;
45
43
  prefix: string;
46
44
  global?: boolean;
47
45
  serverIds?: string[];
@@ -67,7 +65,6 @@ export interface AntiCrash {
67
65
  }
68
66
  export interface EventsOptions {
69
67
  path: string;
70
- baseDir: any;
71
68
  logsId?: string;
72
69
  recursive?: boolean;
73
70
  eventBlacklist?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"starter.d.ts","sourceRoot":"","sources":["../../../lib/discord/types/starter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEnC,MAAM,WAAW,UAAU;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QACH,OAAO,CAAC,EAAE;YACN,MAAM,EAAE,OAAO,CAAA;YACf,WAAW,EAAE,GAAG,CAAC;YACjB,UAAU,EAAE,MAAM,CAAC;YACnB,OAAO,CAAC,EAAE,MAAM,CAAC;SACpB,CAAC;QACF,QAAQ,CAAC,EAAE,OAAO,CAAA;KACrB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,Y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C,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC3B,GAAG,EAAE,UAAU,CAAC;IAChB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,SAAS,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC7B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAC7D"}
@@ -12,7 +12,7 @@ const validExtensions = ['.js', '.ts'];
12
12
 
13
13
  async function processEventFile(client: any, eventsOptions: EventsOptions, filePath: string) {
14
14
  try {
15
- const resolvedPath = resolve(eventsOptions.baseDir, filePath);
15
+ const resolvedPath = resolve(process.cwd(), filePath);
16
16
  const stats = await stat(resolvedPath);
17
17
 
18
18
 
@@ -57,7 +57,7 @@ async function processDirectory(client: any, eventsOptions: EventsOptions, direc
57
57
 
58
58
  export async function loadEvents(client: any, eventsOptions: EventsOptions) {
59
59
  try {
60
- const resolvedPath = resolve(eventsOptions.baseDir, eventsOptions.path);
60
+ const resolvedPath = resolve(process.cwd(), eventsOptions.path);
61
61
  const stats = await stat(resolvedPath);
62
62
  client.eventSize = 0;
63
63
 
@@ -69,7 +69,7 @@ export async function loadEvents(client: any, eventsOptions: EventsOptions) {
69
69
  console.log(`Invalid file or directory: ${resolvedPath}`);
70
70
  }
71
71
 
72
- const eventCount = await countEventFiles(eventsOptions.baseDir, eventsOptions.path, eventsOptions);
72
+ const eventCount = await countEventFiles(eventsOptions.path, eventsOptions);
73
73
  client.eventSize = eventCount;
74
74
  } catch (error) {
75
75
  console.error(`Error while loading events from path: ${eventsOptions.path}`);
@@ -77,10 +77,10 @@ export async function loadEvents(client: any, eventsOptions: EventsOptions) {
77
77
  }
78
78
  }
79
79
 
80
- async function countEventFiles(baseDir: string, filePath: string, eventsOptions: EventsOptions): Promise<number> {
80
+ async function countEventFiles(filePath: string, eventsOptions: EventsOptions): Promise<number> {
81
81
  let count = 0;
82
82
  try {
83
- const resolvedPath = resolve(baseDir, filePath);
83
+ const resolvedPath = resolve(process.cwd(), filePath);
84
84
  const stats = await stat(resolvedPath);
85
85
  if (!eventsOptions.recursive && stats.isDirectory()) {
86
86
  const filesInDirectory = await readdir(resolvedPath);
@@ -94,7 +94,7 @@ async function countEventFiles(baseDir: string, filePath: string, eventsOptions:
94
94
  const filesInDirectory = await readdir(resolvedPath);
95
95
  for (const item of filesInDirectory) {
96
96
  const itemPath = resolve(resolvedPath, item);
97
- count += await countEventFiles(baseDir, itemPath, eventsOptions);
97
+ count += await countEventFiles(itemPath, eventsOptions);
98
98
  }
99
99
  } else if (stats.isFile() && validExtensions.includes(extname(resolvedPath))) {
100
100
  count++;
@@ -1,105 +1,111 @@
1
1
  import { Client, Collection, Routes, DataResolver, ActivityType } from 'discord.js';
2
- import { BotOptions } from '../types/starter';
2
+ import { StarterOptions } from '../types/starter';
3
+ import { loadEvents } from './events';
4
+ import { loadPrefix } from './prefix-responder';
5
+ import { loadSlash } from './slash-responder';
6
+ import { readCommands } from './prefix-register';
3
7
  import * as path from 'path';
4
8
 
5
- export async function login(djs: Client, bot: BotOptions) {
9
+ export async function login(djs: Client, options: StarterOptions) {
6
10
 
7
11
  const botData = new Collection<string, string | string[]>();
8
12
 
9
13
  if (!djs) {
10
14
  throw new Error("\x1b[31mMissing client parameter. Please provide a valid Discord client.\x1b[0m");
11
15
  }
12
- if (bot.token) {
16
+ if (options.bot.token) {
13
17
  try {
14
- await djs.login(bot.token);
18
+ await djs.login(options.bot.token);
15
19
  } catch (error) {
16
20
  console.error("\x1b[31mInvalid token provided. Please provide a valid bot token\x1b[0m");
17
21
  process.exit(1);
18
22
  }
19
23
  }
20
24
  djs.on('ready', async () => {
21
- if (bot.name) djs.user?.setUsername(bot.name);
22
- if (bot.avatar) {
23
- const avatarPath = bot.avatar.startsWith('http') ? bot.avatar : path.join(process.cwd(), bot.avatar);
25
+ if (options.bot.name) djs.user?.setUsername(options.bot.name);
26
+ if (options.bot.avatar) {
27
+ const avatarPath = options.bot.avatar.startsWith('http') ?options. bot.avatar : path.join(process.cwd(), options.bot.avatar);
24
28
  await djs.user?.setAvatar(avatarPath);
25
29
  }
26
- if (bot.banner) {
30
+ if (options.bot.banner) {
27
31
  await djs.rest.patch(Routes.user(), {
28
- body: { banner: await DataResolver.resolveImage(bot.banner) },
32
+ body: { banner: await DataResolver.resolveImage(options.bot.banner) },
29
33
  });
30
34
  }
31
35
 
32
- if (bot.BotInfo?.botInvite) {
33
- botData.set('inviteURL', bot.BotInfo?.botInvite);
36
+ if (options.bot.BotInfo?.botInvite) {
37
+ botData.set('inviteURL', options.bot.BotInfo?.botInvite);
34
38
  }
35
- if (bot.BotInfo && bot.BotInfo.perms) {
36
- botData.set('permissions', bot.BotInfo.perms);
39
+ if (options.bot.BotInfo && options.bot.BotInfo.perms) {
40
+ botData.set('permissions', options.bot.BotInfo.perms);
37
41
  }
38
- if (bot.BotInfo && bot.BotInfo.partners) {
39
- botData.set('partners', bot.BotInfo.partners);
42
+ if (options.bot.BotInfo && options.bot.BotInfo.partners) {
43
+ botData.set('partners', options.bot.BotInfo.partners);
40
44
  }
41
- if (bot.BotInfo && bot.BotInfo.ownerId) {
42
- botData.set('ownerId', bot.BotInfo.ownerId);
45
+ if (options.bot.BotInfo && options.bot.BotInfo.ownerId) {
46
+ botData.set('ownerId', options.bot.BotInfo.ownerId);
43
47
  }
44
- if (bot.BotInfo && bot.BotInfo.serverId) {
45
- botData.set('serverId', bot.BotInfo.serverId);
48
+ if (options.bot.BotInfo && options.bot.BotInfo.serverId) {
49
+ botData.set('serverId', options.bot.BotInfo.serverId);
46
50
  }
47
- if (bot.BotInfo && bot.BotInfo.serverInvite) {
48
- botData.set('serverInvite', bot.BotInfo.serverInvite);
51
+ if (options.bot.BotInfo && options.bot.BotInfo.serverInvite) {
52
+ botData.set('serverInvite', options.bot.BotInfo.serverInvite);
49
53
  }
50
54
 
51
- if (bot.logs?.terminal) {
52
- const { terminalLogs } = require('../functions/terminal');
53
- terminalLogs(djs, bot);
55
+ if (options.events) {
56
+ await loadEvents(djs, options.events);
54
57
  }
55
-
56
- if (bot.logs?.devLogs?.enable) {
57
- const { devLogger } = require('../functions/devLogs');
58
- devLogger(bot.logs.devLogs);
58
+ if (options.prefix) {
59
+ await readCommands(djs, options.prefix)
60
+ await loadPrefix(djs, options.prefix);
59
61
  }
62
+ if (options.slash && options.bot.token) {
63
+ await loadSlash(djs, options.bot?.token, options.slash);
64
+ }
65
+
60
66
 
61
- const userChosenType = bot.Status?.type || 3;
62
- if (bot.Status?.activities) {
63
- if (bot.Status.activities.length >= 1) {
64
- const initialActivity = bot.Status.activities[0];
65
- if (bot.Status.state === 'idle' || bot.Status.state === 'online' || bot.Status.state === 'dnd' || bot.Status.state === 'invisible') {
67
+ const userChosenType = options.bot.Status?.type || 3;
68
+ if (options.bot.Status?.activities) {
69
+ if (options.bot.Status.activities.length >= 1) {
70
+ const initialActivity = options.bot.Status.activities[0];
71
+ if (options.bot.Status.state === 'idle' || options.bot.Status.state === 'online' || options.bot.Status.state === 'dnd' || options.bot.Status.state === 'invisible') {
66
72
  djs.user?.setPresence({
67
73
  activities: [{ name: initialActivity, type: userChosenType }],
68
- status: bot.Status.state,
74
+ status: options.bot.Status.state,
69
75
  });
70
- } else if (bot.Status.state === 'Streaming') {
76
+ } else if (options.bot.Status.state === 'Streaming') {
71
77
  djs.user?.setActivity({
72
78
  name: initialActivity,
73
79
  type: ActivityType.Streaming,
74
80
  url: 'https://www.twitch.tv/discord'
75
81
  });
76
82
  } else {
77
- throw new Error('Invalid bot Status.');
83
+ throw new Error('\x1b[33m%sInvalid bot Status.\x1b[0m');
78
84
  }
79
85
  }
80
86
 
81
- if (bot.Status?.activities.length > 1) {
87
+ if (options.bot.Status?.activities.length > 1) {
82
88
  let delay = 60000;
83
- if (bot.Status.delay !== undefined) {
84
- if (bot.Status.delay < 60000) {
85
- throw new Error('Delay must be at least 1 minute.');
89
+ if (options.bot.Status.delay !== undefined) {
90
+ if (options.bot.Status.delay < 60000) {
91
+ throw new Error('\x1b[33m%sDelay must be at least 1 minute.\x1b[0m');
86
92
  }
87
- delay = bot.Status.delay;
93
+ delay = options.bot.Status.delay;
88
94
  }
89
95
  setInterval(() => {
90
96
  try {
91
- const randomActivity: string | undefined = bot.Status?.activities?.[Math.floor(Math.random() * bot.Status.activities?.length)];
97
+ const randomActivity: string | undefined = options.bot.Status?.activities?.[Math.floor(Math.random() * options.bot.Status.activities?.length)];
92
98
 
93
- if (randomActivity && bot.Status?.state === 'Streaming') {
99
+ if (randomActivity && options.bot.Status?.state === 'Streaming') {
94
100
  djs.user?.setActivity({
95
101
  name: randomActivity,
96
102
  type: ActivityType.Streaming,
97
103
  url: 'https://www.twitch.tv/discord'
98
104
  });
99
- } if (randomActivity && bot.Status?.state !== 'Streaming') {
105
+ } if (randomActivity && options.bot.Status?.state !== 'Streaming') {
100
106
  djs.user?.setPresence({
101
107
  activities: [{ name: randomActivity, type: userChosenType }],
102
- status: bot.Status?.state,
108
+ status: options.bot.Status?.state,
103
109
  });
104
110
  }
105
111
  } catch (error) {
@@ -107,11 +113,21 @@ export async function login(djs: Client, bot: BotOptions) {
107
113
  }
108
114
  }, delay);
109
115
  }
110
- } else if (bot.Status?.activities !== undefined){
111
- throw new Error('Activities array must be provided.');
116
+ } else if (options.bot.Status?.activities !== undefined){
117
+ throw new Error('\x1b[33m%sActivities array must be provided.\x1b[0m');
112
118
  }
113
119
 
114
120
 
121
+ if (options.bot.logs?.terminal) {
122
+ const { terminalLogs } = require('../functions/terminal');
123
+ await terminalLogs(djs, options.bot);
124
+ }
125
+
126
+ if (options.bot.logs?.devLogs?.enable) {
127
+ const { devLogger } = require('../functions/devLogs');
128
+ await devLogger(options.bot.logs.devLogs);
129
+ }
130
+
115
131
  (djs as any).botData = botData;
116
132
  });
117
133
  }
@@ -7,11 +7,11 @@ export const commands = new Collection<string, Command>();
7
7
  export const aliases = new Collection<string, string>();
8
8
  export const commandNames = new Set<string>();
9
9
 
10
- export async function readCommands(client: any, prefix: { baseDir: any; path: string }): Promise<number> {
10
+ export async function readCommands(client: any, prefix: { path: string }): Promise<number> {
11
11
  let prefixCommandCount = 0;
12
12
 
13
13
  try {
14
- const resolvedPath = resolve(prefix.baseDir, prefix.path);
14
+ const resolvedPath = resolve(process.cwd(), prefix.path);
15
15
  await fsPromises.access(resolvedPath);
16
16
  const files = await fsPromises.readdir(resolvedPath, { withFileTypes: true });
17
17
 
@@ -19,7 +19,7 @@ export async function readCommands(client: any, prefix: { baseDir: any; path: st
19
19
  const filePath = join(resolvedPath, file.name);
20
20
 
21
21
  if (file.isDirectory()) {
22
- prefixCommandCount += await readCommands(client, { baseDir: prefix.baseDir, path: filePath });
22
+ prefixCommandCount += await readCommands(client, { path: filePath });
23
23
  } else if (file.isFile()) {
24
24
  try {
25
25
  const commandModule = await import(filePath);
@@ -47,17 +47,17 @@ export async function readCommands(client: any, prefix: { baseDir: any; path: st
47
47
 
48
48
  prefixCommandCount++;
49
49
  }
50
- } catch (error) {
50
+ } catch (error: any) {
51
51
  console.error(`Error in file: ${filePath}`);
52
- console.error(error);
52
+ console.error(error.message);
53
53
  }
54
54
  }
55
55
  }
56
56
  client.prefixSize = prefixCommandCount;
57
57
  return prefixCommandCount;
58
- } catch (error) {
58
+ } catch (error: any) {
59
59
  console.error(`Error reading directory: ${prefix.path}`);
60
- console.error(error);
60
+ console.error(error.message);
61
61
  return 0;
62
62
  }
63
63
  }
@@ -126,7 +126,7 @@ async function handleMessageCreate(message: Message, prefix: PrefixOptions): Pro
126
126
 
127
127
  export async function loadPrefix(client: Client, prefix: PrefixOptions): Promise<void> {
128
128
  if (!prefix.prefix) {
129
- throw new Error("No command prefix provided. Please provide a command prefix.");
129
+ throw new Error("\x1b[33m%sNo 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,14 +8,14 @@ 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("Please provide valid bot token to register slash commands.");
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>();
15
15
  const rest = new REST({ version: '10' }).setToken(token);
16
16
 
17
17
  try {
18
- const resolvedPath = path.join(slash.baseDir, slash.path);
18
+ const resolvedPath = path.join(process.cwd(), slash.path);
19
19
  const dirents = await readdir(resolvedPath, { withFileTypes: true });
20
20
 
21
21
  for (const dirent of dirents) {
@@ -32,9 +32,9 @@ export async function registerSlashCommands(client: any, token: string, slash: S
32
32
  }
33
33
  slashCommands.set(command.data.name, command);
34
34
  }
35
- } catch (error) {
35
+ } catch (error: any) {
36
36
  console.error(`Error in file: ${path.join(folderPath, file)}`);
37
- console.error(error);
37
+ console.error(error.message);
38
38
  }
39
39
  }
40
40
  } else {
@@ -46,9 +46,9 @@ export async function registerSlashCommands(client: any, token: string, slash: S
46
46
  }
47
47
  slashCommands.set(command.data.name, command);
48
48
  }
49
- } catch (error) {
49
+ } catch (error: any) {
50
50
  console.error(`Error in file: ${path.join(resolvedPath, dirent.name)}`);
51
- console.error(error);
51
+ console.error(error.message);
52
52
  }
53
53
  }
54
54
  }
@@ -1,10 +1,7 @@
1
1
  import { StarterOptions, StarterInterface } from '../types/utils';
2
- import { loadEvents } from './events';
3
- import { loadPrefix } from './prefix-responder';
4
- import { loadSlash } from './slash-responder';
5
2
  import { mongoConnect, getDb, verseConnect } from '../functions/utils';
6
3
  import { login } from './login';
7
- import { readCommands } from './prefix-register';
4
+ import { AntiCrash } from '../functions/anticrash';
8
5
 
9
6
  export class Starter implements StarterInterface {
10
7
  async start(djs: any, options: StarterOptions): Promise<any> {
@@ -13,17 +10,7 @@ export class Starter implements StarterInterface {
13
10
 
14
11
  try {
15
12
  if (options.bot) {
16
- await login(djs, options.bot);
17
- }
18
- if (options.events) {
19
- await loadEvents(djs, options.events);
20
- }
21
- if (options.prefix) {
22
- await readCommands(djs, options.prefix)
23
- await loadPrefix(djs, options.prefix);
24
- }
25
- if (options.slash && options.bot.token) {
26
- await loadSlash(djs, options.bot?.token, options.slash);
13
+ await login(djs, options);
27
14
  }
28
15
  if (options.bot?.Database?.mongo) {
29
16
  await mongoConnect(options.bot.Database.mongo.mongoURI, options.bot.Database.mongo.dbName || 'djshandler');
@@ -33,7 +20,7 @@ export class Starter implements StarterInterface {
33
20
  verseDb = await verseConnect(options.bot.Database.verse);
34
21
  }
35
22
  if (options.anticrash?.enable) {
36
-
23
+ await AntiCrash(djs, options)
37
24
  }
38
25
  } catch (error: any) {
39
26
  console.error('An error occurred during bot startup:', error.message);
@@ -1,11 +1,12 @@
1
1
  import { WebhookClient, EmbedBuilder } from 'discord.js';
2
+ import { StarterOptions } from '../types/starter';
2
3
 
3
- export async function AntiCrash(djs: any, options: any) {
4
+ export async function AntiCrash(djs: any, options: StarterOptions) {
4
5
  try {
5
- if (!options.AntiCrash.webhookURL) {
6
+ if (!options.anticrash?.webhookURL) {
6
7
  throw new Error('Please provide a valid webhook URL.');
7
8
  }
8
- const webhookClient = new WebhookClient({ url: options.AntiCrash.webhookURL });
9
+ const webhookClient = new WebhookClient({ url: options.anticrash.webhookURL });
9
10
 
10
11
  process.on('uncaughtException', (error: any) => {
11
12
  console.error('Uncaught Exception:');
@@ -21,7 +22,7 @@ export async function AntiCrash(djs: any, options: any) {
21
22
  .setColor('#FF0000')
22
23
  .setTimestamp();
23
24
 
24
- webhookClient.send({ content: options.AntiCrash?.mention || '', embeds: [embed] });
25
+ webhookClient.send({ content: options.anticrash?.mention || '', embeds: [embed] });
25
26
  }
26
27
  });
27
28
 
@@ -42,7 +43,7 @@ export async function AntiCrash(djs: any, options: any) {
42
43
  .setColor('#FF0000')
43
44
  .setTimestamp();
44
45
 
45
- webhookClient.send({ content: options.AntiCrash?.mention || '', embeds: [embed] });
46
+ webhookClient.send({ content: options.anticrash?.mention || '', embeds: [embed] });
46
47
  });
47
48
 
48
49
  } catch (error: any) {
@@ -7,7 +7,7 @@ export async function devLogger(devLogger: any): Promise<void> {
7
7
 
8
8
  const watchedExtensions = ['.js', '.json', '.txt', '.md', '.ts', '.tsx', '.jsx', '.html', '.css', '.py', '.verse'];
9
9
 
10
- const MAX_FIELD_VALUE_LENGTH = 1024;
10
+ const MAX_DESCRIPTION_LENGTH = 2048;
11
11
 
12
12
  const watchDirectory = (directory: string) => {
13
13
  fs.readdir(directory, (err, files) => {
@@ -51,38 +51,36 @@ export async function devLogger(devLogger: any): Promise<void> {
51
51
  return;
52
52
  }
53
53
 
54
- const embed = createEmbed(filePath, data);
55
- sendWebhook(embed);
54
+ const embeds = createEmbeds(filePath, data);
55
+ sendWebhooks(embeds);
56
56
  });
57
57
  };
58
58
 
59
- const createEmbed = (filePath: string, data: string) => {
60
- let changes = '```' + getFileType(filePath) + '\n' + data + '\n```';
59
+ const createEmbeds = (filePath: string, data: string) => {
60
+ const fileType = getFileType(filePath);
61
+ const formattedData = '```' + fileType + '\n' + data + '\n```';
61
62
 
62
- let changesChunks: string[] = [];
63
- while (changes.length > MAX_FIELD_VALUE_LENGTH) {
64
- changesChunks.push(changes.substring(0, MAX_FIELD_VALUE_LENGTH));
65
- changes = changes.substring(MAX_FIELD_VALUE_LENGTH);
66
- }
67
- changesChunks.push(changes);
68
-
69
- const embed = new EmbedBuilder()
70
- .setColor('#3498db')
71
- .setTitle('File Changed')
72
- .setDescription(`> - File: \`${filePath}\``)
73
- .setTimestamp();
63
+ const chunks = chunkString(formattedData, MAX_DESCRIPTION_LENGTH);
64
+ const embeds: EmbedBuilder[] = [];
74
65
 
75
- for (let i = 0; i < changesChunks.length; i++) {
76
- embed.addFields({ name: 'Changes:', value: changesChunks[i]});
66
+ for (const chunk of chunks) {
67
+ const embed = new EmbedBuilder()
68
+ .setColor('#3498db')
69
+ .setTitle('File Changed')
70
+ .setDescription(`File: \`${filePath}\`\n\n${chunk}`)
71
+ .setTimestamp();
72
+ embeds.push(embed);
77
73
  }
78
74
 
79
- return embed;
75
+ return embeds;
80
76
  };
81
77
 
82
- const sendWebhook = (embed: EmbedBuilder) => {
83
- webhook.send({ content: devLogger.mention || '' ,embeds: [embed] })
84
- .then()
85
- .catch((error) => console.error('Error Dev Logger Message', error));
78
+ const sendWebhooks = (embeds: EmbedBuilder[]) => {
79
+ for (const embed of embeds) {
80
+ webhook.send({ content: devLogger.mention || '', embeds: [embed] })
81
+ .then()
82
+ .catch((error) => console.error('Error Dev Logger Message', error));
83
+ }
86
84
  };
87
85
 
88
86
  const getFileType = (filePath: string): string => {
@@ -111,6 +109,13 @@ export async function devLogger(devLogger: any): Promise<void> {
111
109
  }
112
110
  };
113
111
 
114
- watchDirectory(devLogger.pathToWatch);
115
- }
112
+ const chunkString = (str: string, length: number) => {
113
+ const chunks = [];
114
+ for (let i = 0; i < str.length; i += length) {
115
+ chunks.push(str.substring(i, i + length));
116
+ }
117
+ return chunks;
118
+ };
116
119
 
120
+ watchDirectory(devLogger.pathToWatch);
121
+ }
@@ -36,7 +36,6 @@ export interface BotOptions {
36
36
 
37
37
  export interface SlashOptions {
38
38
  path: string;
39
- baseDir: any;
40
39
  global?: boolean;
41
40
  serverId?: string;
42
41
  logsId?: string;
@@ -44,7 +43,6 @@ export interface SlashOptions {
44
43
 
45
44
  export interface PrefixOptions {
46
45
  path: string;
47
- baseDir: any;
48
46
  prefix: string;
49
47
  global?: boolean;
50
48
  serverIds?: string[];
@@ -74,7 +72,6 @@ export interface AntiCrash{
74
72
 
75
73
  export interface EventsOptions {
76
74
  path: string;
77
- baseDir: any;
78
75
  logsId?: string;
79
76
  recursive?: boolean;
80
77
  eventBlacklist?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "djs-builder",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "Discord.js bot builder. Supports Ts and Js.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",