js-discord-modularcommand 1.0.1 → 2.0.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.
- package/README.md +55 -0
- package/dist/cooldown.d.ts +44 -0
- package/dist/cooldown.js +81 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +24 -0
- package/dist/interaction.d.ts +29 -0
- package/dist/interaction.js +83 -0
- package/dist/loadcommands.d.ts +27 -0
- package/dist/loadcommands.js +40 -0
- package/dist/locales.d.ts +20 -0
- package/dist/locales.js +162 -0
- package/dist/modularbutton.d.ts +33 -0
- package/dist/modularbutton.js +41 -0
- package/dist/modularcommand.d.ts +48 -176
- package/dist/modularcommand.js +54 -464
- package/dist/modularlocale.d.ts +103 -0
- package/dist/modularlocale.js +320 -0
- package/dist/modularmodal.d.ts +51 -0
- package/dist/modularmodal.js +75 -0
- package/dist/registercommand.d.ts +14 -0
- package/dist/registercommand.js +254 -0
- package/dist/types.d.ts +123 -0
- package/dist/types.js +7 -0
- package/package.json +13 -4
- package/index.js +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Contains the structure for creating reusable button components.
|
|
4
|
+
* @author vicentefelipechile
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const discord_js_1 = require("discord.js");
|
|
9
|
+
// =================================================================================================
|
|
10
|
+
// Main Class
|
|
11
|
+
// =================================================================================================
|
|
12
|
+
/**
|
|
13
|
+
* @class ModularButton
|
|
14
|
+
* @description A class to create and manage reusable button components.
|
|
15
|
+
*/
|
|
16
|
+
class ModularButton {
|
|
17
|
+
/**
|
|
18
|
+
* @description Creates a new ModularButton instance.
|
|
19
|
+
* @param {string} customId The custom ID for the button. This should be unique within the context of a message.
|
|
20
|
+
* @param {ButtonStyle} style The visual style of the button.
|
|
21
|
+
*/
|
|
22
|
+
constructor(customId, style) {
|
|
23
|
+
/** The function to execute when the button is clicked. */
|
|
24
|
+
this.execute = async () => { };
|
|
25
|
+
this.buttonObject = new discord_js_1.ButtonBuilder()
|
|
26
|
+
.setCustomId(customId)
|
|
27
|
+
.setStyle(style);
|
|
28
|
+
this.customId = customId;
|
|
29
|
+
this.style = style;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @description Sets the execution function for the button's click event.
|
|
33
|
+
* @param {ButtonExecuteFunction} executeFunction The function to run when the button is interacted with.
|
|
34
|
+
* @returns {this} The current ModularButton instance for method chaining.
|
|
35
|
+
*/
|
|
36
|
+
setExecute(executeFunction) {
|
|
37
|
+
this.execute = executeFunction;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.default = ModularButton;
|
package/dist/modularcommand.d.ts
CHANGED
|
@@ -6,170 +6,50 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Imports
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { LocalizationMap, ButtonStyle, Locale } from 'discord.js';
|
|
10
|
+
import ModularModal from './modularmodal.js';
|
|
11
|
+
import ModularButton from './modularbutton.js';
|
|
12
|
+
import { ButtonExecuteFunction, CommandExecuteFunction, CommandOption, ComponentExecuteFunction, ModalExecuteFunction, PermissionCheckFunction } from './types.js';
|
|
10
13
|
/**
|
|
11
|
-
* Localization Phrases
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* @description Localization phrases for various commands.
|
|
15
|
-
* @example
|
|
16
|
-
* const example = LOCALE_FORBIDDEN[Locale.EnglishUS];
|
|
17
|
-
* console.log(example); // 'You do not have permission to use this command.'
|
|
18
|
-
*/
|
|
19
|
-
declare const LOCALE_FORBIDDEN: Record<Locale, string>;
|
|
20
|
-
/**
|
|
21
|
-
* @description Localization phrases for NSFW commands.
|
|
22
|
-
* @example
|
|
23
|
-
* const example = LOCALE_NSFW[Locale.EnglishUS];
|
|
24
|
-
* console.log(example); // 'This command can only be used in NSFW channels.'
|
|
25
|
-
*/
|
|
26
|
-
declare const LOCALE_NSFW: Record<Locale, string>;
|
|
27
|
-
/**
|
|
28
|
-
* @description Localization phrases for delay commands.
|
|
29
|
-
* @example
|
|
30
|
-
* const example = LOCALE_DELAY[Locale.EnglishUS];
|
|
31
|
-
* const secondsPluralRegEx = new RegExp('{plural\\|([^}]+)}', 'g');
|
|
32
|
-
* const seconds = 5;
|
|
33
|
-
* const formattedPhrase = example
|
|
34
|
-
* .replace('{seconds}', seconds.toString())
|
|
35
|
-
* .replace(secondsPluralRegEx, seconds === 1 ? '' : '$1');
|
|
36
|
-
*
|
|
37
|
-
* console.log(formattedPhrase); // 'You must wait 5 seconds before using this command again.'
|
|
38
|
-
*/
|
|
39
|
-
declare const LOCALE_DELAY: Record<Locale, string>;
|
|
40
|
-
declare const LOCALE_ERROR: Record<Locale, string>;
|
|
41
|
-
/**
|
|
42
|
-
* Types
|
|
43
|
-
*/
|
|
44
|
-
type ArgType = string | number | boolean | User | Channel | Role | GuildMember;
|
|
45
|
-
type ExecuteFunction<T extends ChatInputCommandInteraction | MessageComponentInteraction> = (params: {
|
|
46
|
-
interaction: T;
|
|
47
|
-
args?: Record<string, ArgType>;
|
|
48
|
-
command: ModularCommand;
|
|
49
|
-
locale: Record<string, any>;
|
|
50
|
-
}) => Promise<void>;
|
|
51
|
-
type ButtonExecuteFunction = (params: {
|
|
52
|
-
interaction: MessageComponentInteraction;
|
|
53
|
-
command: ModularCommand;
|
|
54
|
-
locale: Record<string, any>;
|
|
55
|
-
message: Message;
|
|
56
|
-
}) => Promise<void>;
|
|
57
|
-
type ModalExecuteFunction = (params: {
|
|
58
|
-
interaction: ModalSubmitInteraction;
|
|
59
|
-
args: Record<string, string>;
|
|
60
|
-
command: ModularCommand;
|
|
61
|
-
locale: Record<string, any>;
|
|
62
|
-
}) => Promise<void>;
|
|
63
|
-
type PermissionCheckFunction = (interaction: ChatInputCommandInteraction) => boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Interface
|
|
66
|
-
*/
|
|
67
|
-
interface ModularCommandOptions {
|
|
68
|
-
name: string;
|
|
69
|
-
description?: string;
|
|
70
|
-
execute?: ExecuteFunction<ChatInputCommandInteraction>;
|
|
71
|
-
componentExecute?: ExecuteFunction<MessageComponentInteraction>;
|
|
72
|
-
modalExecute?: ModalExecuteFunction;
|
|
73
|
-
}
|
|
74
|
-
interface CommandOption {
|
|
75
|
-
name: string;
|
|
76
|
-
type: ApplicationCommandOptionType;
|
|
77
|
-
description: Record<Locale, string> | string;
|
|
78
|
-
required?: boolean;
|
|
79
|
-
choices?: APIApplicationCommandOptionChoice[];
|
|
80
|
-
}
|
|
81
|
-
interface RegisteredCommand {
|
|
82
|
-
data: SlashCommandBuilder;
|
|
83
|
-
execute: (interaction: ChatInputCommandInteraction) => Promise<void>;
|
|
84
|
-
componentExecute?: (interaction: MessageComponentInteraction) => Promise<void>;
|
|
85
|
-
modalExecute?: (interaction: ModalSubmitInteraction) => Promise<void>;
|
|
86
|
-
buttonExecute?: (interaction: MessageComponentInteraction) => Promise<void>;
|
|
87
|
-
cooldown: number;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* @class ModularButton
|
|
91
|
-
* @description Represents a modular button that can be registered with Discord.js.
|
|
92
|
-
* It allows for dynamic button creation and execution.
|
|
93
|
-
*/
|
|
94
|
-
declare class ModularButton {
|
|
95
|
-
buttonObject: ButtonBuilder;
|
|
96
|
-
customId: string;
|
|
97
|
-
style: ButtonStyle;
|
|
98
|
-
execute: ButtonExecuteFunction;
|
|
99
|
-
/**
|
|
100
|
-
* Creates a new button for the command.
|
|
101
|
-
* @param {string} customId The custom ID for the button.
|
|
102
|
-
* @param {ButtonStyle} style The style of the button.
|
|
103
|
-
*/
|
|
104
|
-
constructor(customId: string, style: ButtonStyle);
|
|
105
|
-
/**
|
|
106
|
-
* Sets the execute function for the button.
|
|
107
|
-
* @param {ButtonExecuteFunction} executeFunction The function to execute.
|
|
108
|
-
* @return {ModularButton} The button instance for chaining.
|
|
109
|
-
*/
|
|
110
|
-
setExecute(executeFunction: ButtonExecuteFunction): this;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* @class ModularModal
|
|
114
|
-
* @description Represents a modular modal that can be registered with Discord.js.
|
|
115
|
-
* It allows for dynamic modal creation and execution.
|
|
116
|
-
*/
|
|
117
|
-
declare class ModularModal {
|
|
118
|
-
modalObject: ModalBuilder;
|
|
119
|
-
modalId: string;
|
|
120
|
-
modalInputs: Map<string, TextInputBuilder>;
|
|
121
|
-
command: ModularCommand;
|
|
122
|
-
execute: ModalExecuteFunction;
|
|
123
|
-
/**
|
|
124
|
-
* Creates a new modal for the command.
|
|
125
|
-
* @param {string} modalId The ID for the modal.
|
|
126
|
-
* @param {ModularCommand} command The command that this modal belongs to.
|
|
127
|
-
*/
|
|
128
|
-
constructor(modalId: string, command: ModularCommand);
|
|
129
|
-
/**
|
|
130
|
-
* Sets the execute function for the modal.
|
|
131
|
-
* @param {ModalExecuteFunction} executeFunction The function to execute.
|
|
132
|
-
* @returns {ModularModal} The modal instance for chaining.
|
|
133
|
-
*/
|
|
134
|
-
setExecute(executeFunction: ModalExecuteFunction): this;
|
|
135
|
-
/**
|
|
136
|
-
* Creates a new text input for the modal.
|
|
137
|
-
* @param {string} id The ID for the text input.
|
|
138
|
-
* @param {TextInputStyle} style The style of the text input.
|
|
139
|
-
* @returns {TextInputBuilder} The created text input instance.
|
|
140
|
-
*/
|
|
141
|
-
newTextInput(id: string, style: TextInputStyle): TextInputBuilder;
|
|
142
|
-
/**
|
|
143
|
-
* Builds the modal object.
|
|
144
|
-
* @param {Record<string, any>} locale The localization object for the modal.
|
|
145
|
-
* @return {ModalBuilder} The built modal object.
|
|
146
|
-
*/
|
|
147
|
-
build(locale: Record<string, any>): ModalBuilder;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @class ModularCommand
|
|
151
14
|
* @description Represents a modular command that can be registered with Discord.js.
|
|
152
15
|
* It allows for dynamic command creation and execution.
|
|
16
|
+
* @example
|
|
17
|
+
* const { ModularCommand, RegisterCommand } = require('js-discord-modularcommand');
|
|
18
|
+
*
|
|
19
|
+
* const PingCommand = new ModularCommand('ping');
|
|
20
|
+
* PingCommand.setDescription('Sends a ping message.');
|
|
21
|
+
* PingCommand.setExecute(async ({interaction}) => {
|
|
22
|
+
* await interaction.reply('Pong!');
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* PingCommand.setPermissionCheck(({ interaction }) => {
|
|
26
|
+
* return interaction.member.permissions.has(PermissionFlagsBits.Administrator);
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* module.exports = RegisterCommand([
|
|
30
|
+
* PingCommand
|
|
31
|
+
* ]);
|
|
153
32
|
*/
|
|
154
|
-
|
|
33
|
+
export default class ModularCommand {
|
|
155
34
|
name: string;
|
|
156
35
|
description: string;
|
|
157
|
-
execute:
|
|
158
|
-
|
|
36
|
+
execute: CommandExecuteFunction;
|
|
37
|
+
buttonExecute?: ButtonExecuteFunction;
|
|
38
|
+
componentExecute?: ComponentExecuteFunction;
|
|
159
39
|
modalExecute?: ModalExecuteFunction;
|
|
160
40
|
options: CommandOption[];
|
|
161
41
|
optionsLocalizations: Record<string, Record<Locale, string>>;
|
|
162
|
-
customIdHandlers: Record<string,
|
|
42
|
+
customIdHandlers: Record<string, CommandExecuteFunction>;
|
|
163
43
|
cooldown: number;
|
|
164
44
|
modals: Map<string, ModularModal>;
|
|
165
45
|
buttons: Map<string, ModularButton>;
|
|
166
46
|
buttonsArray: ModularButton[];
|
|
167
47
|
isNSFW: boolean;
|
|
168
48
|
descriptionLocalizations?: LocalizationMap;
|
|
169
|
-
localizationPhrases?: Record<Locale,
|
|
49
|
+
localizationPhrases?: Record<Locale, string>;
|
|
170
50
|
permissionCheck?: PermissionCheckFunction;
|
|
171
51
|
componentId?: string;
|
|
172
|
-
constructor(
|
|
52
|
+
constructor(name: string);
|
|
173
53
|
/**
|
|
174
54
|
* Sets the description of the command.
|
|
175
55
|
* @param {string} description The description.
|
|
@@ -185,36 +65,23 @@ declare class ModularCommand {
|
|
|
185
65
|
setLocalizationOptions(localizations: Record<string, Record<Locale, string>>): this;
|
|
186
66
|
/**
|
|
187
67
|
* Sets the localization phrases for the command.
|
|
188
|
-
* @param {Record<Locale,
|
|
68
|
+
* @param {Record<Locale, string>} localizationPhrases The localization phrases.
|
|
189
69
|
* @returns {ModularCommand} The command instance for chaining.
|
|
190
70
|
*/
|
|
191
|
-
setLocalizationPhrases(localizationPhrases: Record<Locale,
|
|
71
|
+
setLocalizationPhrases(localizationPhrases: Record<Locale, string>): this;
|
|
192
72
|
/**
|
|
193
73
|
* Sets the execute function for the command.
|
|
194
|
-
* @param {
|
|
74
|
+
* @param {CommandExecuteFunction} executeFunction The function to execute.
|
|
195
75
|
* @returns {ModularCommand} The command instance for chaining.
|
|
196
76
|
*/
|
|
197
|
-
setExecute(executeFunction:
|
|
77
|
+
setExecute(executeFunction: CommandExecuteFunction): this;
|
|
198
78
|
/**
|
|
199
79
|
* Sets the component execute function for the command.
|
|
200
80
|
* @param {string} componentId The base ID for the components.
|
|
201
|
-
* @param {
|
|
81
|
+
* @param {ComponentExecuteFunction} executeFunction The function to execute for component interactions.
|
|
202
82
|
* @returns {ModularCommand} The command instance for chaining.
|
|
203
83
|
*/
|
|
204
|
-
setComponentExecute(componentId: string, executeFunction:
|
|
205
|
-
/**
|
|
206
|
-
* Creates a new modal for the command.
|
|
207
|
-
* @param {string} modalId The ID for the modal.
|
|
208
|
-
* @returns {ModularModal} The created modal instance.
|
|
209
|
-
*/
|
|
210
|
-
newModal(modalId: string): ModularModal;
|
|
211
|
-
/**
|
|
212
|
-
* Creates a new button for the command.
|
|
213
|
-
* @param {string} customId The custom ID for the button.
|
|
214
|
-
* @param {ButtonStyle} style The style of the button.
|
|
215
|
-
* @return {ModularButton} The created button instance.
|
|
216
|
-
*/
|
|
217
|
-
newButton(customId: string, style: ButtonStyle): ModularButton;
|
|
84
|
+
setComponentExecute(componentId: string, executeFunction: ComponentExecuteFunction): this;
|
|
218
85
|
/**
|
|
219
86
|
* Set the minimun permissions required to execute the command.
|
|
220
87
|
* @param {PermissionCheckFunction} permissionCheckFunction The function to check permissions.
|
|
@@ -241,16 +108,21 @@ declare class ModularCommand {
|
|
|
241
108
|
/**
|
|
242
109
|
* Adds a custom ID handler for the command.
|
|
243
110
|
* @param {string} customId The custom ID to match.
|
|
244
|
-
* @param {
|
|
111
|
+
* @param {CommandInteraction<CacheType>} handlerFunction The function to execute when the custom ID matches.
|
|
245
112
|
* @returns {ModularCommand} The command instance for chaining.
|
|
246
113
|
*/
|
|
247
|
-
addCustomIDHandler(customId: string, handlerFunction:
|
|
114
|
+
addCustomIDHandler(customId: string, handlerFunction: CommandExecuteFunction): this;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a new modal for the command.
|
|
117
|
+
* @param {string} modalId The ID for the modal.
|
|
118
|
+
* @returns {ModularModal} The created modal instance.
|
|
119
|
+
*/
|
|
120
|
+
addModal(modalId: string): ModularModal;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new button for the command.
|
|
123
|
+
* @param {string} customId The custom ID for the button.
|
|
124
|
+
* @param {ButtonStyle} style The style of the button.
|
|
125
|
+
* @return {ModularButton} The created button instance.
|
|
126
|
+
*/
|
|
127
|
+
addButton(customId: string, style: ButtonStyle): ModularButton;
|
|
248
128
|
}
|
|
249
|
-
/**
|
|
250
|
-
* Registers an array of modular commands.
|
|
251
|
-
* @param {ModularCommand[]} commands An array of ModularCommand instances.
|
|
252
|
-
* @returns {RegisteredCommand[]} An array of command data objects ready for Discord.js client.
|
|
253
|
-
*/
|
|
254
|
-
declare const RegisterCommand: (commands: ModularCommand[]) => RegisteredCommand[];
|
|
255
|
-
export default ModularCommand;
|
|
256
|
-
export { RegisterCommand, ModularCommand, ModularButton, ModularModal, LOCALE_FORBIDDEN, LOCALE_DELAY, LOCALE_NSFW, LOCALE_ERROR, };
|