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,160 +0,0 @@
1
- import { readdir, stat } from 'fs/promises';
2
- import { resolve, join, extname } from 'path';
3
- import { EventsOptions, Event } from '../types/utils';
4
- import { logError } from '../functions/logger';
5
-
6
- const validExtensions = ['.js', '.ts'];
7
-
8
- export async function processEventFile(client: any, eventsOptions: EventsOptions, filePath: string) {
9
- try {
10
- const resolvedPath = resolve(process.cwd(), filePath);
11
- const stats = await stat(resolvedPath);
12
-
13
- if (stats.isFile() && validExtensions.includes(extname(resolvedPath))) {
14
- const event: Event = await import(resolvedPath);
15
- if (eventsOptions.eventBlacklist?.includes(resolvedPath)) {
16
- return;
17
- }
18
-
19
- let eventHandler: (...args: any[]) => Promise<void> = async (...args: any[]) => {
20
- if (event.initializer) {
21
- await new Promise(resolve => setTimeout(resolve, event.initializer));
22
- }
23
- await event.execute(...args, client);
24
- client.eventSize++;
25
-
26
- if (event.interval) {
27
- if (event.intervalId) clearInterval(event.intervalId);
28
- event.intervalId = setInterval(async () => {
29
- await event.execute(...args, client);
30
- client.eventSize++;
31
- }, event.interval);
32
- }
33
- };
34
-
35
- if (event.once) {
36
- client.once(event.name, eventHandler);
37
- } else {
38
- client.on(event.name, eventHandler);
39
- }
40
-
41
- if (event.maxExecution !== undefined) {
42
- eventHandler = await limitConcurrency(eventHandler, event.maxExecution);
43
- }
44
-
45
- if (event.retryAttempts !== undefined) {
46
- eventHandler = await withRetry(eventHandler, event.retryAttempts);
47
- }
48
- }
49
- } catch (error: any) {
50
- logError(`Error in event file: ${filePath}`);
51
- logError(error.message, error);
52
- }
53
- }
54
-
55
- export async function limitConcurrency(handler: (...args: any[]) => void, maxConcurrentExecutions: number): Promise<(...args: any[]) => Promise<void>> {
56
- let executing = 0;
57
- const queue: any[] = [];
58
-
59
- return async function(...args: any[]) {
60
- if (executing < maxConcurrentExecutions) {
61
- executing++;
62
- await handler(...args);
63
- executing--;
64
-
65
- if (queue.length > 0) {
66
- const next = queue.shift();
67
- next();
68
- }
69
- } else {
70
- queue.push(() => handler(...args));
71
- }
72
- };
73
- }
74
-
75
- export async function withRetry(handler: (...args: any[]) => Promise<void>, retryAttempts: number): Promise<(...args: any[]) => Promise<void>> {
76
- return async function(...args: any[]) {
77
- let attempts = 0;
78
- while (attempts < retryAttempts) {
79
- try {
80
- await handler(...args);
81
- return;
82
- } catch (error: any) {
83
- logError('Error executing event:');
84
- logError(error.message, error);
85
- attempts++;
86
- }
87
- }
88
- logError('Reached maximum retry attempts.');
89
- };
90
- }
91
-
92
- export async function processDirectory(client: any, eventsOptions: EventsOptions, directoryPath: string) {
93
- try {
94
- const filesInDirectory = await readdir(directoryPath);
95
- for (const file of filesInDirectory) {
96
- const filePath = join(directoryPath, file);
97
- const fileStats = await stat(filePath);
98
- if (fileStats.isDirectory() && eventsOptions.recursive) {
99
- await processDirectory(client, eventsOptions, filePath);
100
- } else if (fileStats.isFile()) {
101
- await processEventFile(client, eventsOptions, filePath);
102
- }
103
- }
104
- } catch (error: any) {
105
- logError(`Error while processing directory: ${directoryPath}`);
106
- logError(error.message, error);
107
- }
108
- }
109
-
110
- export async function loadEvents(client: any, eventsOptions: EventsOptions) {
111
- try {
112
- const resolvedPath = resolve(process.cwd(), eventsOptions.path);
113
- const stats = await stat(resolvedPath);
114
- client.eventSize = 0;
115
-
116
- if (stats.isDirectory()) {
117
- await processDirectory(client, eventsOptions, resolvedPath);
118
- } else if (stats.isFile()) {
119
- await processEventFile(client, eventsOptions, eventsOptions.path);
120
- } else {
121
- logError(`Invalid file or directory: ${resolvedPath}`);
122
- }
123
-
124
- const eventCount = await countEventFiles(eventsOptions.path, eventsOptions);
125
- client.eventSize = eventCount;
126
-
127
- } catch (error: any) {
128
- logError(`Error while loading events from path: ${eventsOptions.path}`);
129
- logError(error.message, error);
130
- }
131
- }
132
-
133
- export async function countEventFiles(filePath: string, eventsOptions: EventsOptions): Promise<number> {
134
- let count = 0;
135
- try {
136
- const resolvedPath = resolve(process.cwd(), filePath);
137
- const stats = await stat(resolvedPath);
138
- if (!eventsOptions.recursive && stats.isDirectory()) {
139
- const filesInDirectory = await readdir(resolvedPath);
140
- for (const item of filesInDirectory) {
141
- const itemPath = resolve(resolvedPath, item);
142
- if ((await stat(itemPath)).isFile() && validExtensions.includes(extname(itemPath))) {
143
- count++;
144
- }
145
- }
146
- } else if (stats.isDirectory() && eventsOptions.recursive) {
147
- const filesInDirectory = await readdir(resolvedPath);
148
- for (const item of filesInDirectory) {
149
- const itemPath = resolve(resolvedPath, item);
150
- count += await countEventFiles(itemPath, eventsOptions);
151
- }
152
- } else if (stats.isFile() && validExtensions.includes(extname(resolvedPath))) {
153
- count++;
154
- }
155
- } catch (error: any) {
156
- logError(`Error counting event files in directory: ${filePath}`);
157
- logError(error.message, error);
158
- }
159
- return count;
160
- }
@@ -1,265 +0,0 @@
1
- import { Collection, Routes, resolveImage, ActivityType, Client } from 'discord.js';
2
- import { StarterOptions } from '../types/starter';
3
- import { loadPrefix } from './prefix-responder';
4
- import { loadSlash } from './slash-responder';
5
- import { readCommands } from './prefix-register';
6
- import { GatewayIntentBits } from 'discord-api-types/v10';
7
- import { logError, logInfo, logWarning } from '../utils';
8
- import * as path from 'path';
9
- import fs from 'fs';
10
- import { autoSlashLoader } from './slashLoader';
11
- import { autoPrefixLoader } from './prefixLoader';
12
- import { autoEventLoader } from './eventLoader';
13
-
14
- export const botData = new Collection<string, string | string[]>();
15
-
16
- export async function login(djs: Client & { botData?: Collection<string, string | string[]>; botInfo?: any; ownerId?: string }, options: StarterOptions) {
17
-
18
- if (!djs) {
19
- throw new Error("⚠️ \x1b[31mMissing client parameter. Please provide a valid Discord client.\x1b[0m");
20
- }
21
-
22
- djs.on('rateLimit', (rateLimitInfo) => {
23
- logWarning(`Rate limit hit: ${rateLimitInfo.timeout}ms timeout for ${rateLimitInfo.limit} requests.`);
24
- logInfo(`Route: ${rateLimitInfo.route}`);
25
- });
26
-
27
- djs.on('error', (error) => {
28
- logError('An error occurred', error);
29
- });
30
-
31
- if (options.bot.token) {
32
- try {
33
- await djs.login(options.bot.token);
34
-
35
- if (options.bot?.token) botData.set('botToken', options.bot.token);
36
-
37
- const REQUIRED_INTENTS = {
38
- 'guildCreate': GatewayIntentBits.Guilds,
39
- 'guildUpdate': GatewayIntentBits.Guilds,
40
- 'guildDelete': GatewayIntentBits.Guilds,
41
- 'channelCreate': GatewayIntentBits.Guilds,
42
- 'channelUpdate': GatewayIntentBits.Guilds,
43
- 'channelDelete': GatewayIntentBits.Guilds,
44
- 'channelPinsUpdate': GatewayIntentBits.Guilds,
45
- 'threadCreate': GatewayIntentBits.Guilds,
46
- 'threadUpdate': GatewayIntentBits.Guilds,
47
- 'threadDelete': GatewayIntentBits.Guilds,
48
- 'threadListSync': GatewayIntentBits.Guilds,
49
- 'threadMemberUpdate': GatewayIntentBits.Guilds,
50
- 'threadMembersUpdate': GatewayIntentBits.Guilds,
51
- 'stageInstanceCreate': GatewayIntentBits.Guilds,
52
- 'stageInstanceUpdate': GatewayIntentBits.Guilds,
53
- 'stageInstanceDelete': GatewayIntentBits.Guilds,
54
- 'guildMemberAdd': GatewayIntentBits.GuildMembers,
55
- 'guildMemberUpdate': GatewayIntentBits.GuildMembers,
56
- 'guildMemberRemove': GatewayIntentBits.GuildMembers,
57
- 'guildAuditLogEntryCreate': GatewayIntentBits.GuildModeration,
58
- 'guildBanAdd': GatewayIntentBits.GuildModeration,
59
- 'guildBanRemove': GatewayIntentBits.GuildModeration,
60
- 'guildEmojisUpdate': GatewayIntentBits.GuildEmojisAndStickers,
61
- 'guildStickersUpdate': GatewayIntentBits.GuildEmojisAndStickers,
62
- 'guildIntegrationsUpdate': GatewayIntentBits.GuildIntegrations,
63
- 'integrationCreate': GatewayIntentBits.GuildIntegrations,
64
- 'integrationUpdate': GatewayIntentBits.GuildIntegrations,
65
- 'integrationDelete': GatewayIntentBits.GuildIntegrations,
66
- 'webhooksUpdate': GatewayIntentBits.GuildWebhooks,
67
- 'inviteCreate': GatewayIntentBits.GuildInvites,
68
- 'inviteDelete': GatewayIntentBits.GuildInvites,
69
- 'voiceStateUpdate': GatewayIntentBits.GuildVoiceStates,
70
- 'presenceUpdate': GatewayIntentBits.GuildPresences,
71
- 'messageCreate': GatewayIntentBits.GuildMessages | GatewayIntentBits.DirectMessages,
72
- 'messageUpdate': GatewayIntentBits.GuildMessages | GatewayIntentBits.DirectMessages,
73
- 'messageDelete': GatewayIntentBits.GuildMessages | GatewayIntentBits.DirectMessages,
74
- 'messageDeleteBulk': GatewayIntentBits.GuildMessages,
75
- 'messageReactionAdd': GatewayIntentBits.GuildMessageReactions,
76
- 'messageReactionRemove': GatewayIntentBits.GuildMessageReactions,
77
- 'messageReactionRemoveAll': GatewayIntentBits.GuildMessageReactions,
78
- 'messageReactionRemoveEmoji': GatewayIntentBits.GuildMessageReactions,
79
- 'typingStart': GatewayIntentBits.GuildMessageTyping,
80
- 'guildScheduledEventCreate': GatewayIntentBits.GuildScheduledEvents,
81
- 'guildScheduledEventUpdate': GatewayIntentBits.GuildScheduledEvents,
82
- 'guildScheduledEventDelete': GatewayIntentBits.GuildScheduledEvents,
83
- 'guildScheduledEventUserAdd': GatewayIntentBits.GuildScheduledEvents,
84
- 'guildScheduledEventUserRemove': GatewayIntentBits.GuildScheduledEvents,
85
- 'autoModerationRuleCreate': GatewayIntentBits.AutoModerationConfiguration,
86
- 'autoModerationRuleUpdate': GatewayIntentBits.AutoModerationConfiguration,
87
- 'autoModerationRuleDelete': GatewayIntentBits.AutoModerationConfiguration,
88
- 'autoModerationActionExecution': GatewayIntentBits.AutoModerationExecution,
89
- 'messagePollVoteAdd': GatewayIntentBits.GuildMessagePolls,
90
- 'messagePollVoteRemove': GatewayIntentBits.GuildMessagePolls
91
- };
92
-
93
- const missingIntents = new Set();
94
- const intents = Number(djs.options.intents.bitfield);
95
- for (const eventName of Object.keys((djs as any)._events)) {
96
- const requiredBit = REQUIRED_INTENTS[eventName as keyof typeof REQUIRED_INTENTS];
97
- if (!requiredBit) continue;
98
- if ((intents & requiredBit) === 0) {
99
- missingIntents.add(requiredBit);
100
- }
101
- }
102
-
103
- if (missingIntents.size > 0) {
104
- const EventNames: { [key: number]: string } = Object.fromEntries(
105
- Object.entries(GatewayIntentBits).map(([key, value]) => [value, key])
106
- );
107
-
108
- const missingIntentNames = [...missingIntents].map(bit => {
109
- return EventNames[bit as keyof typeof EventNames] ?? 'unknown';
110
- });
111
-
112
- logError(`Missing intents: ${missingIntentNames.join(', ')}`);
113
- }
114
-
115
- } catch (error: any) {
116
- logError("⚠️ \x1b[31mInvalid token provided. Please provide a valid bot token\x1b[0m", error);
117
- process.exit(1);
118
- }
119
- }
120
- djs.on('ready', async () => {
121
- if (options.bot.name) djs.user?.setUsername(options.bot.name);
122
- if (options.bot.avatar) {
123
- const avatarPath = options.bot.avatar.startsWith('http') ?options. bot.avatar : path.join(process.cwd(), options.bot.avatar);
124
- await djs.user?.setAvatar(avatarPath);
125
- }
126
- if (options.bot.banner) {
127
- const fileBuffer = fs.readFileSync(path.join(process.cwd(), options.bot.banner));
128
- const base64String = fileBuffer.toString('base64');
129
-
130
- await djs.rest.patch(Routes.user(), {
131
- body: { banner: await resolveImage(base64String) }
132
- });
133
- }
134
-
135
- djs.botInfo = djs.botInfo || {};
136
-
137
- if (options.bot.BotInfo) {
138
- if (options.bot.BotInfo.botInvite) {
139
- botData.set('inviteURL', options.bot.BotInfo.botInvite);
140
- djs.botInfo.inviteURL = options.bot.BotInfo.botInvite;
141
- }
142
-
143
- if (options.bot.BotInfo.perms) {
144
- botData.set('permissions', options.bot.BotInfo.perms);
145
- djs.botInfo.perms = options.bot.BotInfo.perms;
146
- }
147
-
148
- if (options.bot.BotInfo.partners) {
149
- botData.set('partners', options.bot.BotInfo.partners);
150
- djs.botInfo.partners = options.bot.BotInfo.partners;
151
- }
152
-
153
- if (options.bot.BotInfo.ownerId) {
154
- botData.set('ownerId', options.bot.BotInfo.ownerId);
155
- djs.ownerId = options.bot.BotInfo.ownerId;
156
- }
157
-
158
- if (options.bot.BotInfo.serverId) {
159
- botData.set('serverId', options.bot.BotInfo.serverId);
160
- djs.botInfo.serverId = options.bot.BotInfo.serverId;
161
- }
162
-
163
- if (options.bot.BotInfo.serverInvite) {
164
- botData.set('serverInvite', options.bot.BotInfo.serverInvite);
165
- djs.botInfo.serverInvite = options.bot.BotInfo.serverInvite;
166
- }
167
-
168
- if (options.bot.BotInfo.developers) {
169
- botData.set('developers', options.bot.BotInfo.developers);
170
- djs.botInfo.developers = options.bot.BotInfo.developers;
171
- }
172
- }
173
-
174
- if (options.prefix) {
175
- await readCommands(djs, options.prefix)
176
- await loadPrefix(djs, options.prefix);
177
- if (options.prefix.path) botData.set('prefixPath', options.prefix.path);
178
-
179
- }
180
- if (options.slash && options.bot.token) {
181
- await loadSlash(djs, options.bot?.token, options.slash);
182
- botData.set('slashCommandPath', options.slash.path);
183
- if (options.slash.serverId) botData.set('serverIdSlash', options.slash.serverId);
184
- if (options.slash.global === true) botData.set('globalSlash', 'true');
185
- if (options.slash.global === false) botData.set('globalSlash', 'false');
186
- }
187
-
188
-
189
- const userChosenType = options.bot.Status ? options.bot.Status.type : 3;
190
- if (options.bot.Status?.activities) {
191
- if (options.bot.Status.activities.length >= 1) {
192
- const initialActivity = options.bot.Status.activities[0];
193
- if (options.bot.Status.state === 'idle' || options.bot.Status.state === 'online' || options.bot.Status.state === 'dnd' || options.bot.Status.state === 'invisible') {
194
- djs.user?.setPresence({
195
- activities: [{ name: initialActivity, type: userChosenType }],
196
- status: options.bot.Status.state,
197
- });
198
- } else if (options.bot.Status.state === 'Streaming') {
199
- djs.user?.setActivity({
200
- name: initialActivity,
201
- type: ActivityType.Streaming,
202
- url: 'https://www.twitch.tv/discord'
203
- });
204
- } else {
205
- throw new Error('⚠️ \x1b[31mInvalid bot Status.\x1b[0m');
206
- }
207
- }
208
-
209
- if (options.bot.Status?.activities.length > 1) {
210
- let delay = 60000;
211
- if (options.bot.Status.delay !== undefined) {
212
- if (options.bot.Status.delay < 60000) {
213
- logWarning('⚠️ Delay must be at least 1 minute.');
214
- }
215
- delay = options.bot.Status.delay;
216
- }
217
- setInterval(() => {
218
- try {
219
- const randomActivity: string | undefined = options.bot.Status?.activities?.[Math.floor(Math.random() * options.bot.Status.activities?.length)];
220
-
221
- if (randomActivity && options.bot.Status?.state === 'Streaming') {
222
- djs.user?.setActivity({
223
- name: randomActivity,
224
- type: ActivityType.Streaming,
225
- url: 'https://www.twitch.tv/discord'
226
- });
227
- } if (randomActivity && options.bot.Status?.state !== 'Streaming') {
228
- djs.user?.setPresence({
229
- activities: [{ name: randomActivity, type: userChosenType }],
230
- status: options.bot.Status?.state,
231
- });
232
- }
233
- } catch (error: any) {
234
- logError("Error setting activity: ${error}", error);
235
- }
236
- }, delay);
237
- }
238
- } else if (options.bot.Status?.activities !== undefined){
239
- throw new Error('⚠️ \x1b[31mActivities array must be provided.\x1b[0m');
240
- }
241
-
242
-
243
- if (options.bot.logs?.terminal) {
244
- const { terminalLogs } = require('../functions/terminal');
245
- await terminalLogs(djs, options.bot);
246
- }
247
-
248
- if (options.bot.logs?.devLogs?.enable) {
249
- const { devLogger } = require('../functions/devLogs');
250
- await devLogger(options.bot.logs.devLogs);
251
- }
252
-
253
- (djs as any).botData = botData;
254
-
255
- if (options.slash?.autoLoader?.enable) {
256
- autoSlashLoader(djs, options.slash?.autoLoader?.DEBOUNCE_DELAY);
257
- }
258
- if (options.prefix?.autoLoader?.enable) {
259
- autoPrefixLoader(djs, options.prefix?.autoLoader?.DEBOUNCE_DELAY);
260
- }
261
- if (options.events?.autoLoader?.enable) {
262
- autoEventLoader(djs, options.events?.autoLoader?.DEBOUNCE_DELAY, options.events);
263
- }
264
- });
265
- }
@@ -1,117 +0,0 @@
1
- import { Collection } from 'discord.js';
2
- import { promises as fsPromises } from 'fs';
3
- import { join, resolve } from 'path';
4
- import { Command } from '../types/utils';
5
- import { logError } from '../functions/logger';
6
-
7
- export const commands = new Collection<string, Command>();
8
- export const aliases = new Collection<string, string>();
9
- export const commandNames = new Set<string>();
10
-
11
- export async function readCommands(client: any, prefix: { path: string }): Promise<Array<{
12
- name: string;
13
- usage: string | undefined;
14
- description: string | undefined;
15
- aliases: string[] | undefined;
16
- cooldown: number | undefined;
17
- developer: boolean | undefined;
18
- owner: boolean | undefined;
19
- fastUse: boolean | undefined;
20
- botPerms: string[] | undefined;
21
- userPerms: string[] | undefined;
22
- category: string | undefined;
23
- accessLevel: string | undefined;
24
- method?: (...args: any[]) => void;
25
- }>> {
26
- const commandDetails: Array<{
27
- name: string;
28
- usage: string | undefined;
29
- description: string | undefined;
30
- aliases: string[] | undefined;
31
- cooldown: number | undefined;
32
- developer: boolean | undefined;
33
- owner: boolean | undefined;
34
- fastUse: boolean | undefined;
35
- botPerms: string[] | undefined;
36
- userPerms: string[] | undefined;
37
- category: string | undefined;
38
- accessLevel: string | undefined;
39
- method?: (...args: any[]) => void;
40
- }> = [];
41
-
42
- try {
43
- const resolvedPath = resolve(process.cwd(), prefix.path);
44
- await fsPromises.access(resolvedPath);
45
- const files = await fsPromises.readdir(resolvedPath, { withFileTypes: true });
46
-
47
- for (const file of files) {
48
- const filePath = join(resolvedPath, file.name);
49
-
50
- if (file.isDirectory()) {
51
- const subCommandDetails = await readCommands(client, { path: filePath });
52
- commandDetails.push(...subCommandDetails);
53
- } else if (file.isFile()) {
54
- try {
55
- const commandModule = await import(filePath);
56
- const command: Command = commandModule.default || commandModule;
57
-
58
- if (command && (command.execute || command.run)) {
59
- const method = command.execute ? command.execute : command.run
60
- const defaultCommand: Command = {
61
- description: "No description provided.",
62
- cooldown: undefined,
63
- usage: "No usage information provided.",
64
- aliases: [],
65
- developer: false,
66
- owner: false,
67
- fastUse: false,
68
- botPerms: [],
69
- userPerms: [],
70
- category: "Uncategorized",
71
- accessLevel: undefined,
72
- ...command,
73
- method
74
- };
75
-
76
- commands.set(defaultCommand.name, defaultCommand);
77
- commandNames.add(defaultCommand.name);
78
-
79
- if (defaultCommand.aliases && Array.isArray(defaultCommand.aliases)) {
80
- defaultCommand.aliases.forEach(alias => {
81
- aliases.set(alias, defaultCommand.name);
82
- commandNames.add(alias);
83
- });
84
- }
85
-
86
- commandDetails.push({
87
- name: defaultCommand.name,
88
- usage: defaultCommand.usage || 'No usage information provided.',
89
- description: defaultCommand.description || 'No description provided.',
90
- aliases: defaultCommand.aliases || [],
91
- cooldown: defaultCommand.cooldown,
92
- developer: defaultCommand.developer,
93
- owner: defaultCommand.owner,
94
- fastUse: defaultCommand.fastUse,
95
- botPerms: defaultCommand.botPerms,
96
- userPerms: defaultCommand.userPerms,
97
- category: defaultCommand.category || 'Uncategorized',
98
- accessLevel: defaultCommand.accessLevel,
99
- method
100
- });
101
- }
102
- } catch (error: any) {
103
- logError(`Error in file: ${filePath}`);
104
- logError(error.message, error);
105
- }
106
- }
107
- }
108
-
109
- client.prefixCommands = commandDetails;
110
- client.prefixSize = commandDetails.length;
111
- return commandDetails;
112
- } catch (error: any) {
113
- logError(`⚠️ Error reading directory: ${prefix.path}`);
114
- logError(error.message, error);
115
- return [];
116
- }
117
- }