js-discord-modularcommand 1.1.0 → 2.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.
- package/dist/cooldown.d.ts +44 -0
- package/dist/cooldown.js +81 -0
- package/dist/index.d.ts +8 -11
- package/dist/index.js +14 -9
- 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 +8 -39
- package/dist/locales.js +47 -135
- package/dist/modularbutton.d.ts +33 -0
- package/dist/modularbutton.js +41 -0
- package/dist/modularcommand.d.ts +54 -121
- package/dist/modularcommand.js +26 -260
- package/dist/modularlocale.d.ts +103 -0
- package/dist/modularlocale.js +320 -0
- package/dist/modularmodal.d.ts +26 -41
- package/dist/modularmodal.js +37 -44
- package/dist/registercommand.d.ts +14 -0
- package/dist/registercommand.js +249 -0
- package/dist/types.d.ts +133 -0
- package/dist/types.js +23 -0
- package/package.json +12 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Contains the structure for creating reusable button components.
|
|
3
|
+
* @author vicentefelipechile
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
import { ButtonBuilder, ButtonStyle } from "discord.js";
|
|
7
|
+
import { ButtonExecuteFunction } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* @class ModularButton
|
|
10
|
+
* @description A class to create and manage reusable button components.
|
|
11
|
+
*/
|
|
12
|
+
export default class ModularButton {
|
|
13
|
+
/** The Discord.js ButtonBuilder instance. */
|
|
14
|
+
buttonObject: ButtonBuilder;
|
|
15
|
+
/** The custom ID for the button, used to identify it in interactions. */
|
|
16
|
+
customId: string;
|
|
17
|
+
/** The visual style of the button. */
|
|
18
|
+
style: ButtonStyle;
|
|
19
|
+
/** The function to execute when the button is clicked. */
|
|
20
|
+
execute: ButtonExecuteFunction;
|
|
21
|
+
/**
|
|
22
|
+
* @description Creates a new ModularButton instance.
|
|
23
|
+
* @param {string} customId The custom ID for the button. This should be unique within the context of a message.
|
|
24
|
+
* @param {ButtonStyle} style The visual style of the button.
|
|
25
|
+
*/
|
|
26
|
+
constructor(customId: string, style: ButtonStyle);
|
|
27
|
+
/**
|
|
28
|
+
* @description Sets the execution function for the button's click event.
|
|
29
|
+
* @param {ButtonExecuteFunction} executeFunction The function to run when the button is interacted with.
|
|
30
|
+
* @returns {this} The current ModularButton instance for method chaining.
|
|
31
|
+
*/
|
|
32
|
+
setExecute(executeFunction: ButtonExecuteFunction): this;
|
|
33
|
+
}
|
|
@@ -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
|
@@ -1,133 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* @
|
|
2
|
+
* @file Contains the main class for creating modular commands.
|
|
3
|
+
* @author vicentefelipechile
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
* Imports
|
|
8
|
-
*/
|
|
9
|
-
import { ApplicationCommandOptionType, MessageComponentInteraction, ChatInputCommandInteraction, ModalSubmitInteraction, SlashCommandBuilder, ButtonBuilder, Locale, Message, ButtonStyle, Channel, User, Role, GuildMember, LocalizationMap, APIApplicationCommandOptionChoice } from 'discord.js';
|
|
6
|
+
import { LocalizationMap, ButtonStyle, Locale } from 'discord.js';
|
|
10
7
|
import ModularModal from './modularmodal.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
type ArgType = string | number | boolean | User | Channel | Role | GuildMember;
|
|
15
|
-
type ExecuteFunction<T extends ChatInputCommandInteraction | MessageComponentInteraction> = (params: {
|
|
16
|
-
interaction: T;
|
|
17
|
-
args?: Record<string, ArgType>;
|
|
18
|
-
command: ModularCommand;
|
|
19
|
-
locale: Record<string, any>;
|
|
20
|
-
}) => Promise<void>;
|
|
21
|
-
type ButtonExecuteFunction = (params: {
|
|
22
|
-
interaction: MessageComponentInteraction;
|
|
23
|
-
command: ModularCommand;
|
|
24
|
-
locale: Record<string, any>;
|
|
25
|
-
message: Message;
|
|
26
|
-
}) => Promise<void>;
|
|
27
|
-
type ModalExecuteFunction = (params: {
|
|
28
|
-
interaction: ModalSubmitInteraction;
|
|
29
|
-
args: Record<string, string>;
|
|
30
|
-
command: ModularCommand;
|
|
31
|
-
locale: Record<string, any>;
|
|
32
|
-
}) => Promise<void>;
|
|
33
|
-
type PermissionCheckFunction = (params: {
|
|
34
|
-
interaction: ChatInputCommandInteraction;
|
|
35
|
-
}) => boolean | Promise<boolean>;
|
|
36
|
-
/**
|
|
37
|
-
* @description Registered Command as object to be used outside the modular command system.
|
|
38
|
-
* @example
|
|
39
|
-
* const PingCommand = new ModularCommand('ping');
|
|
40
|
-
*
|
|
41
|
-
* PingCommand.setExecute(({interaction}) => {
|
|
42
|
-
* interaction.reply('Pong!');
|
|
43
|
-
* });
|
|
44
|
-
*
|
|
45
|
-
* const cmds = RegisterCommand([PingCommand])
|
|
46
|
-
* const cmd = cmds[0];
|
|
47
|
-
* console.log(cmd.execute); // [Function: execute]
|
|
48
|
-
*/
|
|
49
|
-
type RegisteredCommand = {
|
|
50
|
-
data: SlashCommandBuilder;
|
|
51
|
-
execute: (interaction: ChatInputCommandInteraction) => Promise<void>;
|
|
52
|
-
componentExecute?: (interaction: MessageComponentInteraction) => Promise<void>;
|
|
53
|
-
modalExecute?: (interaction: ModalSubmitInteraction) => Promise<void>;
|
|
54
|
-
buttonExecute?: (interaction: MessageComponentInteraction) => Promise<void>;
|
|
55
|
-
cooldown: number;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Interface
|
|
59
|
-
*/
|
|
60
|
-
/**
|
|
61
|
-
* @description Represents a command option for a modular command.
|
|
62
|
-
*/
|
|
63
|
-
interface CommandOption {
|
|
64
|
-
name: string;
|
|
65
|
-
type: ApplicationCommandOptionType;
|
|
66
|
-
description: Record<Locale, string> | string;
|
|
67
|
-
required?: boolean;
|
|
68
|
-
choices?: APIApplicationCommandOptionChoice[];
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* @class ModularButton
|
|
72
|
-
* @description Represents a modular button that can be registered with Discord.js.
|
|
73
|
-
* It allows for dynamic button creation and execution.
|
|
74
|
-
*/
|
|
75
|
-
declare class ModularButton {
|
|
76
|
-
buttonObject: ButtonBuilder;
|
|
77
|
-
customId: string;
|
|
78
|
-
style: ButtonStyle;
|
|
79
|
-
execute: ButtonExecuteFunction;
|
|
80
|
-
/**
|
|
81
|
-
* Creates a new button for the command.
|
|
82
|
-
* @param {string} customId The custom ID for the button.
|
|
83
|
-
* @param {ButtonStyle} style The style of the button.
|
|
84
|
-
*/
|
|
85
|
-
constructor(customId: string, style: ButtonStyle);
|
|
86
|
-
/**
|
|
87
|
-
* Sets the execute function for the button.
|
|
88
|
-
* @param {ButtonExecuteFunction} executeFunction The function to execute.
|
|
89
|
-
* @return {ModularButton} The button instance for chaining.
|
|
90
|
-
*/
|
|
91
|
-
setExecute(executeFunction: ButtonExecuteFunction): this;
|
|
92
|
-
}
|
|
8
|
+
import ModularButton from './modularbutton.js';
|
|
9
|
+
import { ButtonExecuteFunction, CommandExecuteFunction, CommandOption, ComponentExecuteFunction, ModalExecuteFunction, PermissionCheckFunction } from './types.js';
|
|
93
10
|
/**
|
|
94
11
|
* @description Represents a modular command that can be registered with Discord.js.
|
|
95
|
-
* It allows for dynamic command creation and execution.
|
|
12
|
+
* It allows for dynamic command creation and execution in a simple way.
|
|
96
13
|
* @example
|
|
97
14
|
* const { ModularCommand, RegisterCommand } = require('js-discord-modularcommand');
|
|
98
15
|
*
|
|
99
16
|
* const PingCommand = new ModularCommand('ping');
|
|
100
17
|
* PingCommand.setDescription('Sends a ping message.');
|
|
101
18
|
* PingCommand.setExecute(async ({interaction}) => {
|
|
102
|
-
*
|
|
19
|
+
* await interaction.reply('Pong!');
|
|
103
20
|
* });
|
|
104
21
|
*
|
|
105
22
|
* PingCommand.setPermissionCheck(({ interaction }) => {
|
|
106
|
-
*
|
|
23
|
+
* return interaction.member.permissions.has(PermissionFlagsBits.Administrator);
|
|
107
24
|
* });
|
|
108
25
|
*
|
|
109
26
|
* module.exports = RegisterCommand([
|
|
110
|
-
*
|
|
27
|
+
* PingCommand
|
|
111
28
|
* ]);
|
|
112
29
|
*/
|
|
113
|
-
|
|
30
|
+
export default class ModularCommand {
|
|
31
|
+
/** The name of the command, must be unique. */
|
|
114
32
|
name: string;
|
|
33
|
+
/** The main description of the command. */
|
|
115
34
|
description: string;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
35
|
+
/** A map of localizations for the command's description. */
|
|
36
|
+
descriptionLocalizations?: LocalizationMap;
|
|
37
|
+
/** The options (arguments) that the command accepts. */
|
|
119
38
|
options: CommandOption[];
|
|
39
|
+
/** An object containing localizations for the names and descriptions of the options. */
|
|
120
40
|
optionsLocalizations: Record<string, Record<Locale, string>>;
|
|
121
|
-
|
|
41
|
+
/** The main function that executes when the command is invoked. */
|
|
42
|
+
execute: CommandExecuteFunction;
|
|
43
|
+
/** (Optional) The function to handle button interactions. */
|
|
44
|
+
buttonExecute?: ButtonExecuteFunction;
|
|
45
|
+
/** (Optional) The function to handle generic component interactions (like select menus). */
|
|
46
|
+
componentExecute?: ComponentExecuteFunction;
|
|
47
|
+
/** (Optional) The function to handle modal submissions. */
|
|
48
|
+
modalExecute?: ModalExecuteFunction;
|
|
49
|
+
/** A record of handlers for specific component custom IDs. */
|
|
50
|
+
customIdHandlers: Record<string, CommandExecuteFunction>;
|
|
51
|
+
/** The command's cooldown time in seconds. */
|
|
122
52
|
cooldown: number;
|
|
123
|
-
|
|
124
|
-
buttons: Map<string, ModularButton>;
|
|
125
|
-
buttonsArray: ModularButton[];
|
|
53
|
+
/** Whether the command is marked as Not Safe For Work (NSFW). */
|
|
126
54
|
isNSFW: boolean;
|
|
127
|
-
|
|
128
|
-
localizationPhrases?: Record<Locale,
|
|
55
|
+
/** (Optional) An object with localized phrases to be used within the command's execution. */
|
|
56
|
+
localizationPhrases?: Record<Locale, string>;
|
|
57
|
+
/** (Optional) The function that checks if a user has permission to execute the command. */
|
|
129
58
|
permissionCheck?: PermissionCheckFunction;
|
|
59
|
+
/** (Optional) The base ID for components associated with this command. */
|
|
130
60
|
componentId?: string;
|
|
61
|
+
/** A map of modals associated with this command, keyed by modal ID. */
|
|
62
|
+
modals: Map<string, ModularModal>;
|
|
63
|
+
/** A map of buttons associated with this command, keyed by the button's custom ID. */
|
|
64
|
+
buttons: Map<string, ModularButton>;
|
|
65
|
+
/** An array containing all ModularButton instances for easy access. */
|
|
66
|
+
buttonsArray: ModularButton[];
|
|
131
67
|
constructor(name: string);
|
|
132
68
|
/**
|
|
133
69
|
* Sets the description of the command.
|
|
@@ -137,32 +73,37 @@ declare class ModularCommand {
|
|
|
137
73
|
setDescription(description: string): this;
|
|
138
74
|
/**
|
|
139
75
|
* Sets the description localizations for the command.
|
|
140
|
-
* @param {LocalizationMap} localizations The description localizations.
|
|
76
|
+
* @param {LocalizationMap} localizations The description localizations map.
|
|
141
77
|
* @returns {ModularCommand} The command instance for chaining.
|
|
142
78
|
*/
|
|
143
79
|
setLocalizationsDescription(localizations: LocalizationMap): this;
|
|
80
|
+
/**
|
|
81
|
+
* Sets the localizations for the command's options.
|
|
82
|
+
* @param {Record<string, Record<Locale, string>>} localizations An object with the localizations.
|
|
83
|
+
* @returns {ModularCommand} The command instance for chaining.
|
|
84
|
+
*/
|
|
144
85
|
setLocalizationOptions(localizations: Record<string, Record<Locale, string>>): this;
|
|
145
86
|
/**
|
|
146
87
|
* Sets the localization phrases for the command.
|
|
147
|
-
* @param {Record<Locale,
|
|
88
|
+
* @param {Record<Locale, string>} localizationPhrases The localization phrases.
|
|
148
89
|
* @returns {ModularCommand} The command instance for chaining.
|
|
149
90
|
*/
|
|
150
|
-
setLocalizationPhrases(localizationPhrases: Record<Locale,
|
|
91
|
+
setLocalizationPhrases(localizationPhrases: Record<Locale, string>): this;
|
|
151
92
|
/**
|
|
152
93
|
* Sets the execute function for the command.
|
|
153
|
-
* @param {
|
|
94
|
+
* @param {CommandExecuteFunction} executeFunction The function to execute.
|
|
154
95
|
* @returns {ModularCommand} The command instance for chaining.
|
|
155
96
|
*/
|
|
156
|
-
setExecute(executeFunction:
|
|
97
|
+
setExecute(executeFunction: CommandExecuteFunction): this;
|
|
157
98
|
/**
|
|
158
99
|
* Sets the component execute function for the command.
|
|
159
100
|
* @param {string} componentId The base ID for the components.
|
|
160
|
-
* @param {
|
|
101
|
+
* @param {ComponentExecuteFunction} executeFunction The function to execute for component interactions.
|
|
161
102
|
* @returns {ModularCommand} The command instance for chaining.
|
|
162
103
|
*/
|
|
163
|
-
setComponentExecute(componentId: string, executeFunction:
|
|
104
|
+
setComponentExecute(componentId: string, executeFunction: ComponentExecuteFunction): this;
|
|
164
105
|
/**
|
|
165
|
-
*
|
|
106
|
+
* Sets the minimum permissions required to execute the command.
|
|
166
107
|
* @param {PermissionCheckFunction} permissionCheckFunction The function to check permissions.
|
|
167
108
|
* @returns {ModularCommand} The command instance for chaining.
|
|
168
109
|
*/
|
|
@@ -180,17 +121,17 @@ declare class ModularCommand {
|
|
|
180
121
|
getComponentId(): string | undefined;
|
|
181
122
|
/**
|
|
182
123
|
* Adds an option to the command.
|
|
183
|
-
* @param {CommandOption} option The option for the command
|
|
124
|
+
* @param {CommandOption} option The option for the command.
|
|
184
125
|
* @returns {ModularCommand} The command instance for chaining.
|
|
185
126
|
*/
|
|
186
127
|
addOption(option: CommandOption): this;
|
|
187
128
|
/**
|
|
188
129
|
* Adds a custom ID handler for the command.
|
|
189
130
|
* @param {string} customId The custom ID to match.
|
|
190
|
-
* @param {
|
|
131
|
+
* @param {CommandExecuteFunction} handlerFunction The function to execute when the custom ID matches.
|
|
191
132
|
* @returns {ModularCommand} The command instance for chaining.
|
|
192
133
|
*/
|
|
193
|
-
addCustomIDHandler(customId: string, handlerFunction:
|
|
134
|
+
addCustomIDHandler(customId: string, handlerFunction: CommandExecuteFunction): this;
|
|
194
135
|
/**
|
|
195
136
|
* Creates a new modal for the command.
|
|
196
137
|
* @param {string} modalId The ID for the modal.
|
|
@@ -205,11 +146,3 @@ declare class ModularCommand {
|
|
|
205
146
|
*/
|
|
206
147
|
addButton(customId: string, style: ButtonStyle): ModularButton;
|
|
207
148
|
}
|
|
208
|
-
/**
|
|
209
|
-
* Registers an array of modular commands.
|
|
210
|
-
* @param {ModularCommand[]} commands An array of ModularCommand instances.
|
|
211
|
-
* @returns {RegisteredCommand[]} An array of command data objects ready for Discord.js client.
|
|
212
|
-
*/
|
|
213
|
-
declare const RegisterCommand: (commands: ModularCommand[]) => RegisteredCommand[];
|
|
214
|
-
export default ModularCommand;
|
|
215
|
-
export { RegisterCommand, ModularCommand, ModularButton, };
|