djs-next 0.0.1 → 1.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of djs-next might be problematic. Click here for more details.

@@ -4,29 +4,20 @@ import {
4
4
  ButtonStyle,
5
5
  CommandInteraction,
6
6
  EmbedBuilder,
7
- Message,
8
7
  MessageComponentInteraction
9
8
  } from 'discord.js';
10
9
 
11
10
  export async function paginate(
12
- context: Message | CommandInteraction | MessageComponentInteraction,
11
+ interaction: CommandInteraction | MessageComponentInteraction,
13
12
  pages: EmbedBuilder[],
14
13
  time: number = 60000
15
14
  ) {
16
- const isMessage = 'author' in context;
17
-
18
- if (!isMessage) {
19
- if (!context.deferred && !context.replied) {
20
- await context.deferReply();
21
- }
15
+ if (!interaction.deferred && !interaction.replied) {
16
+ await interaction.deferReply();
22
17
  }
23
18
 
24
19
  if (pages.length === 1) {
25
- if (isMessage) {
26
- return context.reply({ embeds: [pages[0]], components: [] });
27
- } else {
28
- return context.editReply({ embeds: [pages[0]], components: [] });
29
- }
20
+ return interaction.editReply({ embeds: [pages[0]], components: [] });
30
21
  }
31
22
 
32
23
  let index = 0;
@@ -44,25 +35,17 @@ export async function paginate(
44
35
 
45
36
  const row = new ActionRowBuilder<ButtonBuilder>().addComponents(prevButton, nextButton);
46
37
 
47
- let message: Message;
48
- if (isMessage) {
49
- message = await context.reply({
50
- embeds: [pages[index]],
51
- components: [row],
52
- });
53
- } else {
54
- message = await context.editReply({
55
- embeds: [pages[index]],
56
- components: [row],
57
- });
58
- }
38
+ const message = await interaction.editReply({
39
+ embeds: [pages[index]],
40
+ components: [row],
41
+ });
59
42
 
60
43
  const collector = message.createMessageComponentCollector({
61
- filter: (i) => i.user.id === (isMessage ? context.author.id : context.user.id),
44
+ filter: (i) => i.user.id === interaction.user.id,
62
45
  time
63
46
  });
64
47
 
65
- collector.on('collect', async (i: MessageComponentInteraction) => {
48
+ collector.on('collect', async (i) => {
66
49
  if (i.customId === 'djs_prev') {
67
50
  index = index > 0 ? index - 1 : index;
68
51
  } else if (i.customId === 'djs_next') {
@@ -81,10 +64,8 @@ export async function paginate(
81
64
  collector.on('end', async () => {
82
65
  prevButton.setDisabled(true);
83
66
  nextButton.setDisabled(true);
84
- if (message.editable) {
85
- await message.edit({
86
- components: [new ActionRowBuilder<ButtonBuilder>().addComponents(prevButton, nextButton)]
87
- }).catch(() => {});
88
- }
67
+ await interaction.editReply({
68
+ components: [new ActionRowBuilder<ButtonBuilder>().addComponents(prevButton, nextButton)]
69
+ }).catch(() => {});
89
70
  });
90
71
  }
package/tsup.config.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { defineConfig } from 'tsup';
2
2
 
3
3
  export default defineConfig({
4
- entry: ['src/index.ts'],
4
+ entry: ['src/index.ts', 'src/cli.ts'],
5
5
  format: ['cjs', 'esm'], // Build for CommonJS and ES Modules
6
6
  dts: true, // Generate declaration file (.d.ts)
7
7
  splitting: false,
@@ -1,78 +0,0 @@
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!');
@@ -1,94 +0,0 @@
1
- import {
2
- ActionRowBuilder,
3
- ButtonBuilder,
4
- ButtonStyle,
5
- CommandInteraction,
6
- EmbedBuilder,
7
- Message,
8
- ComponentType
9
- } from 'discord.js';
10
-
11
- export class PaginationBuilder {
12
- private pages: EmbedBuilder[] = [];
13
- private timeout: number = 60000;
14
-
15
- constructor(pages?: EmbedBuilder[]) {
16
- if (pages) this.pages = pages;
17
- }
18
-
19
- public addPage(embed: EmbedBuilder): this {
20
- this.pages.push(embed);
21
- return this;
22
- }
23
-
24
- public setPages(pages: EmbedBuilder[]): this {
25
- this.pages = pages;
26
- return this;
27
- }
28
-
29
- public setTimeout(ms: number): this {
30
- this.timeout = ms;
31
- return this;
32
- }
33
-
34
- public async build(target: CommandInteraction | Message): Promise<Message | null> {
35
- if (this.pages.length === 0) throw new Error('[djs-next] PaginationBuilder requires at least one page.');
36
-
37
- if (this.pages.length === 1) {
38
- if (target instanceof CommandInteraction) {
39
- if (target.deferred || target.replied) {
40
- return await target.editReply({ embeds: [this.pages[0]] }) as Message;
41
- }
42
- return await target.reply({ embeds: [this.pages[0]], fetchReply: true }) as Message;
43
- } else {
44
- return await target.reply({ embeds: [this.pages[0]] });
45
- }
46
- }
47
-
48
- let currentPage = 0;
49
-
50
- const row = new ActionRowBuilder<ButtonBuilder>().addComponents(
51
- new ButtonBuilder().setCustomId('prev').setLabel('◀').setStyle(ButtonStyle.Primary).setDisabled(true),
52
- new ButtonBuilder().setCustomId('page').setLabel(`1 / ${this.pages.length}`).setStyle(ButtonStyle.Secondary).setDisabled(true),
53
- new ButtonBuilder().setCustomId('next').setLabel('▶').setStyle(ButtonStyle.Primary)
54
- );
55
-
56
- let replyMsg: Message;
57
- if (target instanceof CommandInteraction) {
58
- if (target.deferred || target.replied) {
59
- replyMsg = await target.editReply({ embeds: [this.pages[0]], components: [row] }) as Message;
60
- } else {
61
- replyMsg = await target.reply({ embeds: [this.pages[0]], components: [row], fetchReply: true }) as Message;
62
- }
63
- } else {
64
- replyMsg = await target.reply({ embeds: [this.pages[0]], components: [row] });
65
- }
66
-
67
- const userId = target instanceof CommandInteraction ? target.user.id : target.author.id;
68
-
69
- const collector = replyMsg.createMessageComponentCollector({
70
- componentType: ComponentType.Button,
71
- time: this.timeout,
72
- filter: i => i.user.id === userId
73
- });
74
-
75
- collector.on('collect', async i => {
76
- if (i.customId === 'prev') currentPage--;
77
- else if (i.customId === 'next') currentPage++;
78
-
79
- const newRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
80
- new ButtonBuilder().setCustomId('prev').setLabel('◀').setStyle(ButtonStyle.Primary).setDisabled(currentPage === 0),
81
- new ButtonBuilder().setCustomId('page').setLabel(`${currentPage + 1} / ${this.pages.length}`).setStyle(ButtonStyle.Secondary).setDisabled(true),
82
- new ButtonBuilder().setCustomId('next').setLabel('▶').setStyle(ButtonStyle.Primary).setDisabled(currentPage === this.pages.length - 1)
83
- );
84
-
85
- await i.update({ embeds: [this.pages[currentPage]], components: [newRow] });
86
- });
87
-
88
- collector.on('end', () => {
89
- replyMsg.edit({ components: [] }).catch(() => null);
90
- });
91
-
92
- return replyMsg;
93
- }
94
- }
@@ -1,76 +0,0 @@
1
- import {
2
- ActionRowBuilder,
3
- ButtonBuilder,
4
- ButtonStyle,
5
- CommandInteraction,
6
- EmbedBuilder,
7
- Message,
8
- MessageComponentInteraction
9
- } from 'discord.js';
10
-
11
- /**
12
- * Sends a confirmation prompt (Yes/No) to the user.
13
- * @param context The message or interaction context.
14
- * @param content The text or embed to display in the prompt.
15
- * @param time Time to wait for a response in milliseconds.
16
- * @returns Boolean indicating true for Yes, false for No, or null if timed out.
17
- */
18
- export async function confirmPrompt(
19
- context: Message | CommandInteraction | MessageComponentInteraction,
20
- content: string | EmbedBuilder,
21
- time: number = 30000
22
- ): Promise<boolean | null> {
23
- const isMessage = 'author' in context;
24
-
25
- if (!isMessage) {
26
- if (!context.deferred && !context.replied) {
27
- await context.deferReply();
28
- }
29
- }
30
-
31
- const yesButton = new ButtonBuilder()
32
- .setCustomId('djs_prompt_yes')
33
- .setLabel('Yes')
34
- .setStyle(ButtonStyle.Success);
35
-
36
- const noButton = new ButtonBuilder()
37
- .setCustomId('djs_prompt_no')
38
- .setLabel('No')
39
- .setStyle(ButtonStyle.Danger);
40
-
41
- const row = new ActionRowBuilder<ButtonBuilder>().addComponents(yesButton, noButton);
42
-
43
- const payload: any = { components: [row] };
44
- if (typeof content === 'string') {
45
- payload.content = content;
46
- } else {
47
- payload.embeds = [content];
48
- }
49
-
50
- let message: Message;
51
- if (isMessage) {
52
- message = await context.reply(payload);
53
- } else {
54
- message = await context.editReply(payload);
55
- }
56
-
57
- try {
58
- const interaction = await message.awaitMessageComponent({
59
- filter: (i) => i.user.id === (isMessage ? context.author.id : context.user.id),
60
- time
61
- });
62
-
63
- if (interaction.customId === 'djs_prompt_yes') {
64
- await interaction.update({ components: [] });
65
- return true;
66
- } else {
67
- await interaction.update({ components: [] });
68
- return false;
69
- }
70
- } catch (error) {
71
- if (message.editable) {
72
- await message.edit({ components: [] }).catch(() => {});
73
- }
74
- return null; // Timed out
75
- }
76
- }
package/test_payload.js DELETED
@@ -1,3 +0,0 @@
1
- const { MessagePayload, Message } = require('discord.js');
2
- const payload = MessagePayload.create({ flags: { bitfield: 0 } }, "Pong!");
3
- console.log(payload.resolveBody());
package/test_reply.js DELETED
@@ -1,4 +0,0 @@
1
- const { Client, MessagePayload } = require('discord.js');
2
- const client = new Client({ intents: [] });
3
- const payload = MessagePayload.create(client, { components: [], flags: 32768 });
4
- console.log(payload.resolveBody());