djs-builder 0.5.31 → 0.5.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tsbuildinfo +1 -1
- package/dist/discord/events-handler/eventLoader.d.ts +2 -1
- package/dist/discord/events-handler/eventLoader.d.ts.map +1 -1
- package/dist/discord/events-handler/eventLoader.js +23 -0
- package/dist/discord/events-handler/eventLoader.js.map +1 -1
- package/dist/discord/events-handler/login.d.ts.map +1 -1
- package/dist/discord/events-handler/login.js +12 -0
- package/dist/discord/events-handler/login.js.map +1 -1
- package/dist/discord/events-handler/prefixLoader.d.ts +2 -1
- package/dist/discord/events-handler/prefixLoader.d.ts.map +1 -1
- package/dist/discord/events-handler/prefixLoader.js +23 -0
- package/dist/discord/events-handler/prefixLoader.js.map +1 -1
- package/dist/discord/events-handler/slash-responder.js +4 -4
- package/dist/discord/events-handler/slash-responder.js.map +1 -1
- package/dist/discord/events-handler/slashLoader.d.ts +2 -1
- package/dist/discord/events-handler/slashLoader.d.ts.map +1 -1
- package/dist/discord/events-handler/slashLoader.js +23 -0
- package/dist/discord/events-handler/slashLoader.js.map +1 -1
- package/dist/discord/games/X-O.d.ts +20 -0
- package/dist/discord/games/X-O.d.ts.map +1 -0
- package/dist/discord/games/X-O.js +166 -0
- package/dist/discord/games/X-O.js.map +1 -0
- package/dist/discord/games/rps.d.ts +21 -0
- package/dist/discord/games/rps.d.ts.map +1 -0
- package/dist/discord/games/rps.js +99 -0
- package/dist/discord/games/rps.js.map +1 -0
- package/dist/discord/types/starter.d.ts +12 -0
- package/dist/discord/types/starter.d.ts.map +1 -1
- package/dist/discord/utils.d.ts.map +1 -1
- package/dist/discord/utils.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/lib/discord/events-handler/eventLoader.ts +29 -1
- package/lib/discord/events-handler/login.ts +13 -0
- package/lib/discord/events-handler/prefixLoader.ts +31 -2
- package/lib/discord/events-handler/slash-responder.ts +4 -4
- package/lib/discord/events-handler/slashLoader.ts +29 -1
- package/lib/discord/types/starter.ts +12 -0
- package/lib/discord/utils.ts +2 -1
- package/lib/index.ts +1 -1
- package/package.json +2 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Collection } from 'discord.js';
|
|
1
|
+
import { Client, Collection } from 'discord.js';
|
|
2
2
|
import { readdir } from 'fs/promises';
|
|
3
3
|
import { join, resolve, extname } from 'path';
|
|
4
4
|
import { commands, aliases, commandNames } from './prefix-register';
|
|
5
5
|
import { readCommands } from './prefix-register';
|
|
6
|
-
import { logError } from '../functions/logger';
|
|
6
|
+
import { logError, logInfo } from '../functions/logger';
|
|
7
7
|
import { botData } from './login';
|
|
8
|
+
import { watch } from 'fs';
|
|
8
9
|
const validExtensions = ['.js', '.ts'];
|
|
9
10
|
|
|
10
11
|
export async function prefixLoader(client: any): Promise<{ commands: Collection<string, any>; success: boolean }> {
|
|
@@ -52,3 +53,31 @@ export async function prefixLoader(client: any): Promise<{ commands: Collection<
|
|
|
52
53
|
return { commands: new Collection(), success: false };
|
|
53
54
|
}
|
|
54
55
|
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export function autoPrefixLoader(client: Client, DEBOUNCE_DELAY: number = 10000) {
|
|
59
|
+
|
|
60
|
+
const slashPath = botData.get('slashCommandPath') as string;
|
|
61
|
+
const commandPath = resolve(process.cwd(), slashPath);
|
|
62
|
+
|
|
63
|
+
let debounceTimer: NodeJS.Timeout | null = null;
|
|
64
|
+
|
|
65
|
+
const handleReload = async () => {
|
|
66
|
+
if (debounceTimer) {
|
|
67
|
+
clearTimeout(debounceTimer);
|
|
68
|
+
}
|
|
69
|
+
debounceTimer = setTimeout(async () => {
|
|
70
|
+
await prefixLoader(client);
|
|
71
|
+
logInfo('Slash commands successfully reloaded after debounce.');
|
|
72
|
+
}, DEBOUNCE_DELAY);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
watch(commandPath, { recursive: false }, (eventType: any, filename: any) => {
|
|
76
|
+
if (filename && validExtensions.includes(extname(filename))) {
|
|
77
|
+
logInfo(`Detected ${eventType} in ${filename}, waiting for debouncing...`);
|
|
78
|
+
handleReload();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
logInfo('Started watching for changes in slash commands...');
|
|
83
|
+
}
|
|
@@ -14,7 +14,7 @@ export async function loadSlash(client: any, token: string, options: SlashOption
|
|
|
14
14
|
const interactionCooldowns: Collection<Snowflake, Collection<string, number>> = new Collection();
|
|
15
15
|
|
|
16
16
|
client.on('interactionCreate', async (interaction: Interaction) => {
|
|
17
|
-
if (!interaction.isCommand() || !interaction.
|
|
17
|
+
if (!interaction.isCommand() || !interaction.isChatInputCommand()) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -82,12 +82,12 @@ export async function loadSlash(client: any, token: string, options: SlashOption
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if (options.logsId) {
|
|
85
|
-
const channel = interaction.guild
|
|
85
|
+
const channel = interaction.guild?.channels.cache.get(options.logsId as string) as TextChannel;
|
|
86
86
|
if(channel) {
|
|
87
87
|
const userName = interaction.user.username;
|
|
88
88
|
const userId = interaction.user.id;
|
|
89
|
-
const serverName = interaction.guild
|
|
90
|
-
const serverId = interaction.guild
|
|
89
|
+
const serverName = interaction.guild?.name || 'Unknown Server';
|
|
90
|
+
const serverId = interaction.guild?.id || 'Unknown ID';
|
|
91
91
|
let messageLink = '';
|
|
92
92
|
|
|
93
93
|
if (interaction.channel) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Collection } from 'discord.js';
|
|
1
|
+
import { Client, Collection } from 'discord.js';
|
|
2
2
|
import { REST } from '@discordjs/rest';
|
|
3
3
|
import { Routes } from 'discord-api-types/v10';
|
|
4
4
|
import { readdir } from 'fs/promises';
|
|
5
5
|
import { resolve, extname } from 'path';
|
|
6
6
|
import { botData } from './login';
|
|
7
7
|
import { logError, logInfo } from '../functions/logger';
|
|
8
|
+
import { watch } from 'fs';
|
|
8
9
|
|
|
9
10
|
const validExtensions = ['.js', '.ts'];
|
|
10
11
|
|
|
@@ -74,3 +75,30 @@ export async function slashLoader(client: any): Promise<{ commands: Collection<s
|
|
|
74
75
|
return { commands: new Collection<string, any>(), success: false };
|
|
75
76
|
}
|
|
76
77
|
}
|
|
78
|
+
|
|
79
|
+
export function autoSlashLoader(client: Client, DEBOUNCE_DELAY: number = 10000) {
|
|
80
|
+
|
|
81
|
+
const slashPath = botData.get('slashCommandPath') as string;
|
|
82
|
+
const commandPath = resolve(process.cwd(), slashPath);
|
|
83
|
+
|
|
84
|
+
let debounceTimer: NodeJS.Timeout | null = null;
|
|
85
|
+
|
|
86
|
+
const handleReload = async () => {
|
|
87
|
+
if (debounceTimer) {
|
|
88
|
+
clearTimeout(debounceTimer);
|
|
89
|
+
}
|
|
90
|
+
debounceTimer = setTimeout(async () => {
|
|
91
|
+
await slashLoader(client);
|
|
92
|
+
logInfo('Slash commands successfully reloaded after debounce.');
|
|
93
|
+
}, DEBOUNCE_DELAY);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
watch(commandPath, { recursive: false }, (eventType: any, filename: any) => {
|
|
97
|
+
if (filename && validExtensions.includes(extname(filename))) {
|
|
98
|
+
logInfo(`Detected ${eventType} in ${filename}, waiting for debouncing...`);
|
|
99
|
+
handleReload();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
logInfo('Started watching for changes in slash commands...');
|
|
104
|
+
}
|
|
@@ -41,6 +41,10 @@ export interface SlashOptions {
|
|
|
41
41
|
global?: boolean;
|
|
42
42
|
serverId?: string;
|
|
43
43
|
logsId?: string;
|
|
44
|
+
autoLoader?: {
|
|
45
|
+
enable?: boolean;
|
|
46
|
+
DEBOUNCE_DELAY?: number;
|
|
47
|
+
}
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
export interface PrefixOptions {
|
|
@@ -54,6 +58,10 @@ export interface PrefixOptions {
|
|
|
54
58
|
}[];
|
|
55
59
|
similarity?: boolean;
|
|
56
60
|
logsId?: string;
|
|
61
|
+
autoLoader?: {
|
|
62
|
+
enable?: boolean;
|
|
63
|
+
DEBOUNCE_DELAY?: number;
|
|
64
|
+
}
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
export interface MongoDbOptions{
|
|
@@ -86,6 +94,10 @@ export interface EventsOptions {
|
|
|
86
94
|
logsId?: string;
|
|
87
95
|
recursive?: boolean;
|
|
88
96
|
eventBlacklist?: string[];
|
|
97
|
+
autoLoader?: {
|
|
98
|
+
enable?: boolean;
|
|
99
|
+
DEBOUNCE_DELAY?: number;
|
|
100
|
+
}
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
export interface Event {
|
package/lib/discord/utils.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { loadSlash } from "./events-handler/slash-responder";
|
|
|
10
10
|
import { logError, logInfo, logSuccess, logWarning } from "./functions/logger";
|
|
11
11
|
import { Pagination } from "./builder/system/Pagination";
|
|
12
12
|
import { loadEvents, withRetry, processEventFile, processDirectory, limitConcurrency, countEventFiles } from "./events-handler/events";
|
|
13
|
+
|
|
13
14
|
export { Starter, ButtonManager, MenuManager, PermissionChecker, slashLoader, prefixLoader, eventLoader, readCommands, loadEvents,
|
|
14
15
|
loadSlash, loadPrefix, handleMessageCreate, processDirectory, countEventFiles, limitConcurrency, withRetry, registerSlashCommands,
|
|
15
|
-
|
|
16
|
+
processEventFile, logError, logInfo, logSuccess, logWarning, Pagination };
|
package/lib/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ import { Starter, ButtonManager, MenuManager, PermissionChecker, slashLoader, pr
|
|
|
33
33
|
|
|
34
34
|
export { Starter, ButtonManager, MenuManager, PermissionChecker, slashLoader, prefixLoader, eventLoader, readCommands, loadEvents,
|
|
35
35
|
loadSlash, loadPrefix, handleMessageCreate, processDirectory, countEventFiles, limitConcurrency, withRetry, registerSlashCommands,
|
|
36
|
-
processEventFile , logError, logInfo, logSuccess, logWarning};
|
|
36
|
+
processEventFile , logError, logInfo, logSuccess, logWarning };
|
|
37
37
|
export default { Starter, ButtonManager, MenuManager, PermissionChecker, slashLoader, prefixLoader, eventLoader, readCommands, loadEvents,
|
|
38
38
|
loadSlash, loadPrefix, handleMessageCreate, processDirectory, countEventFiles, limitConcurrency, withRetry, registerSlashCommands,
|
|
39
39
|
processEventFile, logError, logInfo, logSuccess, logWarning, Pagination };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "djs-builder",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.32",
|
|
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,6 +30,7 @@
|
|
|
30
30
|
"mongodb"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"@napi-rs/canvas": "^0.1.55",
|
|
33
34
|
"@types/figlet": "^1.5.8",
|
|
34
35
|
"cli-table": "^0.3.11",
|
|
35
36
|
"colorette": "^2.0.20",
|