djs-next 0.0.1
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.
Potentially problematic release.
This version of djs-next might be problematic. Click here for more details.
- package/README.md +250 -0
- package/assets/djs-next.png +0 -0
- package/bin/create-djs-next.js +78 -0
- package/dist/index.d.mts +161 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.js +1283 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1259 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
- package/src/client.ts +492 -0
- package/src/handlers/commandHandler.ts +139 -0
- package/src/handlers/componentHandler.ts +31 -0
- package/src/handlers/eventHandler.ts +37 -0
- package/src/handlers/taskHandler.ts +38 -0
- package/src/handlers/utils.ts +25 -0
- package/src/index.ts +10 -0
- package/src/plugins/dnxt.ts +418 -0
- package/src/templates/cjs.ts +54 -0
- package/src/templates/esm.ts +50 -0
- package/src/templates/ts.ts +53 -0
- package/src/test/client.test.ts +8 -0
- package/src/types.ts +94 -0
- package/src/utils/PaginationBuilder.ts +94 -0
- package/src/utils/configLoader.ts +27 -0
- package/src/utils/i18n.ts +57 -0
- package/src/utils/paginate.ts +90 -0
- package/src/utils/prompts.ts +76 -0
- package/test_payload.js +3 -0
- package/test_reply.js +4 -0
- package/tsconfig.json +16 -0
- package/tsup.config.ts +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="assets/djs-next.png" alt="djs-next logo" width="300" />
|
|
3
|
+
<h1>djs-next</h1>
|
|
4
|
+
<p><b>Discord Bots at Next.</b></p>
|
|
5
|
+
<p>A hyper-modern, production-ready framework for Discord.js featuring file-based routing, native DNXT developer tools, Hot Module Replacement (HMR), and built-in safety nets.</p>
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.org/package/djs-next)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<br />
|
|
12
|
+
|
|
13
|
+
## ✨ Features
|
|
14
|
+
|
|
15
|
+
- 📁 **Next.js File-Based Routing**: Auto-loads commands, events, components, and tasks natively. Supports Regex dynamic routes (e.g., `[id].ts` for components).
|
|
16
|
+
- 🛠️ **Native Developer Tools (`dnxt`)**: A comprehensive, built-in developer suite. Live JS evaluation, remote shell execution, and instant Hot-Module Reloading!
|
|
17
|
+
- 🔄 **Hot Module Replacement (HMR)**: Live-reload your commands, events, and logic on save without ever dropping your Discord Gateway connection.
|
|
18
|
+
- 🗄️ **Strict Database Interop**: Connect your ORM (Prisma, Mongoose) securely.
|
|
19
|
+
- 🌍 **Localization (i18n)**: Out-of-the-box native string translations.
|
|
20
|
+
- 🛡️ **Middleware Routing**: Global `beforeExecute` hooks for overarching permission checks and analytics.
|
|
21
|
+
- 🚦 **Persistent Cooldowns**: Connect custom cache adapters (like Redis) for global persistent cooldown tracking.
|
|
22
|
+
- 📄 **PaginationBuilder**: A built-in class for creating robust interactive pagination menus.
|
|
23
|
+
|
|
24
|
+
## 📦 Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install djs-next
|
|
28
|
+
```
|
|
29
|
+
*(Or use `pnpm`, `yarn`, or `bun`)*
|
|
30
|
+
|
|
31
|
+
## 🚀 Quick Start
|
|
32
|
+
|
|
33
|
+
The fastest way to start building is to use our powerful scaffolding tool. Open your terminal and run:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx djs-next init
|
|
37
|
+
```
|
|
38
|
+
This interactive CLI will instantly bootstrap a fully-configured **TypeScript**, **ESModule**, or **CommonJS** repository!
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 💻 Manual Setup
|
|
43
|
+
|
|
44
|
+
If you prefer to start manually, here's how to bootstrap `djs-next`:
|
|
45
|
+
|
|
46
|
+
### 1. The Entry Point (`index.js`)
|
|
47
|
+
```javascript
|
|
48
|
+
const { GatewayIntentBits, DJSNextClient } = require('djs-next');
|
|
49
|
+
const { PrismaClient } = require('@prisma/client'); // Optional Database
|
|
50
|
+
|
|
51
|
+
const db = new PrismaClient();
|
|
52
|
+
|
|
53
|
+
const client = new DJSNextClient({
|
|
54
|
+
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
|
|
55
|
+
developers: ['YOUR_DISCORD_ID'], // Required for Developer Tools
|
|
56
|
+
|
|
57
|
+
// Explicit Framework Toggles
|
|
58
|
+
enableSlashCommands: true,
|
|
59
|
+
enableTextCommands: true,
|
|
60
|
+
enableMentionPrefix: true,
|
|
61
|
+
enableNoPrefix: false,
|
|
62
|
+
prefixes: ['!', '?'], // Standard prefixes
|
|
63
|
+
|
|
64
|
+
// Connect your database (Mongoose, Prisma, etc.)
|
|
65
|
+
db: db,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// Enable Hot-Module Reloading (HMR) for dev
|
|
70
|
+
client.enableHMR();
|
|
71
|
+
|
|
72
|
+
// Enable the Native Developer Tools (Prefix must be exactly 'dnxt' or 'nxt')
|
|
73
|
+
client.enableDevTools('nxt');
|
|
74
|
+
|
|
75
|
+
// Boot!
|
|
76
|
+
client.start(process.env.DISCORD_TOKEN);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 2. Creating a Command
|
|
80
|
+
Drop a file into `src/commands/ping.js`. The framework reads it and registers it for **both** Slash Commands AND normal text prefixes!
|
|
81
|
+
```javascript
|
|
82
|
+
/** @type {import('djs-next').FileCommand} */
|
|
83
|
+
module.exports = {
|
|
84
|
+
description: 'Replies with Pong!',
|
|
85
|
+
aliases: ['p'], // Works for text commands (e.g. !p)
|
|
86
|
+
cooldown: 5, // Automatically intercepts spammers
|
|
87
|
+
|
|
88
|
+
// Triggers on Slash Command: /ping
|
|
89
|
+
execute: async (interaction, client) => {
|
|
90
|
+
await interaction.reply('Pong! 🏓');
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
// Triggers on Text Prefix: !ping, @Bot ping, or no-prefix ping
|
|
94
|
+
executeText: async (message, args, client) => {
|
|
95
|
+
await message.reply('Pong from text! 🏓');
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 3. Dynamic Component Routing
|
|
101
|
+
Have a button with a custom ID like `ban_user_12345`? You don't need a massive switch statement. Just create `src/components/ban_user_[id].js`:
|
|
102
|
+
```javascript
|
|
103
|
+
/** @type {import('djs-next').FileComponent} */
|
|
104
|
+
module.exports = {
|
|
105
|
+
// Matches "ban_user_12345" and extracts the param dynamically!
|
|
106
|
+
customId: 'ban_user_[id]',
|
|
107
|
+
execute: async (interaction, client, params) => {
|
|
108
|
+
const targetId = params.id; // '12345'
|
|
109
|
+
await interaction.reply(`Banning user ${targetId}...`);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 4. Interactive Pagination
|
|
119
|
+
You no longer need to write complex collectors for simple pagination menus. `djs-next` ships with a `PaginationBuilder`:
|
|
120
|
+
```javascript
|
|
121
|
+
const { PaginationBuilder } = require('djs-next');
|
|
122
|
+
const { EmbedBuilder } = require('discord.js');
|
|
123
|
+
|
|
124
|
+
// Inside a command execute function:
|
|
125
|
+
const paginator = new PaginationBuilder()
|
|
126
|
+
.addPage(new EmbedBuilder().setDescription('Page 1'))
|
|
127
|
+
.addPage(new EmbedBuilder().setDescription('Page 2'))
|
|
128
|
+
.setTimeout(60000);
|
|
129
|
+
|
|
130
|
+
await paginator.build(interaction);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 🗄️ Database Integrations
|
|
136
|
+
|
|
137
|
+
Because `djs-next` uses a global `<DB>` generic, you can natively bind any popular database (like MongoDB Atlas, Supabase, Prisma, or PostgreSQL) directly into the framework core. It will propagate 100% type-safety to all your commands and events.
|
|
138
|
+
|
|
139
|
+
### MongoDB Atlas (using Mongoose)
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
// index.js
|
|
143
|
+
const mongoose = require('mongoose');
|
|
144
|
+
const { DJSNextClient, GatewayIntentBits } = require('djs-next');
|
|
145
|
+
|
|
146
|
+
// Connect to Atlas
|
|
147
|
+
mongoose.connect(process.env.MONGO_URI);
|
|
148
|
+
|
|
149
|
+
// Initialize DJSNext
|
|
150
|
+
const client = new DJSNextClient({
|
|
151
|
+
intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ],
|
|
152
|
+
db: mongoose
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
client.start(process.env.TOKEN);
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
// src/commands/profile.js
|
|
160
|
+
const UserSchema = require('../models/User.js');
|
|
161
|
+
|
|
162
|
+
/** @type {import('djs-next').FileCommand} */
|
|
163
|
+
module.exports = {
|
|
164
|
+
description: 'View your profile',
|
|
165
|
+
execute: async (interaction, client) => {
|
|
166
|
+
// client.db is your connected Mongoose instance
|
|
167
|
+
const user = await UserSchema.findOne({ discordId: interaction.user.id });
|
|
168
|
+
await interaction.reply(`You have ${user.coins} coins!`);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Supabase (PostgreSQL)
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
// index.js
|
|
177
|
+
const { createClient } = require('@supabase/supabase-js');
|
|
178
|
+
const { DJSNextClient, GatewayIntentBits } = require('djs-next');
|
|
179
|
+
|
|
180
|
+
const supabase = createClient('https://xyz.supabase.co', process.env.SUPABASE_KEY);
|
|
181
|
+
|
|
182
|
+
const client = new DJSNextClient({
|
|
183
|
+
intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ],
|
|
184
|
+
db: supabase
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
client.start(process.env.TOKEN);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
// src/commands/leaderboard.js
|
|
192
|
+
/** @type {import('djs-next').FileCommand} */
|
|
193
|
+
module.exports = {
|
|
194
|
+
description: 'View the leaderboard',
|
|
195
|
+
execute: async (interaction, client) => {
|
|
196
|
+
// client.db is your Supabase client
|
|
197
|
+
const { data, error } = await client.db.from('users').select('*').order('level', { ascending: false });
|
|
198
|
+
await interaction.reply(`Top user is: ${data[0].username}`);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 🛠️ The Developer Suite (`dnxt`)
|
|
206
|
+
|
|
207
|
+
`djs-next` comes with a hyper-advanced, native developer suite. By providing your Discord User ID in the `developers` array and calling `client.enableDevTools('nxt')` (or `'dnxt'`), you can execute backend logic live directly from Discord!
|
|
208
|
+
|
|
209
|
+
***(Make sure your bot has the `MessageContent` Intent enabled!)***
|
|
210
|
+
|
|
211
|
+
| Command | Action |
|
|
212
|
+
| --- | --- |
|
|
213
|
+
| `dnxt js <code>` | Evaluates Javascript live with async resolution. |
|
|
214
|
+
| `dnxt sh <cmd>` | Executes raw shell/terminal code on your host machine. |
|
|
215
|
+
| `dnxt git <cmd>` | Executes standard git workflows (e.g., `dnxt git pull`). |
|
|
216
|
+
| `dnxt in <channelId> <text>`| Injects a message seamlessly into a specific channel as the bot. |
|
|
217
|
+
| `dnxt reload <target>` | Hot-swaps the internal cache. (e.g., `dnxt reload commands`, `dnxt reload all`). |
|
|
218
|
+
| `dnxt debug <cmd>` | Executes Javascript while explicitly tracking the Node.js V8 Heap Memory Delta. |
|
|
219
|
+
| `dnxt sync` | Manually forces a global Discord Slash Command synchronization. |
|
|
220
|
+
| `dnxt restart` | Safely spawns a new background process and shuts down the current one. |
|
|
221
|
+
| `dnxt stop` or `dnxt shutdown` | Fully disconnects the client and kills the Node process. |
|
|
222
|
+
| `dnxt` | Displays the Developer Dashboard tracking System RAM, Node Host status, and Process uptime. |
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## ⚙️ Configuration (`djs-next.config.js`)
|
|
227
|
+
|
|
228
|
+
At the root of your project, you can drop a config file to heavily control how `djs-next` acts:
|
|
229
|
+
|
|
230
|
+
```javascript
|
|
231
|
+
module.exports = {
|
|
232
|
+
devGuildId: 'YOUR_TESTING_SERVER_ID',
|
|
233
|
+
defaultLocale: 'en-US',
|
|
234
|
+
directories: {
|
|
235
|
+
commands: 'src/commands',
|
|
236
|
+
events: 'src/events',
|
|
237
|
+
components: 'src/components',
|
|
238
|
+
tasks: 'src/tasks',
|
|
239
|
+
locales: 'src/locales'
|
|
240
|
+
},
|
|
241
|
+
// Optional Redis or persistent cache adapter for cooldowns
|
|
242
|
+
cooldownAdapter: {
|
|
243
|
+
get: async (cmdId, userId) => { /* return timestamp or null */ },
|
|
244
|
+
set: async (cmdId, userId, expiration) => { /* save to db */ }
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## 📜 License
|
|
250
|
+
Released under the [MIT License](LICENSE).
|
|
Binary file
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const projectDir = process.cwd();
|
|
7
|
+
|
|
8
|
+
console.log('🚀 Welcome to create-djs-next! Scaffolding your project...\n');
|
|
9
|
+
|
|
10
|
+
const dirsToCreate = [
|
|
11
|
+
'src/commands',
|
|
12
|
+
'src/events',
|
|
13
|
+
'src/components',
|
|
14
|
+
'src/tasks',
|
|
15
|
+
'src/locales'
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
for (const dir of dirsToCreate) {
|
|
19
|
+
const dirPath = path.join(projectDir, dir);
|
|
20
|
+
if (!fs.existsSync(dirPath)) {
|
|
21
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
22
|
+
console.log(`✅ Created directory: ${dir}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const envContent = `DISCORD_TOKEN=your_token_here\nCLIENT_ID=your_client_id\nGUILD_ID=your_dev_guild_id`;
|
|
27
|
+
const envPath = path.join(projectDir, '.env');
|
|
28
|
+
if (!fs.existsSync(envPath)) {
|
|
29
|
+
fs.writeFileSync(envPath, envContent);
|
|
30
|
+
console.log('✅ Created .env file');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const indexContent = `const { GatewayIntentBits, DJSNextClient } = require('djs-next');
|
|
34
|
+
|
|
35
|
+
const client = new DJSNextClient({
|
|
36
|
+
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
|
|
37
|
+
developers: ['YOUR_DISCORD_USER_ID'],
|
|
38
|
+
clientId: process.env.CLIENT_ID,
|
|
39
|
+
|
|
40
|
+
// Framework Toggles
|
|
41
|
+
enableSlashCommands: true,
|
|
42
|
+
enableTextCommands: true,
|
|
43
|
+
enableMentionPrefix: true,
|
|
44
|
+
enableNoPrefix: false,
|
|
45
|
+
prefixes: ['!', '?'],
|
|
46
|
+
|
|
47
|
+
// Custom Middleware
|
|
48
|
+
middleware: (interactionOrMessage, client) => {
|
|
49
|
+
return true; // Return false to block execution
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
// Configuration
|
|
53
|
+
config: {
|
|
54
|
+
devGuildId: process.env.GUILD_ID,
|
|
55
|
+
locales: ['en'],
|
|
56
|
+
defaultLocale: 'en',
|
|
57
|
+
responses: {
|
|
58
|
+
developerOnly: '⛔ This command is restricted to bot developers.',
|
|
59
|
+
guildOnly: '⛔ This command can only be used inside a server.',
|
|
60
|
+
cooldown: '⏳ You are on cooldown! Please wait {time}.',
|
|
61
|
+
missingPerms: '⛔ You lack permissions.',
|
|
62
|
+
errorBoundary: '❌ An unexpected error occurred.',
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
client.enableHMR();
|
|
68
|
+
client.enableDevTools('dnxt'); // Enable 'dnxt' prefix dev commands
|
|
69
|
+
client.start(process.env.DISCORD_TOKEN);
|
|
70
|
+
\`;
|
|
71
|
+
|
|
72
|
+
const indexPath = path.join(projectDir, 'index.js');
|
|
73
|
+
if (!fs.existsSync(indexPath)) {
|
|
74
|
+
fs.writeFileSync(indexPath, indexContent);
|
|
75
|
+
console.log('✅ Created index.js');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log('\n🎉 Scaffolding complete! Run \`npm install djs-next\` and start coding!');
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { ApplicationCommandOptionData, PermissionResolvable, ChatInputCommandInteraction, Client, Message, AutocompleteInteraction, MessageComponentInteraction, ModalSubmitInteraction, ClientOptions, Interaction, ClientEvents, Collection, CommandInteraction, EmbedBuilder } from 'discord.js';
|
|
2
|
+
export * from 'discord.js';
|
|
3
|
+
|
|
4
|
+
interface CooldownAdapter {
|
|
5
|
+
get(commandId: string, userId: string): Promise<number | null> | number | null;
|
|
6
|
+
set(commandId: string, userId: string, expirationTime: number): Promise<void> | void;
|
|
7
|
+
}
|
|
8
|
+
interface DJSNextConfig {
|
|
9
|
+
devGuildId?: string;
|
|
10
|
+
errorLogChannelId?: string;
|
|
11
|
+
responses?: {
|
|
12
|
+
developerOnly?: string | null;
|
|
13
|
+
guildOnly?: string | null;
|
|
14
|
+
cooldown?: string | null;
|
|
15
|
+
missingPerms?: string | null;
|
|
16
|
+
errorBoundary?: string | null;
|
|
17
|
+
};
|
|
18
|
+
locales?: string[];
|
|
19
|
+
defaultLocale?: string;
|
|
20
|
+
directories?: {
|
|
21
|
+
commands?: string;
|
|
22
|
+
events?: string;
|
|
23
|
+
components?: string;
|
|
24
|
+
tasks?: string;
|
|
25
|
+
locales?: string;
|
|
26
|
+
};
|
|
27
|
+
cooldownAdapter?: CooldownAdapter;
|
|
28
|
+
}
|
|
29
|
+
interface DJSNextClientOptions extends ClientOptions {
|
|
30
|
+
commandsDir?: string;
|
|
31
|
+
eventsDir?: string;
|
|
32
|
+
componentsDir?: string;
|
|
33
|
+
tasksDir?: string;
|
|
34
|
+
clientId?: string;
|
|
35
|
+
guildId?: string;
|
|
36
|
+
developers?: string[];
|
|
37
|
+
prefixes?: string[] | string;
|
|
38
|
+
enableSlashCommands?: boolean;
|
|
39
|
+
enableTextCommands?: boolean;
|
|
40
|
+
enableMentionPrefix?: boolean | string[];
|
|
41
|
+
enableNoPrefix?: boolean | string[];
|
|
42
|
+
middleware?: (interaction: Interaction | Message, client: Client) => Promise<boolean> | boolean;
|
|
43
|
+
config?: DJSNextConfig;
|
|
44
|
+
db?: any;
|
|
45
|
+
}
|
|
46
|
+
interface FileTask<DB = any> {
|
|
47
|
+
filepath?: string;
|
|
48
|
+
interval: number;
|
|
49
|
+
execute: (client: Client & {
|
|
50
|
+
db: DB;
|
|
51
|
+
t: Function;
|
|
52
|
+
config: DJSNextConfig;
|
|
53
|
+
}) => Promise<void> | void;
|
|
54
|
+
}
|
|
55
|
+
interface FileCommand<DB = any> {
|
|
56
|
+
filepath?: string;
|
|
57
|
+
description: string;
|
|
58
|
+
options?: ApplicationCommandOptionData[];
|
|
59
|
+
cooldown?: number;
|
|
60
|
+
userPermissions?: PermissionResolvable[];
|
|
61
|
+
botPermissions?: PermissionResolvable[];
|
|
62
|
+
developerOnly?: boolean;
|
|
63
|
+
guildOnly?: boolean;
|
|
64
|
+
aliases?: string[];
|
|
65
|
+
preconditions?: string[];
|
|
66
|
+
execute?: (interaction: ChatInputCommandInteraction, client: Client & {
|
|
67
|
+
db: DB;
|
|
68
|
+
t: Function;
|
|
69
|
+
config: DJSNextConfig;
|
|
70
|
+
}) => Promise<void> | void;
|
|
71
|
+
executeText?: (message: Message, args: string[], client: Client & {
|
|
72
|
+
db: DB;
|
|
73
|
+
t: Function;
|
|
74
|
+
config: DJSNextConfig;
|
|
75
|
+
}) => Promise<void> | void;
|
|
76
|
+
autocomplete?: (interaction: AutocompleteInteraction, client: Client & {
|
|
77
|
+
db: DB;
|
|
78
|
+
t: Function;
|
|
79
|
+
config: DJSNextConfig;
|
|
80
|
+
}) => Promise<void> | void;
|
|
81
|
+
}
|
|
82
|
+
interface FileComponent<DB = any> {
|
|
83
|
+
filepath?: string;
|
|
84
|
+
customId?: string;
|
|
85
|
+
preconditions?: string[];
|
|
86
|
+
execute: (interaction: MessageComponentInteraction | ModalSubmitInteraction, client: Client & {
|
|
87
|
+
db: DB;
|
|
88
|
+
t: Function;
|
|
89
|
+
config: DJSNextConfig;
|
|
90
|
+
}, params?: Record<string, string>) => Promise<void> | void;
|
|
91
|
+
}
|
|
92
|
+
interface Event<K extends keyof ClientEvents = keyof ClientEvents, DB = any> {
|
|
93
|
+
filepath?: string;
|
|
94
|
+
name: K;
|
|
95
|
+
once?: boolean;
|
|
96
|
+
execute: (client: Client & {
|
|
97
|
+
db: DB;
|
|
98
|
+
t: Function;
|
|
99
|
+
config: DJSNextConfig;
|
|
100
|
+
}, ...args: ClientEvents[K]) => Promise<void> | void;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
declare function loadLocales(localesDir: string, defaultLocale?: string): void;
|
|
104
|
+
declare function translate(key: string, locale?: string, variables?: Record<string, string | number>): string;
|
|
105
|
+
declare function getLocalesCache(): Record<string, Record<string, any>>;
|
|
106
|
+
|
|
107
|
+
declare class DJSNextClient<DB = any> extends Client {
|
|
108
|
+
commands: Collection<string, FileCommand>;
|
|
109
|
+
components: Collection<string, FileComponent>;
|
|
110
|
+
cooldowns: Collection<string, Collection<string, number>>;
|
|
111
|
+
config: DJSNextConfig;
|
|
112
|
+
t: typeof translate;
|
|
113
|
+
db: DB;
|
|
114
|
+
private _commandsDir?;
|
|
115
|
+
private _eventsDir?;
|
|
116
|
+
private _componentsDir?;
|
|
117
|
+
private _tasksDir?;
|
|
118
|
+
private _localesDir?;
|
|
119
|
+
private _clientId?;
|
|
120
|
+
private _guildId?;
|
|
121
|
+
private _developers;
|
|
122
|
+
private _middleware?;
|
|
123
|
+
private _prefixes;
|
|
124
|
+
private _enableSlashCommands;
|
|
125
|
+
private _enableTextCommands;
|
|
126
|
+
private _enableMentionPrefix;
|
|
127
|
+
private _enableNoPrefix;
|
|
128
|
+
constructor(options: DJSNextClientOptions);
|
|
129
|
+
private attachCoreListeners;
|
|
130
|
+
start(token: string): Promise<void>;
|
|
131
|
+
enableDevTools(prefix?: 'dnxt' | 'nxt'): void;
|
|
132
|
+
enableHMR(): Promise<void>;
|
|
133
|
+
private handleCommandError;
|
|
134
|
+
private handlePreconditions;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
declare function paginate(context: Message | CommandInteraction | MessageComponentInteraction, pages: EmbedBuilder[], time?: number): Promise<Message<boolean> | undefined>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Sends a confirmation prompt (Yes/No) to the user.
|
|
141
|
+
* @param context The message or interaction context.
|
|
142
|
+
* @param content The text or embed to display in the prompt.
|
|
143
|
+
* @param time Time to wait for a response in milliseconds.
|
|
144
|
+
* @returns Boolean indicating true for Yes, false for No, or null if timed out.
|
|
145
|
+
*/
|
|
146
|
+
declare function confirmPrompt(context: Message | CommandInteraction | MessageComponentInteraction, content: string | EmbedBuilder, time?: number): Promise<boolean | null>;
|
|
147
|
+
|
|
148
|
+
declare function loadConfig(): Promise<DJSNextConfig>;
|
|
149
|
+
declare function defineConfig(config: DJSNextConfig): DJSNextConfig;
|
|
150
|
+
|
|
151
|
+
declare class PaginationBuilder {
|
|
152
|
+
private pages;
|
|
153
|
+
private timeout;
|
|
154
|
+
constructor(pages?: EmbedBuilder[]);
|
|
155
|
+
addPage(embed: EmbedBuilder): this;
|
|
156
|
+
setPages(pages: EmbedBuilder[]): this;
|
|
157
|
+
setTimeout(ms: number): this;
|
|
158
|
+
build(target: CommandInteraction | Message): Promise<Message | null>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { type CooldownAdapter, DJSNextClient, type DJSNextClientOptions, type DJSNextConfig, type Event as DJSNextEvent, type FileCommand, type FileComponent, type FileTask, PaginationBuilder, confirmPrompt, defineConfig, getLocalesCache, loadConfig, loadLocales, paginate, translate };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { ApplicationCommandOptionData, PermissionResolvable, ChatInputCommandInteraction, Client, Message, AutocompleteInteraction, MessageComponentInteraction, ModalSubmitInteraction, ClientOptions, Interaction, ClientEvents, Collection, CommandInteraction, EmbedBuilder } from 'discord.js';
|
|
2
|
+
export * from 'discord.js';
|
|
3
|
+
|
|
4
|
+
interface CooldownAdapter {
|
|
5
|
+
get(commandId: string, userId: string): Promise<number | null> | number | null;
|
|
6
|
+
set(commandId: string, userId: string, expirationTime: number): Promise<void> | void;
|
|
7
|
+
}
|
|
8
|
+
interface DJSNextConfig {
|
|
9
|
+
devGuildId?: string;
|
|
10
|
+
errorLogChannelId?: string;
|
|
11
|
+
responses?: {
|
|
12
|
+
developerOnly?: string | null;
|
|
13
|
+
guildOnly?: string | null;
|
|
14
|
+
cooldown?: string | null;
|
|
15
|
+
missingPerms?: string | null;
|
|
16
|
+
errorBoundary?: string | null;
|
|
17
|
+
};
|
|
18
|
+
locales?: string[];
|
|
19
|
+
defaultLocale?: string;
|
|
20
|
+
directories?: {
|
|
21
|
+
commands?: string;
|
|
22
|
+
events?: string;
|
|
23
|
+
components?: string;
|
|
24
|
+
tasks?: string;
|
|
25
|
+
locales?: string;
|
|
26
|
+
};
|
|
27
|
+
cooldownAdapter?: CooldownAdapter;
|
|
28
|
+
}
|
|
29
|
+
interface DJSNextClientOptions extends ClientOptions {
|
|
30
|
+
commandsDir?: string;
|
|
31
|
+
eventsDir?: string;
|
|
32
|
+
componentsDir?: string;
|
|
33
|
+
tasksDir?: string;
|
|
34
|
+
clientId?: string;
|
|
35
|
+
guildId?: string;
|
|
36
|
+
developers?: string[];
|
|
37
|
+
prefixes?: string[] | string;
|
|
38
|
+
enableSlashCommands?: boolean;
|
|
39
|
+
enableTextCommands?: boolean;
|
|
40
|
+
enableMentionPrefix?: boolean | string[];
|
|
41
|
+
enableNoPrefix?: boolean | string[];
|
|
42
|
+
middleware?: (interaction: Interaction | Message, client: Client) => Promise<boolean> | boolean;
|
|
43
|
+
config?: DJSNextConfig;
|
|
44
|
+
db?: any;
|
|
45
|
+
}
|
|
46
|
+
interface FileTask<DB = any> {
|
|
47
|
+
filepath?: string;
|
|
48
|
+
interval: number;
|
|
49
|
+
execute: (client: Client & {
|
|
50
|
+
db: DB;
|
|
51
|
+
t: Function;
|
|
52
|
+
config: DJSNextConfig;
|
|
53
|
+
}) => Promise<void> | void;
|
|
54
|
+
}
|
|
55
|
+
interface FileCommand<DB = any> {
|
|
56
|
+
filepath?: string;
|
|
57
|
+
description: string;
|
|
58
|
+
options?: ApplicationCommandOptionData[];
|
|
59
|
+
cooldown?: number;
|
|
60
|
+
userPermissions?: PermissionResolvable[];
|
|
61
|
+
botPermissions?: PermissionResolvable[];
|
|
62
|
+
developerOnly?: boolean;
|
|
63
|
+
guildOnly?: boolean;
|
|
64
|
+
aliases?: string[];
|
|
65
|
+
preconditions?: string[];
|
|
66
|
+
execute?: (interaction: ChatInputCommandInteraction, client: Client & {
|
|
67
|
+
db: DB;
|
|
68
|
+
t: Function;
|
|
69
|
+
config: DJSNextConfig;
|
|
70
|
+
}) => Promise<void> | void;
|
|
71
|
+
executeText?: (message: Message, args: string[], client: Client & {
|
|
72
|
+
db: DB;
|
|
73
|
+
t: Function;
|
|
74
|
+
config: DJSNextConfig;
|
|
75
|
+
}) => Promise<void> | void;
|
|
76
|
+
autocomplete?: (interaction: AutocompleteInteraction, client: Client & {
|
|
77
|
+
db: DB;
|
|
78
|
+
t: Function;
|
|
79
|
+
config: DJSNextConfig;
|
|
80
|
+
}) => Promise<void> | void;
|
|
81
|
+
}
|
|
82
|
+
interface FileComponent<DB = any> {
|
|
83
|
+
filepath?: string;
|
|
84
|
+
customId?: string;
|
|
85
|
+
preconditions?: string[];
|
|
86
|
+
execute: (interaction: MessageComponentInteraction | ModalSubmitInteraction, client: Client & {
|
|
87
|
+
db: DB;
|
|
88
|
+
t: Function;
|
|
89
|
+
config: DJSNextConfig;
|
|
90
|
+
}, params?: Record<string, string>) => Promise<void> | void;
|
|
91
|
+
}
|
|
92
|
+
interface Event<K extends keyof ClientEvents = keyof ClientEvents, DB = any> {
|
|
93
|
+
filepath?: string;
|
|
94
|
+
name: K;
|
|
95
|
+
once?: boolean;
|
|
96
|
+
execute: (client: Client & {
|
|
97
|
+
db: DB;
|
|
98
|
+
t: Function;
|
|
99
|
+
config: DJSNextConfig;
|
|
100
|
+
}, ...args: ClientEvents[K]) => Promise<void> | void;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
declare function loadLocales(localesDir: string, defaultLocale?: string): void;
|
|
104
|
+
declare function translate(key: string, locale?: string, variables?: Record<string, string | number>): string;
|
|
105
|
+
declare function getLocalesCache(): Record<string, Record<string, any>>;
|
|
106
|
+
|
|
107
|
+
declare class DJSNextClient<DB = any> extends Client {
|
|
108
|
+
commands: Collection<string, FileCommand>;
|
|
109
|
+
components: Collection<string, FileComponent>;
|
|
110
|
+
cooldowns: Collection<string, Collection<string, number>>;
|
|
111
|
+
config: DJSNextConfig;
|
|
112
|
+
t: typeof translate;
|
|
113
|
+
db: DB;
|
|
114
|
+
private _commandsDir?;
|
|
115
|
+
private _eventsDir?;
|
|
116
|
+
private _componentsDir?;
|
|
117
|
+
private _tasksDir?;
|
|
118
|
+
private _localesDir?;
|
|
119
|
+
private _clientId?;
|
|
120
|
+
private _guildId?;
|
|
121
|
+
private _developers;
|
|
122
|
+
private _middleware?;
|
|
123
|
+
private _prefixes;
|
|
124
|
+
private _enableSlashCommands;
|
|
125
|
+
private _enableTextCommands;
|
|
126
|
+
private _enableMentionPrefix;
|
|
127
|
+
private _enableNoPrefix;
|
|
128
|
+
constructor(options: DJSNextClientOptions);
|
|
129
|
+
private attachCoreListeners;
|
|
130
|
+
start(token: string): Promise<void>;
|
|
131
|
+
enableDevTools(prefix?: 'dnxt' | 'nxt'): void;
|
|
132
|
+
enableHMR(): Promise<void>;
|
|
133
|
+
private handleCommandError;
|
|
134
|
+
private handlePreconditions;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
declare function paginate(context: Message | CommandInteraction | MessageComponentInteraction, pages: EmbedBuilder[], time?: number): Promise<Message<boolean> | undefined>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Sends a confirmation prompt (Yes/No) to the user.
|
|
141
|
+
* @param context The message or interaction context.
|
|
142
|
+
* @param content The text or embed to display in the prompt.
|
|
143
|
+
* @param time Time to wait for a response in milliseconds.
|
|
144
|
+
* @returns Boolean indicating true for Yes, false for No, or null if timed out.
|
|
145
|
+
*/
|
|
146
|
+
declare function confirmPrompt(context: Message | CommandInteraction | MessageComponentInteraction, content: string | EmbedBuilder, time?: number): Promise<boolean | null>;
|
|
147
|
+
|
|
148
|
+
declare function loadConfig(): Promise<DJSNextConfig>;
|
|
149
|
+
declare function defineConfig(config: DJSNextConfig): DJSNextConfig;
|
|
150
|
+
|
|
151
|
+
declare class PaginationBuilder {
|
|
152
|
+
private pages;
|
|
153
|
+
private timeout;
|
|
154
|
+
constructor(pages?: EmbedBuilder[]);
|
|
155
|
+
addPage(embed: EmbedBuilder): this;
|
|
156
|
+
setPages(pages: EmbedBuilder[]): this;
|
|
157
|
+
setTimeout(ms: number): this;
|
|
158
|
+
build(target: CommandInteraction | Message): Promise<Message | null>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { type CooldownAdapter, DJSNextClient, type DJSNextClientOptions, type DJSNextConfig, type Event as DJSNextEvent, type FileCommand, type FileComponent, type FileTask, PaginationBuilder, confirmPrompt, defineConfig, getLocalesCache, loadConfig, loadLocales, paginate, translate };
|