js-discord-modularcommand 1.0.0 → 1.1.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/index.d.ts +13 -0
- package/dist/index.js +19 -0
- package/dist/locales.d.ts +51 -0
- package/dist/locales.js +250 -0
- package/dist/modularcommand.d.ts +60 -101
- package/dist/modularcommand.js +70 -258
- package/dist/modularmodal.d.ts +66 -0
- package/dist/modularmodal.js +82 -0
- package/package.json +13 -7
- package/index.js +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# JS Discord ModularCommand
|
|
2
|
+
|
|
3
|
+
A module to create and manage modular commands in a simple way for Discord.js bots.
|
|
4
|
+
|
|
5
|
+
## What is it for?
|
|
6
|
+
|
|
7
|
+
This library simplifies the creation and management of slash commands for [Discord.js](https://discord.js.org/). It allows you to structure your commands in a modular way, making it easier to handle logic, permissions, cooldowns, localizations, and interactive components like buttons and modals.
|
|
8
|
+
|
|
9
|
+
The main classes are:
|
|
10
|
+
- [`ModularCommand`](src/modularcommand.ts): To define the base structure of a command.
|
|
11
|
+
- [`ModularButton`](src/modularcommand.ts): To create interactive buttons associated with a command.
|
|
12
|
+
- [`ModularModal`](src/modularcommand.ts): To create modals (forms) that the user can fill out.
|
|
13
|
+
|
|
14
|
+
## How to use it?
|
|
15
|
+
|
|
16
|
+
First, install the package in your project:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install js-discord-modularcommand
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then, you can create your commands in a modular fashion. Here is a basic example of a `ping` command:
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
// filepath: commands/ping.js
|
|
26
|
+
const { ModularCommand, RegisterCommand } = require('js-discord-modularcommand');
|
|
27
|
+
const { PermissionFlagsBits } = require('discord.js');
|
|
28
|
+
|
|
29
|
+
// Create a new command instance
|
|
30
|
+
const PingCommand = new ModularCommand('ping');
|
|
31
|
+
|
|
32
|
+
// Set the description
|
|
33
|
+
PingCommand.setDescription('Sends a ping message!');
|
|
34
|
+
|
|
35
|
+
// Optional: Add a permission check
|
|
36
|
+
PingCommand.setPermissionCheck(async ({ interaction }) => {
|
|
37
|
+
return interaction.member.permissions.has(PermissionFlagsBits.Administrator);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Define the logic to be executed
|
|
41
|
+
PingCommand.setExecute(async ({ interaction }) => {
|
|
42
|
+
await interaction.reply('Pong!');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Register the command so it can be used by the Discord.js client
|
|
46
|
+
module.exports = RegisterCommand([
|
|
47
|
+
PingCommand
|
|
48
|
+
]);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
In your main file, you can load the commands and register their executors with your Discord client.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
This project is under the MIT License. See the [LICENSE](LICENSE) file
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModularCommand, ModularButton, RegisterCommand } from "./modularcommand";
|
|
2
|
+
import ModularModal from "./modularmodal";
|
|
3
|
+
import { LOCALE_DELAY, LOCALE_ERROR, LOCALE_FORBIDDEN, LOCALE_NSFW, FormatSecondsLocale } from "./locales";
|
|
4
|
+
export default ModularCommand;
|
|
5
|
+
export { ModularCommand };
|
|
6
|
+
export { ModularButton };
|
|
7
|
+
export { ModularModal };
|
|
8
|
+
export { RegisterCommand };
|
|
9
|
+
export { FormatSecondsLocale };
|
|
10
|
+
export { LOCALE_DELAY };
|
|
11
|
+
export { LOCALE_ERROR };
|
|
12
|
+
export { LOCALE_FORBIDDEN };
|
|
13
|
+
export { LOCALE_NSFW };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LOCALE_NSFW = exports.LOCALE_FORBIDDEN = exports.LOCALE_ERROR = exports.LOCALE_DELAY = exports.FormatSecondsLocale = exports.RegisterCommand = exports.ModularModal = exports.ModularButton = exports.ModularCommand = void 0;
|
|
7
|
+
const modularcommand_1 = require("./modularcommand");
|
|
8
|
+
Object.defineProperty(exports, "ModularCommand", { enumerable: true, get: function () { return modularcommand_1.ModularCommand; } });
|
|
9
|
+
Object.defineProperty(exports, "ModularButton", { enumerable: true, get: function () { return modularcommand_1.ModularButton; } });
|
|
10
|
+
Object.defineProperty(exports, "RegisterCommand", { enumerable: true, get: function () { return modularcommand_1.RegisterCommand; } });
|
|
11
|
+
const modularmodal_1 = __importDefault(require("./modularmodal"));
|
|
12
|
+
exports.ModularModal = modularmodal_1.default;
|
|
13
|
+
const locales_1 = require("./locales");
|
|
14
|
+
Object.defineProperty(exports, "LOCALE_DELAY", { enumerable: true, get: function () { return locales_1.LOCALE_DELAY; } });
|
|
15
|
+
Object.defineProperty(exports, "LOCALE_ERROR", { enumerable: true, get: function () { return locales_1.LOCALE_ERROR; } });
|
|
16
|
+
Object.defineProperty(exports, "LOCALE_FORBIDDEN", { enumerable: true, get: function () { return locales_1.LOCALE_FORBIDDEN; } });
|
|
17
|
+
Object.defineProperty(exports, "LOCALE_NSFW", { enumerable: true, get: function () { return locales_1.LOCALE_NSFW; } });
|
|
18
|
+
Object.defineProperty(exports, "FormatSecondsLocale", { enumerable: true, get: function () { return locales_1.FormatSecondsLocale; } });
|
|
19
|
+
exports.default = modularcommand_1.ModularCommand;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ModularCommand Locales
|
|
3
|
+
* @description Generic localization phrases used throughout the application.
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
import { Locale } from "discord.js";
|
|
7
|
+
/**
|
|
8
|
+
* @description Function to handle seconds format
|
|
9
|
+
* @param phrase The phrase to format
|
|
10
|
+
* @param time The time in seconds
|
|
11
|
+
* @returns The formatted string
|
|
12
|
+
* @example ```javascript
|
|
13
|
+
* const phraseLocale = LOCALE_DELAY[Locale.EnglishUS];
|
|
14
|
+
* const phrasePlural = FormatSecondsLocale(phraseLocale, 90);
|
|
15
|
+
* console.log(phrasePlural); // 'You must wait 1 minute 30 seconds before using this command again.'
|
|
16
|
+
*
|
|
17
|
+
* const phraseSingular = FormatSecondsLocale(phraseLocale, 60);
|
|
18
|
+
* console.log(phraseSingular); // 'You must wait 1 minute before using this command again.'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function FormatSecondsLocale(phrase: string, time: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* @description Localization phrases for delay commands.
|
|
24
|
+
* @example
|
|
25
|
+
* const example = LOCALE_DELAY[Locale.EnglishUS];
|
|
26
|
+
*
|
|
27
|
+
* console.log(FormatTimeLocale(example, 5)); // 'You must wait 5 seconds before using this command again.'
|
|
28
|
+
* console.log(FormatTimeLocale(example, 63)); // 'You must wait 3 seconds and 1 minute before using this command again.'
|
|
29
|
+
*/
|
|
30
|
+
declare const LOCALE_DELAY: Record<Locale, string>;
|
|
31
|
+
/**
|
|
32
|
+
* @description Localization phrases for various commands.
|
|
33
|
+
* @example ```js
|
|
34
|
+
* const example = LOCALE_FORBIDDEN[Locale.EnglishUS];
|
|
35
|
+
* console.log(example); // 'You do not have permission to use this command.'
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare const LOCALE_FORBIDDEN: Record<Locale, string>;
|
|
39
|
+
/**
|
|
40
|
+
* @description Localization phrases for NSFW commands.
|
|
41
|
+
* @example ```js
|
|
42
|
+
* const example = LOCALE_NSFW[Locale.EnglishUS];
|
|
43
|
+
* console.log(example); // 'This command can only be used in NSFW channels.'
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
declare const LOCALE_NSFW: Record<Locale, string>;
|
|
47
|
+
/**
|
|
48
|
+
* Error messages for different locales.
|
|
49
|
+
*/
|
|
50
|
+
declare const LOCALE_ERROR: Record<Locale, string>;
|
|
51
|
+
export { FormatSecondsLocale, LOCALE_DELAY, LOCALE_ERROR, LOCALE_FORBIDDEN, LOCALE_NSFW };
|
package/dist/locales.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module ModularCommand Locales
|
|
4
|
+
* @description Generic localization phrases used throughout the application.
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.LOCALE_NSFW = exports.LOCALE_FORBIDDEN = exports.LOCALE_ERROR = exports.LOCALE_DELAY = void 0;
|
|
9
|
+
exports.FormatSecondsLocale = FormatSecondsLocale;
|
|
10
|
+
const discord_js_1 = require("discord.js");
|
|
11
|
+
/**
|
|
12
|
+
* Regular expressions for time formatting
|
|
13
|
+
* Used to match and replace time-related placeholders in localization strings.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @name SECONDS
|
|
17
|
+
* @description Matches the `{seconds}` placeholder in localization strings to replace it with the amount of seconds of delay.
|
|
18
|
+
*/
|
|
19
|
+
const SECONDS = new RegExp('\\{seconds(?:\\|([^}]+))?\\}', 'g');
|
|
20
|
+
/**
|
|
21
|
+
* @name SECONDS_PLURAL
|
|
22
|
+
* @description Matches the `{seconds|plural|...}` placeholder in localization strings, unlike SECONDS RegEx, this one handles pluralization.
|
|
23
|
+
*/
|
|
24
|
+
const SECONDS_PLURAL = new RegExp('\\{seconds\\|plural\\|([^}]+)\\}', 'g');
|
|
25
|
+
/**
|
|
26
|
+
* @name MINUTES
|
|
27
|
+
* @description The same as `SECONDS`, but for minutes.
|
|
28
|
+
*/
|
|
29
|
+
const MINUTES = new RegExp('\\{minutes(?:\\|([^}]+))?\\}', 'g');
|
|
30
|
+
/**
|
|
31
|
+
* @name MINUTES_PLURAL
|
|
32
|
+
* @description Do we really need an explanation for this RegEx?
|
|
33
|
+
*/
|
|
34
|
+
const MINUTES_PLURAL = new RegExp('\\{minutes\\|plural\\|([^}]+)\\}', 'g');
|
|
35
|
+
/**
|
|
36
|
+
* @description Function to handle seconds format
|
|
37
|
+
* @param phrase The phrase to format
|
|
38
|
+
* @param time The time in seconds
|
|
39
|
+
* @returns The formatted string
|
|
40
|
+
* @example ```javascript
|
|
41
|
+
* const phraseLocale = LOCALE_DELAY[Locale.EnglishUS];
|
|
42
|
+
* const phrasePlural = FormatSecondsLocale(phraseLocale, 90);
|
|
43
|
+
* console.log(phrasePlural); // 'You must wait 1 minute 30 seconds before using this command again.'
|
|
44
|
+
*
|
|
45
|
+
* const phraseSingular = FormatSecondsLocale(phraseLocale, 60);
|
|
46
|
+
* console.log(phraseSingular); // 'You must wait 1 minute before using this command again.'
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
function FormatSecondsLocale(phrase, time) {
|
|
50
|
+
const minutes = Math.floor(time / 60);
|
|
51
|
+
const seconds = time % 60;
|
|
52
|
+
let formattedPhrase = phrase;
|
|
53
|
+
if (minutes > 0) {
|
|
54
|
+
// Replace plural forms for minutes first
|
|
55
|
+
formattedPhrase = formattedPhrase.replace(MINUTES_PLURAL, (match, p1) => {
|
|
56
|
+
return minutes === 1 ? '' : p1;
|
|
57
|
+
});
|
|
58
|
+
// Replace minute values
|
|
59
|
+
formattedPhrase = formattedPhrase.replace(MINUTES, (match, p1) => {
|
|
60
|
+
if (p1) {
|
|
61
|
+
// Handles patterns like {minutes|y $ minuto}
|
|
62
|
+
return p1.replace('$', minutes.toString());
|
|
63
|
+
}
|
|
64
|
+
return minutes.toString();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// If no minutes, remove all minute-related placeholders
|
|
69
|
+
formattedPhrase = formattedPhrase.replace(MINUTES, '').replace(MINUTES_PLURAL, '');
|
|
70
|
+
}
|
|
71
|
+
if (seconds > 0 || minutes === 0) {
|
|
72
|
+
// Replace plural forms for seconds
|
|
73
|
+
formattedPhrase = formattedPhrase.replace(SECONDS_PLURAL, (match, p1) => {
|
|
74
|
+
return seconds === 1 ? '' : p1;
|
|
75
|
+
});
|
|
76
|
+
// Replace second values
|
|
77
|
+
formattedPhrase = formattedPhrase.replace(SECONDS, seconds.toString());
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// If there are minutes but no seconds, remove second-related placeholders
|
|
81
|
+
formattedPhrase = formattedPhrase.replace(SECONDS, '').replace(SECONDS_PLURAL, '');
|
|
82
|
+
}
|
|
83
|
+
// Clean up any remaining empty placeholders and extra spaces
|
|
84
|
+
return formattedPhrase.replace(/\{[^}]+\}/g, '').replace(/\s+/g, ' ').trim();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @description Localization phrases for delay commands.
|
|
88
|
+
* @example
|
|
89
|
+
* const example = LOCALE_DELAY[Locale.EnglishUS];
|
|
90
|
+
*
|
|
91
|
+
* console.log(FormatTimeLocale(example, 5)); // 'You must wait 5 seconds before using this command again.'
|
|
92
|
+
* console.log(FormatTimeLocale(example, 63)); // 'You must wait 3 seconds and 1 minute before using this command again.'
|
|
93
|
+
*/
|
|
94
|
+
const LOCALE_DELAY = {
|
|
95
|
+
[discord_js_1.Locale.SpanishLATAM]: 'Debes esperar {seconds} segundo{seconds|plural|s} {minutes|y $ minuto}{minutes|plural|s} antes de utilizar este comando denuevo.',
|
|
96
|
+
[discord_js_1.Locale.EnglishUS]: 'You must wait {seconds} second{seconds|plural|s} {minutes|and $ minute}{minutes|plural|s} before using this command again.',
|
|
97
|
+
[discord_js_1.Locale.EnglishGB]: 'Good heavens! One must exhibit a spot of patience, you see. A brief pause of {seconds} second{seconds|plural|s} {minutes|and $ minute}{minutes|plural|s} is required before another attempt, what?',
|
|
98
|
+
[discord_js_1.Locale.SpanishES]: '¡Joder, tío! ¡Que te esperes {seconds} segundo{seconds|plural|s} {minutes|y $ minuto}{minutes|plural|s}, coño! ¡No flipes y dale un respiro al bot, hostia ya!',
|
|
99
|
+
[discord_js_1.Locale.PortugueseBR]: 'Você deve esperar {seconds} segundo{seconds|plural|s} {minutes|e $ minuto}{minutes|plural|s} antes de usar este comando novamente.',
|
|
100
|
+
[discord_js_1.Locale.French]: 'Vous devez attendre {seconds} seconde{seconds|plural|s} {minutes|et $ minute}{minutes|plural|s} avant d\'utiliser cette commande à nouveau.',
|
|
101
|
+
[discord_js_1.Locale.German]: 'Sie müssen {seconds} Sekunde{seconds|plural|n} {minutes|und $ Minute}{minutes|plural|n} warten, bevor Sie diesen Befehl erneut verwenden können.',
|
|
102
|
+
[discord_js_1.Locale.Italian]: 'Devi aspettare {seconds} secondo{seconds|plural|i} {minutes|e $ minuto}{minutes|plural|i} prima di utilizzare di nuovo questo comando.',
|
|
103
|
+
[discord_js_1.Locale.Russian]: 'Вы должны подождать {seconds} секунд{seconds|plural|у} {minutes|и $ минут}{minutes|plural|ы} перед повторным использованием этой команды.',
|
|
104
|
+
[discord_js_1.Locale.ChineseCN]: '您必须等待 {seconds} 秒 {minutes|和 $ 分钟} 才能再次使用此命令。',
|
|
105
|
+
[discord_js_1.Locale.ChineseTW]: '您必須等待 {seconds} 秒 {minutes|和 $ 分鐘} 才能再次使用此命令。',
|
|
106
|
+
[discord_js_1.Locale.Japanese]: 'このコマンドを再度使用するには、{seconds} 秒 {minutes|と $ 分} 待つ必要があります。',
|
|
107
|
+
[discord_js_1.Locale.Korean]: '이 명령어를 다시 사용하려면 {seconds} 초 {minutes|하고 $ 분} 기다려야 합니다.',
|
|
108
|
+
[discord_js_1.Locale.Bulgarian]: 'Трябва да изчакате {seconds} секунд{seconds|plural|и} {minutes|и $ минут}{minutes|plural|и}, преди да използвате тази команда отново.',
|
|
109
|
+
[discord_js_1.Locale.Czech]: 'Musíte počkat {seconds} sekund{seconds|plural|u} {minutes|a $ minut}{minutes|plural|y}, než znovu použijete tento příkaz.',
|
|
110
|
+
[discord_js_1.Locale.Danish]: 'Du skal vente {seconds} sekund{seconds|plural|er} {minutes|og $ minut}{minutes|plural|ter} før du kan bruge denne kommando igen.',
|
|
111
|
+
[discord_js_1.Locale.Dutch]: 'Je moet {seconds} seconde{seconds|plural|n} {minutes|en $ minuut}{minutes|plural|en} wachten voordat je dit commando opnieuw kunt gebruiken.',
|
|
112
|
+
[discord_js_1.Locale.Finnish]: 'Sinun on odotettava {seconds} sekunti{seconds|plural|a} {minutes|ja $ minuutti}{minutes|plural|a} ennen kuin voit käyttää tätä komentoa uudelleen.',
|
|
113
|
+
[discord_js_1.Locale.Hungarian]: 'Várnod kell {seconds} másodperc{seconds|plural|et} {minutes|és $ perc}{minutes|plural|et}, mielőtt újra használhatod ezt a parancsot.',
|
|
114
|
+
[discord_js_1.Locale.Norwegian]: 'Du må vente {seconds} sekund{seconds|plural|er} {minutes|og $ minutt}{minutes|plural|er} før du kan bruke denne kommandoen igjen.',
|
|
115
|
+
[discord_js_1.Locale.Polish]: 'Musisz poczekać {seconds} sekund{seconds|plural|y} {minutes|i $ minut}{minutes|plural|y}, zanim ponownie użyjesz tego polecenia.',
|
|
116
|
+
[discord_js_1.Locale.Romanian]: 'Trebuie să aștepți {seconds} secund{seconds|plural|ă} {minutes|și $ minut}{minutes|plural|e} înainte de a folosi din nou acest comandă.',
|
|
117
|
+
[discord_js_1.Locale.Swedish]: 'Du måste vänta {seconds} sekund{seconds|plural|er} {minutes|och $ minut}{minutes|plural|er} innan du kan använda det här kommandot igen.',
|
|
118
|
+
[discord_js_1.Locale.Turkish]: 'Bu komutu tekrar kullanmadan önce {seconds} saniye {minutes|ve $ dakika} beklemelisiniz.',
|
|
119
|
+
[discord_js_1.Locale.Ukrainian]: 'Вам потрібно почекати {seconds} секунд{seconds|plural|и} {minutes|і $ хвилин}{minutes|plural|и}, перш ніж знову використовувати цю команду.',
|
|
120
|
+
[discord_js_1.Locale.Hindi]: 'आपको इस कमांड का उपयोग करने से पहले {seconds} सेकंड {minutes|और $ मिनट} इंतजार करना होगा।',
|
|
121
|
+
[discord_js_1.Locale.Indonesian]: 'Anda harus menunggu {seconds} detik {minutes|dan $ menit} sebelum menggunakan perintah ini lagi.',
|
|
122
|
+
[discord_js_1.Locale.Greek]: 'Πρέπει να περιμένετε {seconds} δευτερόλεπτ{seconds|plural|ο} {minutes|και $ λεπτό}{minutes|plural|ά} πριν χρησιμοποιήσετε ξανά αυτήν την εντολή.',
|
|
123
|
+
[discord_js_1.Locale.Croatian]: 'Morate pričekati {seconds} sekund{seconds|plural|u} {minutes|i $ minut}{minutes|plural|e} prije nego što ponovno upotrijebite ovu naredbu.',
|
|
124
|
+
[discord_js_1.Locale.Lithuanian]: 'Prieš vėl naudodamiesi šiuo komandu, turite palaukti {seconds} sekund{seconds|plural|ę} {minutes|ir $ minut}{minutes|plural|es}.',
|
|
125
|
+
[discord_js_1.Locale.Thai]: 'คุณต้องรอ {seconds} วินาที {minutes|และ $ นาที} ก่อนที่จะใช้คำสั่งนี้อีกครั้ง',
|
|
126
|
+
[discord_js_1.Locale.Vietnamese]: 'Bạn phải đợi {seconds} giây {minutes|và $ phút} trước khi sử dụng lại lệnh này.'
|
|
127
|
+
};
|
|
128
|
+
exports.LOCALE_DELAY = LOCALE_DELAY;
|
|
129
|
+
/**
|
|
130
|
+
* @description Localization phrases for various commands.
|
|
131
|
+
* @example ```js
|
|
132
|
+
* const example = LOCALE_FORBIDDEN[Locale.EnglishUS];
|
|
133
|
+
* console.log(example); // 'You do not have permission to use this command.'
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
const LOCALE_FORBIDDEN = {
|
|
137
|
+
[discord_js_1.Locale.SpanishLATAM]: 'No tienes permiso para usar este comando.',
|
|
138
|
+
[discord_js_1.Locale.EnglishUS]: 'You do not have permission to use this command.',
|
|
139
|
+
[discord_js_1.Locale.EnglishGB]: 'I say, it appears you lack the proper authorisation to utilise this command, old bean.',
|
|
140
|
+
[discord_js_1.Locale.SpanishES]: 'Ostias chaval, tio parece que no vais a poder usar este comando madre mia willy, que barbaridad.',
|
|
141
|
+
[discord_js_1.Locale.PortugueseBR]: 'Você não tem permissão para usar este comando.',
|
|
142
|
+
[discord_js_1.Locale.French]: 'Vous n\'avez pas la permission d\'utiliser cette commande.',
|
|
143
|
+
[discord_js_1.Locale.German]: 'Du hast keine Berechtigung, diesen Befehl zu verwenden.',
|
|
144
|
+
[discord_js_1.Locale.Italian]: 'Non hai il permesso di usare questo comando.',
|
|
145
|
+
[discord_js_1.Locale.Russian]: 'У вас нет разрешения на использование этой команды.',
|
|
146
|
+
[discord_js_1.Locale.ChineseCN]: '您没有权限使用此命令。',
|
|
147
|
+
[discord_js_1.Locale.ChineseTW]: '您沒有權限使用此命令。',
|
|
148
|
+
[discord_js_1.Locale.Japanese]: 'このコマンドを使用する権限がありません。',
|
|
149
|
+
[discord_js_1.Locale.Korean]: '이 명령을 사용할 권한이 없습니다.',
|
|
150
|
+
[discord_js_1.Locale.Bulgarian]: 'Нямате разрешение да използвате тази команда.',
|
|
151
|
+
[discord_js_1.Locale.Czech]: 'Nemáte oprávnění k použití tohoto příkazu.',
|
|
152
|
+
[discord_js_1.Locale.Danish]: 'Du har ikke tilladelse til at bruge denne kommando.',
|
|
153
|
+
[discord_js_1.Locale.Dutch]: 'Je hebt geen toestemming om deze opdracht te gebruiken.',
|
|
154
|
+
[discord_js_1.Locale.Finnish]: 'Sinulla ei ole lupaa käyttää tätä komentoa.',
|
|
155
|
+
[discord_js_1.Locale.Hungarian]: 'Nincs jogosultságod ehhez a parancshoz.',
|
|
156
|
+
[discord_js_1.Locale.Norwegian]: 'Du har ikke tillatelse til å bruke denne kommandoen.',
|
|
157
|
+
[discord_js_1.Locale.Polish]: 'Nie masz uprawnień do używania tej komendy.',
|
|
158
|
+
[discord_js_1.Locale.Romanian]: 'Nu ai permisiunea de a folosi acest comandă.',
|
|
159
|
+
[discord_js_1.Locale.Swedish]: 'Du har inte behörighet att använda det här kommandot.',
|
|
160
|
+
[discord_js_1.Locale.Turkish]: 'Bu komutu kullanma izniniz yok.',
|
|
161
|
+
[discord_js_1.Locale.Ukrainian]: 'У вас немає дозволу на використання цієї команди.',
|
|
162
|
+
[discord_js_1.Locale.Hindi]: 'आपको इस कमांड का उपयोग करने की अनुमति नहीं है।',
|
|
163
|
+
[discord_js_1.Locale.Indonesian]: 'Anda tidak memiliki izin untuk menggunakan perintah ini.',
|
|
164
|
+
[discord_js_1.Locale.Greek]: 'Δεν έχετε άδεια να χρησιμοποιήσετε αυτήν την εντολή.',
|
|
165
|
+
[discord_js_1.Locale.Croatian]: 'Nemate dopuštenje za korištenje ove naredbe.',
|
|
166
|
+
[discord_js_1.Locale.Lithuanian]: 'Jūs neturite teisės naudoti šio komandos.',
|
|
167
|
+
[discord_js_1.Locale.Thai]: 'คุณไม่มีสิทธิ์ใช้คำสั่งนี้.',
|
|
168
|
+
[discord_js_1.Locale.Vietnamese]: 'Bạn không có quyền sử dụng lệnh này.'
|
|
169
|
+
};
|
|
170
|
+
exports.LOCALE_FORBIDDEN = LOCALE_FORBIDDEN;
|
|
171
|
+
/**
|
|
172
|
+
* @description Localization phrases for NSFW commands.
|
|
173
|
+
* @example ```js
|
|
174
|
+
* const example = LOCALE_NSFW[Locale.EnglishUS];
|
|
175
|
+
* console.log(example); // 'This command can only be used in NSFW channels.'
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
const LOCALE_NSFW = {
|
|
179
|
+
[discord_js_1.Locale.SpanishLATAM]: 'Este comando solo puede ser usado en canales NSFW.',
|
|
180
|
+
[discord_js_1.Locale.EnglishUS]: 'This command can only be used in NSFW channels.',
|
|
181
|
+
[discord_js_1.Locale.EnglishGB]: 'I do declare, this command is exclusively for channels of a... risqué nature. little bit of cheeky fun, eh?',
|
|
182
|
+
[discord_js_1.Locale.SpanishES]: '¡Ostias, chaval! Que este comando es solo para los canales más guarros, ¿vale? No me seas meapilas.',
|
|
183
|
+
[discord_js_1.Locale.PortugueseBR]: 'Este comando só pode ser usado em canais NSFW.',
|
|
184
|
+
[discord_js_1.Locale.French]: 'Cette commande ne peut être utilisée que dans les salons NSFW.',
|
|
185
|
+
[discord_js_1.Locale.German]: 'Dieser Befehl kann nur in NSFW-Kanälen verwendet werden.',
|
|
186
|
+
[discord_js_1.Locale.Italian]: 'Questo comando può essere utilizzato solo nei canali NSFW.',
|
|
187
|
+
[discord_js_1.Locale.Russian]: 'Эту команду можно использовать только в каналах NSFW.',
|
|
188
|
+
[discord_js_1.Locale.ChineseCN]: '此命令只能在NSFW频道中使用。',
|
|
189
|
+
[discord_js_1.Locale.ChineseTW]: '此命令只能在 NSFW 頻道中使用。',
|
|
190
|
+
[discord_js_1.Locale.Japanese]: 'このコマンドはNSFWチャンネルでのみ使用できます。',
|
|
191
|
+
[discord_js_1.Locale.Korean]: '이 명령어는 NSFW 채널에서만 사용할 수 있습니다.',
|
|
192
|
+
[discord_js_1.Locale.Bulgarian]: 'Тази команда може да се използва само в NSFW канали.',
|
|
193
|
+
[discord_js_1.Locale.Czech]: 'Tento příkaz lze použít pouze v kanálech NSFW.',
|
|
194
|
+
[discord_js_1.Locale.Danish]: 'Denne kommando kan kun bruges i NSFW-kanaler.',
|
|
195
|
+
[discord_js_1.Locale.Dutch]: 'Deze opdracht kan alleen worden gebruikt in NSFW-kanalen.',
|
|
196
|
+
[discord_js_1.Locale.Finnish]: 'Tätä komentoa voi käyttää vain NSFW-kanavilla.',
|
|
197
|
+
[discord_js_1.Locale.Hungarian]: 'Ez a parancs csak NSFW csatornákon használható.',
|
|
198
|
+
[discord_js_1.Locale.Norwegian]: 'Denne kommandoen kan bare brukes i NSFW-kanaler.',
|
|
199
|
+
[discord_js_1.Locale.Polish]: 'Ta komenda może być używana tylko na kanałach NSFW.',
|
|
200
|
+
[discord_js_1.Locale.Romanian]: 'Această comandă poate fi utilizată numai în canalele NSFW.',
|
|
201
|
+
[discord_js_1.Locale.Swedish]: 'Det här kommandot kan endast användas i NSFW-kanaler.',
|
|
202
|
+
[discord_js_1.Locale.Turkish]: 'Bu komut yalnızca NSFW kanallarında kullanılabilir.',
|
|
203
|
+
[discord_js_1.Locale.Ukrainian]: 'Цю команду можна використовувати лише в каналах NSFW.',
|
|
204
|
+
[discord_js_1.Locale.Hindi]: 'यह कमांड केवल NSFW चैनलों में ही उपयोग की जा सकती है।',
|
|
205
|
+
[discord_js_1.Locale.Indonesian]: 'Perintah ini hanya dapat digunakan di saluran NSFW.',
|
|
206
|
+
[discord_js_1.Locale.Greek]: 'Αυτή η εντολή μπορεί να χρησιμοποιηθεί μόνο σε κανάλια NSFW.',
|
|
207
|
+
[discord_js_1.Locale.Croatian]: 'Ova se naredba može koristiti samo u NSFW kanalima.',
|
|
208
|
+
[discord_js_1.Locale.Lithuanian]: 'Ši komanda gali būti naudojama tik NSFW kanaluose.',
|
|
209
|
+
[discord_js_1.Locale.Thai]: 'คำสั่งนี้สามารถใช้ได้เฉพาะในช่องทาง NSFW เท่านั้น.',
|
|
210
|
+
[discord_js_1.Locale.Vietnamese]: 'Lệnh này chỉ có thể được sử dụng trong các kênh NSFW.'
|
|
211
|
+
};
|
|
212
|
+
exports.LOCALE_NSFW = LOCALE_NSFW;
|
|
213
|
+
/**
|
|
214
|
+
* Error messages for different locales.
|
|
215
|
+
*/
|
|
216
|
+
const LOCALE_ERROR = {
|
|
217
|
+
[discord_js_1.Locale.SpanishLATAM]: 'Ocurrió un error al procesar tu solicitud.',
|
|
218
|
+
[discord_js_1.Locale.EnglishUS]: 'An error occurred while processing your request.',
|
|
219
|
+
[discord_js_1.Locale.EnglishGB]: 'I do declare, an error occurred while processing your request.',
|
|
220
|
+
[discord_js_1.Locale.SpanishES]: 'Pero que me estás contando, willy, ocurrió un error al procesar tu solicitud.',
|
|
221
|
+
[discord_js_1.Locale.PortugueseBR]: 'Ocorreu um erro ao processar sua solicitação.',
|
|
222
|
+
[discord_js_1.Locale.French]: 'Une erreur est survenue lors du traitement de votre demande.',
|
|
223
|
+
[discord_js_1.Locale.German]: 'Bei der Verarbeitung Ihrer Anfrage ist ein Fehler aufgetreten.',
|
|
224
|
+
[discord_js_1.Locale.Italian]: 'Si è verificato un errore durante l\'elaborazione della tua richiesta.',
|
|
225
|
+
[discord_js_1.Locale.Russian]: 'Произошла ошибка при обработке вашего запроса.',
|
|
226
|
+
[discord_js_1.Locale.ChineseCN]: '处理您的请求时发生错误。',
|
|
227
|
+
[discord_js_1.Locale.ChineseTW]: '處理您的請求時發生錯誤。',
|
|
228
|
+
[discord_js_1.Locale.Japanese]: 'リクエストの処理中にエラーが発生しました。',
|
|
229
|
+
[discord_js_1.Locale.Korean]: '요청을 처리하는 동안 오류가 발생했습니다.',
|
|
230
|
+
[discord_js_1.Locale.Bulgarian]: 'При обработката на заявката ви възникна грешка.',
|
|
231
|
+
[discord_js_1.Locale.Czech]: 'Při zpracování vaší žádosti došlo k chybě.',
|
|
232
|
+
[discord_js_1.Locale.Danish]: 'Der opstod en fejl under behandlingen af din anmodning.',
|
|
233
|
+
[discord_js_1.Locale.Dutch]: 'Er is een fout opgetreden bij het verwerken van uw verzoek.',
|
|
234
|
+
[discord_js_1.Locale.Finnish]: 'Pyyntösi käsittelyssä tapahtui virhe.',
|
|
235
|
+
[discord_js_1.Locale.Hungarian]: 'A kérésed feldolgozása során hiba lépett fel.',
|
|
236
|
+
[discord_js_1.Locale.Norwegian]: 'Det oppstod en feil under behandling av forespørselen din.',
|
|
237
|
+
[discord_js_1.Locale.Polish]: 'Wystąpił błąd podczas przetwarzania twojej prośby.',
|
|
238
|
+
[discord_js_1.Locale.Romanian]: 'A apărut o eroare în timpul procesării cererii tale.',
|
|
239
|
+
[discord_js_1.Locale.Swedish]: 'Ett fel inträffade vid behandling av din begäran.',
|
|
240
|
+
[discord_js_1.Locale.Turkish]: 'Talebiniz işlenirken bir hata oluştu.',
|
|
241
|
+
[discord_js_1.Locale.Ukrainian]: 'Під час обробки вашого запиту сталася помилка.',
|
|
242
|
+
[discord_js_1.Locale.Hindi]: 'आपके अनुरोध को संसाधित करते समय एक त्रुटि हुई।',
|
|
243
|
+
[discord_js_1.Locale.Indonesian]: 'Terjadi kesalahan saat memproses permintaan Anda.',
|
|
244
|
+
[discord_js_1.Locale.Greek]: 'Συνέβη σφάλμα κατά την επεξεργασία του αιτήματός σας.',
|
|
245
|
+
[discord_js_1.Locale.Croatian]: 'Došlo je do pogreške prilikom obrade vašeg zahtjeva.',
|
|
246
|
+
[discord_js_1.Locale.Lithuanian]: 'Apdorojant jūsų užklausą įvyko klaida.',
|
|
247
|
+
[discord_js_1.Locale.Thai]: 'เกิดข้อผิดพลาดระหว่างการประมวลผลคำขอของคุณ',
|
|
248
|
+
[discord_js_1.Locale.Vietnamese]: 'Đã xảy ra lỗi trong quá trình xử lý yêu cầu của bạn.'
|
|
249
|
+
};
|
|
250
|
+
exports.LOCALE_ERROR = LOCALE_ERROR;
|
package/dist/modularcommand.d.ts
CHANGED
|
@@ -6,38 +6,8 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Imports
|
|
8
8
|
*/
|
|
9
|
-
import { ApplicationCommandOptionType, MessageComponentInteraction, ChatInputCommandInteraction, ModalSubmitInteraction, SlashCommandBuilder,
|
|
10
|
-
|
|
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>;
|
|
9
|
+
import { ApplicationCommandOptionType, MessageComponentInteraction, ChatInputCommandInteraction, ModalSubmitInteraction, SlashCommandBuilder, ButtonBuilder, Locale, Message, ButtonStyle, Channel, User, Role, GuildMember, LocalizationMap, APIApplicationCommandOptionChoice } from 'discord.js';
|
|
10
|
+
import ModularModal from './modularmodal.js';
|
|
41
11
|
/**
|
|
42
12
|
* Types
|
|
43
13
|
*/
|
|
@@ -60,17 +30,36 @@ type ModalExecuteFunction = (params: {
|
|
|
60
30
|
command: ModularCommand;
|
|
61
31
|
locale: Record<string, any>;
|
|
62
32
|
}) => Promise<void>;
|
|
63
|
-
type PermissionCheckFunction = (
|
|
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
|
+
};
|
|
64
57
|
/**
|
|
65
58
|
* Interface
|
|
66
59
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
execute?: ExecuteFunction<ChatInputCommandInteraction>;
|
|
71
|
-
componentExecute?: ExecuteFunction<MessageComponentInteraction>;
|
|
72
|
-
modalExecute?: ModalExecuteFunction;
|
|
73
|
-
}
|
|
60
|
+
/**
|
|
61
|
+
* @description Represents a command option for a modular command.
|
|
62
|
+
*/
|
|
74
63
|
interface CommandOption {
|
|
75
64
|
name: string;
|
|
76
65
|
type: ApplicationCommandOptionType;
|
|
@@ -78,14 +67,6 @@ interface CommandOption {
|
|
|
78
67
|
required?: boolean;
|
|
79
68
|
choices?: APIApplicationCommandOptionChoice[];
|
|
80
69
|
}
|
|
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
70
|
/**
|
|
90
71
|
* @class ModularButton
|
|
91
72
|
* @description Represents a modular button that can be registered with Discord.js.
|
|
@@ -110,46 +91,24 @@ declare class ModularButton {
|
|
|
110
91
|
setExecute(executeFunction: ButtonExecuteFunction): this;
|
|
111
92
|
}
|
|
112
93
|
/**
|
|
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
94
|
* @description Represents a modular command that can be registered with Discord.js.
|
|
152
95
|
* It allows for dynamic command creation and execution.
|
|
96
|
+
* @example
|
|
97
|
+
* const { ModularCommand, RegisterCommand } = require('js-discord-modularcommand');
|
|
98
|
+
*
|
|
99
|
+
* const PingCommand = new ModularCommand('ping');
|
|
100
|
+
* PingCommand.setDescription('Sends a ping message.');
|
|
101
|
+
* PingCommand.setExecute(async ({interaction}) => {
|
|
102
|
+
* await interaction.reply('Pong!');
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* PingCommand.setPermissionCheck(({ interaction }) => {
|
|
106
|
+
* return interaction.member.permissions.has(PermissionFlagsBits.Administrator);
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* module.exports = RegisterCommand([
|
|
110
|
+
* PingCommand
|
|
111
|
+
* ]);
|
|
153
112
|
*/
|
|
154
113
|
declare class ModularCommand {
|
|
155
114
|
name: string;
|
|
@@ -169,7 +128,7 @@ declare class ModularCommand {
|
|
|
169
128
|
localizationPhrases?: Record<Locale, any>;
|
|
170
129
|
permissionCheck?: PermissionCheckFunction;
|
|
171
130
|
componentId?: string;
|
|
172
|
-
constructor(
|
|
131
|
+
constructor(name: string);
|
|
173
132
|
/**
|
|
174
133
|
* Sets the description of the command.
|
|
175
134
|
* @param {string} description The description.
|
|
@@ -202,19 +161,6 @@ declare class ModularCommand {
|
|
|
202
161
|
* @returns {ModularCommand} The command instance for chaining.
|
|
203
162
|
*/
|
|
204
163
|
setComponentExecute(componentId: string, executeFunction: ExecuteFunction<MessageComponentInteraction>): this;
|
|
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;
|
|
218
164
|
/**
|
|
219
165
|
* Set the minimun permissions required to execute the command.
|
|
220
166
|
* @param {PermissionCheckFunction} permissionCheckFunction The function to check permissions.
|
|
@@ -245,6 +191,19 @@ declare class ModularCommand {
|
|
|
245
191
|
* @returns {ModularCommand} The command instance for chaining.
|
|
246
192
|
*/
|
|
247
193
|
addCustomIDHandler(customId: string, handlerFunction: ExecuteFunction<ChatInputCommandInteraction>): this;
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new modal for the command.
|
|
196
|
+
* @param {string} modalId The ID for the modal.
|
|
197
|
+
* @returns {ModularModal} The created modal instance.
|
|
198
|
+
*/
|
|
199
|
+
addModal(modalId: string): ModularModal;
|
|
200
|
+
/**
|
|
201
|
+
* Creates a new button for the command.
|
|
202
|
+
* @param {string} customId The custom ID for the button.
|
|
203
|
+
* @param {ButtonStyle} style The style of the button.
|
|
204
|
+
* @return {ModularButton} The created button instance.
|
|
205
|
+
*/
|
|
206
|
+
addButton(customId: string, style: ButtonStyle): ModularButton;
|
|
248
207
|
}
|
|
249
208
|
/**
|
|
250
209
|
* Registers an array of modular commands.
|
|
@@ -253,4 +212,4 @@ declare class ModularCommand {
|
|
|
253
212
|
*/
|
|
254
213
|
declare const RegisterCommand: (commands: ModularCommand[]) => RegisteredCommand[];
|
|
255
214
|
export default ModularCommand;
|
|
256
|
-
export { RegisterCommand, ModularCommand, ModularButton,
|
|
215
|
+
export { RegisterCommand, ModularCommand, ModularButton, };
|
package/dist/modularcommand.js
CHANGED
|
@@ -4,179 +4,18 @@
|
|
|
4
4
|
* @description A module for creating and managing modular commands in a easy way for me.
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
7
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
11
|
+
exports.ModularButton = exports.ModularCommand = exports.RegisterCommand = void 0;
|
|
9
12
|
/**
|
|
10
13
|
* Imports
|
|
11
14
|
*/
|
|
12
15
|
const discord_js_1 = require("discord.js");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @description Localization phrases for various commands.
|
|
18
|
-
* @example
|
|
19
|
-
* const example = LOCALE_FORBIDDEN[Locale.EnglishUS];
|
|
20
|
-
* console.log(example); // 'You do not have permission to use this command.'
|
|
21
|
-
*/
|
|
22
|
-
const LOCALE_FORBIDDEN = {
|
|
23
|
-
[discord_js_1.Locale.SpanishLATAM]: 'No tienes permiso para usar este comando.',
|
|
24
|
-
[discord_js_1.Locale.EnglishUS]: 'You do not have permission to use this command.',
|
|
25
|
-
[discord_js_1.Locale.EnglishGB]: 'I say, it appears you lack the proper authorisation to utilise this command, old bean.',
|
|
26
|
-
[discord_js_1.Locale.SpanishES]: 'Ostias chaval, tio parece que no vais a poder usar este comando madre mia willy, que barbaridad.',
|
|
27
|
-
[discord_js_1.Locale.PortugueseBR]: 'Você não tem permissão para usar este comando.',
|
|
28
|
-
[discord_js_1.Locale.French]: 'Vous n\'avez pas la permission d\'utiliser cette commande.',
|
|
29
|
-
[discord_js_1.Locale.German]: 'Du hast keine Berechtigung, diesen Befehl zu verwenden.',
|
|
30
|
-
[discord_js_1.Locale.Italian]: 'Non hai il permesso di usare questo comando.',
|
|
31
|
-
[discord_js_1.Locale.Russian]: 'У вас нет разрешения на использование этой команды.',
|
|
32
|
-
[discord_js_1.Locale.ChineseCN]: '您没有权限使用此命令。',
|
|
33
|
-
[discord_js_1.Locale.ChineseTW]: '您沒有權限使用此命令。',
|
|
34
|
-
[discord_js_1.Locale.Japanese]: 'このコマンドを使用する権限がありません。',
|
|
35
|
-
[discord_js_1.Locale.Korean]: '이 명령을 사용할 권한이 없습니다.',
|
|
36
|
-
[discord_js_1.Locale.Bulgarian]: 'Нямате разрешение да използвате тази команда.',
|
|
37
|
-
[discord_js_1.Locale.Czech]: 'Nemáte oprávnění k použití tohoto příkazu.',
|
|
38
|
-
[discord_js_1.Locale.Danish]: 'Du har ikke tilladelse til at bruge denne kommando.',
|
|
39
|
-
[discord_js_1.Locale.Dutch]: 'Je hebt geen toestemming om deze opdracht te gebruiken.',
|
|
40
|
-
[discord_js_1.Locale.Finnish]: 'Sinulla ei ole lupaa käyttää tätä komentoa.',
|
|
41
|
-
[discord_js_1.Locale.Hungarian]: 'Nincs jogosultságod ehhez a parancshoz.',
|
|
42
|
-
[discord_js_1.Locale.Norwegian]: 'Du har ikke tillatelse til å bruke denne kommandoen.',
|
|
43
|
-
[discord_js_1.Locale.Polish]: 'Nie masz uprawnień do używania tej komendy.',
|
|
44
|
-
[discord_js_1.Locale.Romanian]: 'Nu ai permisiunea de a folosi acest comandă.',
|
|
45
|
-
[discord_js_1.Locale.Swedish]: 'Du har inte behörighet att använda det här kommandot.',
|
|
46
|
-
[discord_js_1.Locale.Turkish]: 'Bu komutu kullanma izniniz yok.',
|
|
47
|
-
[discord_js_1.Locale.Ukrainian]: 'У вас немає дозволу на використання цієї команди.',
|
|
48
|
-
[discord_js_1.Locale.Hindi]: 'आपको इस कमांड का उपयोग करने की अनुमति नहीं है।',
|
|
49
|
-
[discord_js_1.Locale.Indonesian]: 'Anda tidak memiliki izin untuk menggunakan perintah ini.',
|
|
50
|
-
[discord_js_1.Locale.Greek]: 'Δεν έχετε άδεια να χρησιμοποιήσετε αυτήν την εντολή.',
|
|
51
|
-
[discord_js_1.Locale.Croatian]: 'Nemate dopuštenje za korištenje ove naredbe.',
|
|
52
|
-
[discord_js_1.Locale.Lithuanian]: 'Jūs neturite teisės naudoti šio komandos.',
|
|
53
|
-
[discord_js_1.Locale.Thai]: 'คุณไม่มีสิทธิ์ใช้คำสั่งนี้.',
|
|
54
|
-
[discord_js_1.Locale.Vietnamese]: 'Bạn không có quyền sử dụng lệnh này.'
|
|
55
|
-
};
|
|
56
|
-
exports.LOCALE_FORBIDDEN = LOCALE_FORBIDDEN;
|
|
57
|
-
/**
|
|
58
|
-
* @description Localization phrases for NSFW commands.
|
|
59
|
-
* @example
|
|
60
|
-
* const example = LOCALE_NSFW[Locale.EnglishUS];
|
|
61
|
-
* console.log(example); // 'This command can only be used in NSFW channels.'
|
|
62
|
-
*/
|
|
63
|
-
const LOCALE_NSFW = {
|
|
64
|
-
[discord_js_1.Locale.SpanishLATAM]: 'Este comando solo puede ser usado en canales NSFW.',
|
|
65
|
-
[discord_js_1.Locale.EnglishUS]: 'This command can only be used in NSFW channels.',
|
|
66
|
-
[discord_js_1.Locale.EnglishGB]: 'I do declare, this command is exclusively for channels of a... risqué nature. little bit of cheeky fun, eh?',
|
|
67
|
-
[discord_js_1.Locale.SpanishES]: '¡Ostias, chaval! Que este comando es solo para los canales más guarros, ¿vale? No me seas meapilas.',
|
|
68
|
-
[discord_js_1.Locale.PortugueseBR]: 'Este comando só pode ser usado em canais NSFW.',
|
|
69
|
-
[discord_js_1.Locale.French]: 'Cette commande ne peut être utilisée que dans les salons NSFW.',
|
|
70
|
-
[discord_js_1.Locale.German]: 'Dieser Befehl kann nur in NSFW-Kanälen verwendet werden.',
|
|
71
|
-
[discord_js_1.Locale.Italian]: 'Questo comando può essere utilizzato solo nei canali NSFW.',
|
|
72
|
-
[discord_js_1.Locale.Russian]: 'Эту команду можно использовать только в каналах NSFW.',
|
|
73
|
-
[discord_js_1.Locale.ChineseCN]: '此命令只能在NSFW频道中使用。',
|
|
74
|
-
[discord_js_1.Locale.ChineseTW]: '此命令只能在 NSFW 頻道中使用。',
|
|
75
|
-
[discord_js_1.Locale.Japanese]: 'このコマンドはNSFWチャンネルでのみ使用できます。',
|
|
76
|
-
[discord_js_1.Locale.Korean]: '이 명령어는 NSFW 채널에서만 사용할 수 있습니다.',
|
|
77
|
-
[discord_js_1.Locale.Bulgarian]: 'Тази команда може да се използва само в NSFW канали.',
|
|
78
|
-
[discord_js_1.Locale.Czech]: 'Tento příkaz lze použít pouze v kanálech NSFW.',
|
|
79
|
-
[discord_js_1.Locale.Danish]: 'Denne kommando kan kun bruges i NSFW-kanaler.',
|
|
80
|
-
[discord_js_1.Locale.Dutch]: 'Deze opdracht kan alleen worden gebruikt in NSFW-kanalen.',
|
|
81
|
-
[discord_js_1.Locale.Finnish]: 'Tätä komentoa voi käyttää vain NSFW-kanavilla.',
|
|
82
|
-
[discord_js_1.Locale.Hungarian]: 'Ez a parancs csak NSFW csatornákon használható.',
|
|
83
|
-
[discord_js_1.Locale.Norwegian]: 'Denne kommandoen kan bare brukes i NSFW-kanaler.',
|
|
84
|
-
[discord_js_1.Locale.Polish]: 'Ta komenda może być używana tylko na kanałach NSFW.',
|
|
85
|
-
[discord_js_1.Locale.Romanian]: 'Această comandă poate fi utilizată numai în canalele NSFW.',
|
|
86
|
-
[discord_js_1.Locale.Swedish]: 'Det här kommandot kan endast användas i NSFW-kanaler.',
|
|
87
|
-
[discord_js_1.Locale.Turkish]: 'Bu komut yalnızca NSFW kanallarında kullanılabilir.',
|
|
88
|
-
[discord_js_1.Locale.Ukrainian]: 'Цю команду можна використовувати лише в каналах NSFW.',
|
|
89
|
-
[discord_js_1.Locale.Hindi]: 'यह कमांड केवल NSFW चैनलों में ही उपयोग की जा सकती है।',
|
|
90
|
-
[discord_js_1.Locale.Indonesian]: 'Perintah ini hanya dapat digunakan di saluran NSFW.',
|
|
91
|
-
[discord_js_1.Locale.Greek]: 'Αυτή η εντολή μπορεί να χρησιμοποιηθεί μόνο σε κανάλια NSFW.',
|
|
92
|
-
[discord_js_1.Locale.Croatian]: 'Ova se naredba može koristiti samo u NSFW kanalima.',
|
|
93
|
-
[discord_js_1.Locale.Lithuanian]: 'Ši komanda gali būti naudojama tik NSFW kanaluose.',
|
|
94
|
-
[discord_js_1.Locale.Thai]: 'คำสั่งนี้สามารถใช้ได้เฉพาะในช่องทาง NSFW เท่านั้น.',
|
|
95
|
-
[discord_js_1.Locale.Vietnamese]: 'Lệnh này chỉ có thể được sử dụng trong các kênh NSFW.'
|
|
96
|
-
};
|
|
97
|
-
exports.LOCALE_NSFW = LOCALE_NSFW;
|
|
98
|
-
/**
|
|
99
|
-
* @description Localization phrases for delay commands.
|
|
100
|
-
* @example
|
|
101
|
-
* const example = LOCALE_DELAY[Locale.EnglishUS];
|
|
102
|
-
* const secondsPluralRegEx = new RegExp('{plural\\|([^}]+)}', 'g');
|
|
103
|
-
* const seconds = 5;
|
|
104
|
-
* const formattedPhrase = example
|
|
105
|
-
* .replace('{seconds}', seconds.toString())
|
|
106
|
-
* .replace(secondsPluralRegEx, seconds === 1 ? '' : '$1');
|
|
107
|
-
*
|
|
108
|
-
* console.log(formattedPhrase); // 'You must wait 5 seconds before using this command again.'
|
|
109
|
-
*/
|
|
110
|
-
const LOCALE_DELAY = {
|
|
111
|
-
[discord_js_1.Locale.SpanishLATAM]: 'Debes esperar {seconds} segundo{plural|s} antes de utilizar este comando denuevo.',
|
|
112
|
-
[discord_js_1.Locale.EnglishUS]: 'You must wait {seconds} second{plural|s} before using this command again.',
|
|
113
|
-
[discord_js_1.Locale.EnglishGB]: 'I do declare, you must wait {seconds} second{plural|s} before using this command again.',
|
|
114
|
-
[discord_js_1.Locale.SpanishES]: '¡Ostias, chaval! Debes esperar {seconds} segundo{plural|s} antes de utilizar este comando denuevo.',
|
|
115
|
-
[discord_js_1.Locale.PortugueseBR]: 'Você deve esperar {seconds} segundo{plural|s} antes de usar este comando novamente.',
|
|
116
|
-
[discord_js_1.Locale.French]: 'Vous devez attendre {seconds} seconde{plural|s} avant d\'utiliser cette commande à nouveau.',
|
|
117
|
-
[discord_js_1.Locale.German]: 'Sie müssen {seconds} Sekunde{plural|n} warten, bevor Sie diesen Befehl erneut verwenden können.',
|
|
118
|
-
[discord_js_1.Locale.Italian]: 'Devi aspettare {seconds} secondo{plural|i} prima di utilizzare di nuovo questo comando.',
|
|
119
|
-
[discord_js_1.Locale.Russian]: 'Вы должны подождать {seconds} секунду{plural|ы} перед повторным использованием этой команды.',
|
|
120
|
-
[discord_js_1.Locale.ChineseCN]: '您必须等待 {seconds} 秒钟{plural|s}才能再次使用此命令。',
|
|
121
|
-
[discord_js_1.Locale.ChineseTW]: '您必須等待 {seconds} 秒鐘{plural|s}才能再次使用此命令。',
|
|
122
|
-
[discord_js_1.Locale.Japanese]: 'このコマンドを再度使用するには、{seconds} 秒待つ必要があります。',
|
|
123
|
-
[discord_js_1.Locale.Korean]: '이 명령어를 다시 사용하려면 {seconds} 초 기다려야 합니다.',
|
|
124
|
-
[discord_js_1.Locale.Bulgarian]: 'Трябва да изчакате {seconds} секунда{plural|и}, преди да използвате тази команда отново.',
|
|
125
|
-
[discord_js_1.Locale.Czech]: 'Musíte počkat {seconds} sekundu{plural|y}, než znovu použijete tento příkaz.',
|
|
126
|
-
[discord_js_1.Locale.Danish]: 'Du skal vente {seconds} sekund{plural|er} før du kan bruge denne kommando igen.',
|
|
127
|
-
[discord_js_1.Locale.Dutch]: 'Je moet {seconds} seconde{plural|n} wachten voordat je dit commando opnieuw kunt gebruiken.',
|
|
128
|
-
[discord_js_1.Locale.Finnish]: 'Sinun on odotettava {seconds} sekuntia ennen kuin voit käyttää tätä komentoa uudelleen.',
|
|
129
|
-
[discord_js_1.Locale.Hungarian]: 'Várnod kell {seconds} másodpercet, mielőtt újra használhatod ezt a parancsot.',
|
|
130
|
-
[discord_js_1.Locale.Norwegian]: 'Du må vente {seconds} sekund{plural|er} før du kan bruke denne kommandoen igjen.',
|
|
131
|
-
[discord_js_1.Locale.Polish]: 'Musisz poczekać {seconds} sekund{plural|y}, zanim ponownie użyjesz tego polecenia.',
|
|
132
|
-
[discord_js_1.Locale.Romanian]: 'Trebuie să aștepți {seconds} secundă{plural|e} înainte de a folosi din nou acest comandă.',
|
|
133
|
-
[discord_js_1.Locale.Swedish]: 'Du måste vänta {seconds} sekund{plural|er} innan du kan använda det här kommandot igen.',
|
|
134
|
-
[discord_js_1.Locale.Turkish]: 'Bu komutu tekrar kullanmadan önce {seconds} saniye beklemelisiniz.',
|
|
135
|
-
[discord_js_1.Locale.Ukrainian]: 'Вам потрібно почекати {seconds} секунду{plural|и}, перш ніж знову використовувати цю команду.',
|
|
136
|
-
[discord_js_1.Locale.Hindi]: 'आपको इस कमांड का उपयोग करने से पहले {seconds} सेकंड{plural|s} इंतजार करना होगा।',
|
|
137
|
-
[discord_js_1.Locale.Indonesian]: 'Anda harus menunggu {seconds} detik{plural|s} sebelum menggunakan perintah ini lagi.',
|
|
138
|
-
[discord_js_1.Locale.Greek]: 'Πρέπει να περιμένετε {seconds} δευτερόλεπτο{plural|α} πριν χρησιμοποιήσετε ξανά αυτήν την εντολή.',
|
|
139
|
-
[discord_js_1.Locale.Croatian]: 'Morate pričekati {seconds} sekundu{plural|e} prije nego što ponovno upotrijebite ovu naredbu.',
|
|
140
|
-
[discord_js_1.Locale.Lithuanian]: 'Prieš vėl naudodamiesi šiuo komandu, turite palaukti {seconds} sekundę{plural|es}.',
|
|
141
|
-
[discord_js_1.Locale.Thai]: 'คุณต้องรอ {seconds} วินาที{plural|s} ก่อนที่จะใช้คำสั่งนี้อีกครั้ง',
|
|
142
|
-
[discord_js_1.Locale.Vietnamese]: 'Bạn phải đợi {seconds} giây{plural|s} trước khi sử dụng lại lệnh này.'
|
|
143
|
-
};
|
|
144
|
-
exports.LOCALE_DELAY = LOCALE_DELAY;
|
|
145
|
-
const LOCALE_ERROR = {
|
|
146
|
-
[discord_js_1.Locale.SpanishLATAM]: 'Ocurrió un error al procesar tu solicitud.',
|
|
147
|
-
[discord_js_1.Locale.EnglishUS]: 'An error occurred while processing your request.',
|
|
148
|
-
[discord_js_1.Locale.EnglishGB]: 'I do declare, an error occurred while processing your request.',
|
|
149
|
-
[discord_js_1.Locale.SpanishES]: 'Pero que me estás contando, willy, ocurrió un error al procesar tu solicitud.',
|
|
150
|
-
[discord_js_1.Locale.PortugueseBR]: 'Ocorreu um erro ao processar sua solicitação.',
|
|
151
|
-
[discord_js_1.Locale.French]: 'Une erreur est survenue lors du traitement de votre demande.',
|
|
152
|
-
[discord_js_1.Locale.German]: 'Bei der Verarbeitung Ihrer Anfrage ist ein Fehler aufgetreten.',
|
|
153
|
-
[discord_js_1.Locale.Italian]: 'Si è verificato un errore durante l\'elaborazione della tua richiesta.',
|
|
154
|
-
[discord_js_1.Locale.Russian]: 'Произошла ошибка при обработке вашего запроса.',
|
|
155
|
-
[discord_js_1.Locale.ChineseCN]: '处理您的请求时发生错误。',
|
|
156
|
-
[discord_js_1.Locale.ChineseTW]: '處理您的請求時發生錯誤。',
|
|
157
|
-
[discord_js_1.Locale.Japanese]: 'リクエストの処理中にエラーが発生しました。',
|
|
158
|
-
[discord_js_1.Locale.Korean]: '요청을 처리하는 동안 오류가 발생했습니다.',
|
|
159
|
-
[discord_js_1.Locale.Bulgarian]: 'При обработката на заявката ви възникна грешка.',
|
|
160
|
-
[discord_js_1.Locale.Czech]: 'Při zpracování vaší žádosti došlo k chybě.',
|
|
161
|
-
[discord_js_1.Locale.Danish]: 'Der opstod en fejl under behandlingen af din anmodning.',
|
|
162
|
-
[discord_js_1.Locale.Dutch]: 'Er is een fout opgetreden bij het verwerken van uw verzoek.',
|
|
163
|
-
[discord_js_1.Locale.Finnish]: 'Pyyntösi käsittelyssä tapahtui virhe.',
|
|
164
|
-
[discord_js_1.Locale.Hungarian]: 'A kérésed feldolgozása során hiba lépett fel.',
|
|
165
|
-
[discord_js_1.Locale.Norwegian]: 'Det oppstod en feil under behandling av forespørselen din.',
|
|
166
|
-
[discord_js_1.Locale.Polish]: 'Wystąpił błąd podczas przetwarzania twojej prośby.',
|
|
167
|
-
[discord_js_1.Locale.Romanian]: 'A apărut o eroare în timpul procesării cererii tale.',
|
|
168
|
-
[discord_js_1.Locale.Swedish]: 'Ett fel inträffade vid behandling av din begäran.',
|
|
169
|
-
[discord_js_1.Locale.Turkish]: 'Talebiniz işlenirken bir hata oluştu.',
|
|
170
|
-
[discord_js_1.Locale.Ukrainian]: 'Під час обробки вашого запиту сталася помилка.',
|
|
171
|
-
[discord_js_1.Locale.Hindi]: 'आपके अनुरोध को संसाधित करते समय एक त्रुटि हुई।',
|
|
172
|
-
[discord_js_1.Locale.Indonesian]: 'Terjadi kesalahan saat memproses permintaan Anda.',
|
|
173
|
-
[discord_js_1.Locale.Greek]: 'Συνέβη σφάλμα κατά την επεξεργασία του αιτήματός σας.',
|
|
174
|
-
[discord_js_1.Locale.Croatian]: 'Došlo je do pogreške prilikom obrade vašeg zahtjeva.',
|
|
175
|
-
[discord_js_1.Locale.Lithuanian]: 'Apdorojant jūsų užklausą įvyko klaida.',
|
|
176
|
-
[discord_js_1.Locale.Thai]: 'เกิดข้อผิดพลาดระหว่างการประมวลผลคำขอของคุณ',
|
|
177
|
-
[discord_js_1.Locale.Vietnamese]: 'Đã xảy ra lỗi trong quá trình xử lý yêu cầu của bạn.'
|
|
178
|
-
};
|
|
179
|
-
exports.LOCALE_ERROR = LOCALE_ERROR;
|
|
16
|
+
const locales_js_1 = require("./locales.js");
|
|
17
|
+
const locales_js_2 = require("./locales.js");
|
|
18
|
+
const modularmodal_js_1 = __importDefault(require("./modularmodal.js"));
|
|
180
19
|
/**
|
|
181
20
|
* Variables
|
|
182
21
|
*/
|
|
@@ -188,6 +27,7 @@ const ALLOWED_OPTION_TYPE = [
|
|
|
188
27
|
discord_js_1.ApplicationCommandOptionType.User,
|
|
189
28
|
discord_js_1.ApplicationCommandOptionType.Channel,
|
|
190
29
|
];
|
|
30
|
+
const COOLDOWNS_MAP = new Map();
|
|
191
31
|
/**
|
|
192
32
|
* @class ModularButton
|
|
193
33
|
* @description Represents a modular button that can be registered with Discord.js.
|
|
@@ -219,76 +59,32 @@ class ModularButton {
|
|
|
219
59
|
}
|
|
220
60
|
exports.ModularButton = ModularButton;
|
|
221
61
|
/**
|
|
222
|
-
* @class ModularModal
|
|
223
|
-
* @description Represents a modular modal that can be registered with Discord.js.
|
|
224
|
-
* It allows for dynamic modal creation and execution.
|
|
225
|
-
*/
|
|
226
|
-
class ModularModal {
|
|
227
|
-
/**
|
|
228
|
-
* Creates a new modal for the command.
|
|
229
|
-
* @param {string} modalId The ID for the modal.
|
|
230
|
-
* @param {ModularCommand} command The command that this modal belongs to.
|
|
231
|
-
*/
|
|
232
|
-
constructor(modalId, command) {
|
|
233
|
-
this.execute = async () => { };
|
|
234
|
-
this.modalObject = new discord_js_1.ModalBuilder();
|
|
235
|
-
this.modalObject.setCustomId(modalId);
|
|
236
|
-
this.modalId = modalId;
|
|
237
|
-
this.modalInputs = new Map();
|
|
238
|
-
this.command = command;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Sets the execute function for the modal.
|
|
242
|
-
* @param {ModalExecuteFunction} executeFunction The function to execute.
|
|
243
|
-
* @returns {ModularModal} The modal instance for chaining.
|
|
244
|
-
*/
|
|
245
|
-
setExecute(executeFunction) {
|
|
246
|
-
this.execute = executeFunction;
|
|
247
|
-
return this;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Creates a new text input for the modal.
|
|
251
|
-
* @param {string} id The ID for the text input.
|
|
252
|
-
* @param {TextInputStyle} style The style of the text input.
|
|
253
|
-
* @returns {TextInputBuilder} The created text input instance.
|
|
254
|
-
*/
|
|
255
|
-
newTextInput(id, style) {
|
|
256
|
-
const textInput = new discord_js_1.TextInputBuilder();
|
|
257
|
-
textInput.setCustomId(id);
|
|
258
|
-
textInput.setStyle(style);
|
|
259
|
-
this.modalInputs.set(id, textInput);
|
|
260
|
-
this.modalObject.addComponents(new discord_js_1.ActionRowBuilder().addComponents(textInput));
|
|
261
|
-
return textInput;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Builds the modal object.
|
|
265
|
-
* @param {Record<string, any>} locale The localization object for the modal.
|
|
266
|
-
* @return {ModalBuilder} The built modal object.
|
|
267
|
-
*/
|
|
268
|
-
build(locale) {
|
|
269
|
-
const selfModal = this.modalObject;
|
|
270
|
-
const commandName = this.command.name;
|
|
271
|
-
selfModal.setTitle(locale[`${commandName}.${this.modalId}.title`]);
|
|
272
|
-
this.modalInputs.forEach((input, id) => {
|
|
273
|
-
input.setLabel(locale[`${commandName}.${id}.label`]);
|
|
274
|
-
input.setPlaceholder(locale[`${commandName}.${id}.placeholder`]);
|
|
275
|
-
});
|
|
276
|
-
return selfModal;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
exports.ModularModal = ModularModal;
|
|
280
|
-
/**
|
|
281
|
-
* @class ModularCommand
|
|
282
62
|
* @description Represents a modular command that can be registered with Discord.js.
|
|
283
63
|
* It allows for dynamic command creation and execution.
|
|
64
|
+
* @example
|
|
65
|
+
* const { ModularCommand, RegisterCommand } = require('js-discord-modularcommand');
|
|
66
|
+
*
|
|
67
|
+
* const PingCommand = new ModularCommand('ping');
|
|
68
|
+
* PingCommand.setDescription('Sends a ping message.');
|
|
69
|
+
* PingCommand.setExecute(async ({interaction}) => {
|
|
70
|
+
* await interaction.reply('Pong!');
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* PingCommand.setPermissionCheck(({ interaction }) => {
|
|
74
|
+
* return interaction.member.permissions.has(PermissionFlagsBits.Administrator);
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* module.exports = RegisterCommand([
|
|
78
|
+
* PingCommand
|
|
79
|
+
* ]);
|
|
284
80
|
*/
|
|
285
81
|
class ModularCommand {
|
|
286
|
-
constructor(
|
|
82
|
+
constructor(name) {
|
|
287
83
|
this.name = name;
|
|
288
|
-
this.description =
|
|
289
|
-
this.execute =
|
|
290
|
-
this.componentExecute =
|
|
291
|
-
this.modalExecute =
|
|
84
|
+
this.description = '';
|
|
85
|
+
this.execute = async () => { };
|
|
86
|
+
this.componentExecute = undefined;
|
|
87
|
+
this.modalExecute = undefined;
|
|
292
88
|
this.options = [];
|
|
293
89
|
this.optionsLocalizations = {};
|
|
294
90
|
this.customIdHandlers = {};
|
|
@@ -350,28 +146,6 @@ class ModularCommand {
|
|
|
350
146
|
this.componentExecute = executeFunction;
|
|
351
147
|
return this;
|
|
352
148
|
}
|
|
353
|
-
/**
|
|
354
|
-
* Creates a new modal for the command.
|
|
355
|
-
* @param {string} modalId The ID for the modal.
|
|
356
|
-
* @returns {ModularModal} The created modal instance.
|
|
357
|
-
*/
|
|
358
|
-
newModal(modalId) {
|
|
359
|
-
const modal = new ModularModal(modalId, this);
|
|
360
|
-
this.modals.set(modalId, modal);
|
|
361
|
-
return modal;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Creates a new button for the command.
|
|
365
|
-
* @param {string} customId The custom ID for the button.
|
|
366
|
-
* @param {ButtonStyle} style The style of the button.
|
|
367
|
-
* @return {ModularButton} The created button instance.
|
|
368
|
-
*/
|
|
369
|
-
newButton(customId, style) {
|
|
370
|
-
const button = new ModularButton(customId, style);
|
|
371
|
-
this.buttons.set(customId, button);
|
|
372
|
-
this.buttonsArray.push(button);
|
|
373
|
-
return button;
|
|
374
|
-
}
|
|
375
149
|
/**
|
|
376
150
|
* Set the minimun permissions required to execute the command.
|
|
377
151
|
* @param {PermissionCheckFunction} permissionCheckFunction The function to check permissions.
|
|
@@ -419,6 +193,28 @@ class ModularCommand {
|
|
|
419
193
|
this.customIdHandlers[customId] = handlerFunction;
|
|
420
194
|
return this;
|
|
421
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Creates a new modal for the command.
|
|
198
|
+
* @param {string} modalId The ID for the modal.
|
|
199
|
+
* @returns {ModularModal} The created modal instance.
|
|
200
|
+
*/
|
|
201
|
+
addModal(modalId) {
|
|
202
|
+
const modal = new modularmodal_js_1.default(modalId, this);
|
|
203
|
+
this.modals.set(modalId, modal);
|
|
204
|
+
return modal;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Creates a new button for the command.
|
|
208
|
+
* @param {string} customId The custom ID for the button.
|
|
209
|
+
* @param {ButtonStyle} style The style of the button.
|
|
210
|
+
* @return {ModularButton} The created button instance.
|
|
211
|
+
*/
|
|
212
|
+
addButton(customId, style) {
|
|
213
|
+
const button = new ModularButton(customId, style);
|
|
214
|
+
this.buttons.set(customId, button);
|
|
215
|
+
this.buttonsArray.push(button);
|
|
216
|
+
return button;
|
|
217
|
+
}
|
|
422
218
|
}
|
|
423
219
|
exports.ModularCommand = ModularCommand;
|
|
424
220
|
/**
|
|
@@ -432,6 +228,7 @@ const RegisterCommand = (commands) => {
|
|
|
432
228
|
.setName(command.name)
|
|
433
229
|
.setDescription(command.description)
|
|
434
230
|
.setDescriptionLocalizations(command.descriptionLocalizations || null);
|
|
231
|
+
COOLDOWNS_MAP.set(command.name, new Map());
|
|
435
232
|
const options = {};
|
|
436
233
|
command.options.forEach(opt => {
|
|
437
234
|
const description = typeof opt.description === 'string' ?
|
|
@@ -476,20 +273,35 @@ const RegisterCommand = (commands) => {
|
|
|
476
273
|
}
|
|
477
274
|
});
|
|
478
275
|
const executeBuilder = async (interaction) => {
|
|
479
|
-
|
|
276
|
+
// User has permissions
|
|
277
|
+
if (command.permissionCheck && !command.permissionCheck({ interaction })) {
|
|
480
278
|
await interaction.reply({
|
|
481
|
-
content: LOCALE_FORBIDDEN[interaction.locale]
|
|
279
|
+
content: locales_js_1.LOCALE_FORBIDDEN[interaction.locale],
|
|
482
280
|
flags: discord_js_1.MessageFlags.Ephemeral,
|
|
483
281
|
});
|
|
484
282
|
return;
|
|
485
283
|
}
|
|
284
|
+
// User is using a NSFW command in a non-NSFW channel
|
|
486
285
|
if (command.isNSFW && (!interaction.channel || !('nsfw' in interaction.channel) || !interaction.channel.nsfw)) {
|
|
487
286
|
await interaction.reply({
|
|
488
|
-
content: LOCALE_NSFW[interaction.locale]
|
|
287
|
+
content: locales_js_1.LOCALE_NSFW[interaction.locale],
|
|
489
288
|
flags: discord_js_1.MessageFlags.Ephemeral,
|
|
490
289
|
});
|
|
491
290
|
return;
|
|
492
291
|
}
|
|
292
|
+
// User is in a cooldown
|
|
293
|
+
const lastTime = COOLDOWNS_MAP.get(command.name)?.get(interaction.user.id);
|
|
294
|
+
if (lastTime) {
|
|
295
|
+
const cooldownDuration = (Date.now() / 1000) - lastTime;
|
|
296
|
+
if (cooldownDuration < command.cooldown) {
|
|
297
|
+
await interaction.reply({
|
|
298
|
+
content: (0, locales_js_2.FormatSecondsLocale)(locales_js_1.LOCALE_DELAY[interaction.locale], command.cooldown - cooldownDuration),
|
|
299
|
+
flags: discord_js_1.MessageFlags.Ephemeral,
|
|
300
|
+
});
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
COOLDOWNS_MAP.get(command.name)?.set(interaction.user.id, Date.now() / 1000);
|
|
304
|
+
}
|
|
493
305
|
const args = {};
|
|
494
306
|
for (const option of Object.keys(options)) {
|
|
495
307
|
switch (options[option]) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ModularModal
|
|
3
|
+
* @description A module for creating and managing modals in a easy way for me.
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Imports
|
|
8
|
+
*/
|
|
9
|
+
import { ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } from "discord.js";
|
|
10
|
+
import { ModularCommand } from "./modularcommand";
|
|
11
|
+
/**
|
|
12
|
+
* Types
|
|
13
|
+
*/
|
|
14
|
+
type ModalExecuteFunction = (params: {
|
|
15
|
+
interaction: ModalSubmitInteraction;
|
|
16
|
+
args: Record<string, string>;
|
|
17
|
+
command: ModularCommand;
|
|
18
|
+
locale: Record<string, any>;
|
|
19
|
+
}) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* @class ModularModal
|
|
22
|
+
* @description Represents a modular modal that can be registered with Discord.js.
|
|
23
|
+
* It allows for dynamic modal creation and execution.
|
|
24
|
+
*/
|
|
25
|
+
declare class ModularModal {
|
|
26
|
+
modalObject: ModalBuilder;
|
|
27
|
+
customId: string;
|
|
28
|
+
modalId: string;
|
|
29
|
+
modalInputs: Map<string, TextInputBuilder>;
|
|
30
|
+
command: ModularCommand;
|
|
31
|
+
execute: ModalExecuteFunction;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new modal for the command.
|
|
34
|
+
* @param {string} modalId The ID for the modal.
|
|
35
|
+
* @param {ModularCommand} command The command that this modal belongs to.
|
|
36
|
+
*/
|
|
37
|
+
constructor(modalId: string, command: ModularCommand);
|
|
38
|
+
/**
|
|
39
|
+
* Sets the execute function for the modal.
|
|
40
|
+
* @param {ModalExecuteFunction} executeFunction The function to execute.
|
|
41
|
+
* @returns {ModularModal} The modal instance for chaining.
|
|
42
|
+
*/
|
|
43
|
+
setExecute(executeFunction: ModalExecuteFunction): this;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the modal custom ID.
|
|
46
|
+
* @returns {string} The modal custom ID.
|
|
47
|
+
*/
|
|
48
|
+
getCustomId(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new text input for the modal.
|
|
51
|
+
* @param {string} id The ID for the text input.
|
|
52
|
+
* @param {TextInputStyle} style The style of the text input.
|
|
53
|
+
* @returns {TextInputBuilder} The created text input instance.
|
|
54
|
+
*/
|
|
55
|
+
newTextInput(id: string, style: TextInputStyle): TextInputBuilder;
|
|
56
|
+
/**
|
|
57
|
+
* Builds the modal object.
|
|
58
|
+
* @param {Record<string, any>} locale The localization object for the modal.
|
|
59
|
+
* @return {ModalBuilder} The built modal object.
|
|
60
|
+
*/
|
|
61
|
+
build(locale: Record<string, any>): ModalBuilder;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Exports
|
|
65
|
+
*/
|
|
66
|
+
export default ModularModal;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module ModularModal
|
|
4
|
+
* @description A module for creating and managing modals in a easy way for me.
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
/**
|
|
9
|
+
* Imports
|
|
10
|
+
*/
|
|
11
|
+
const discord_js_1 = require("discord.js");
|
|
12
|
+
/**
|
|
13
|
+
* @class ModularModal
|
|
14
|
+
* @description Represents a modular modal that can be registered with Discord.js.
|
|
15
|
+
* It allows for dynamic modal creation and execution.
|
|
16
|
+
*/
|
|
17
|
+
class ModularModal {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new modal for the command.
|
|
20
|
+
* @param {string} modalId The ID for the modal.
|
|
21
|
+
* @param {ModularCommand} command The command that this modal belongs to.
|
|
22
|
+
*/
|
|
23
|
+
constructor(modalId, command) {
|
|
24
|
+
this.execute = async () => { };
|
|
25
|
+
const customModalId = `${command.name}_${modalId}`;
|
|
26
|
+
this.modalObject = new discord_js_1.ModalBuilder();
|
|
27
|
+
this.modalObject.setCustomId(customModalId);
|
|
28
|
+
this.customId = customModalId;
|
|
29
|
+
this.modalId = modalId;
|
|
30
|
+
this.modalInputs = new Map();
|
|
31
|
+
this.command = command;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets the execute function for the modal.
|
|
35
|
+
* @param {ModalExecuteFunction} executeFunction The function to execute.
|
|
36
|
+
* @returns {ModularModal} The modal instance for chaining.
|
|
37
|
+
*/
|
|
38
|
+
setExecute(executeFunction) {
|
|
39
|
+
this.execute = executeFunction;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the modal custom ID.
|
|
44
|
+
* @returns {string} The modal custom ID.
|
|
45
|
+
*/
|
|
46
|
+
getCustomId() {
|
|
47
|
+
return this.customId;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new text input for the modal.
|
|
51
|
+
* @param {string} id The ID for the text input.
|
|
52
|
+
* @param {TextInputStyle} style The style of the text input.
|
|
53
|
+
* @returns {TextInputBuilder} The created text input instance.
|
|
54
|
+
*/
|
|
55
|
+
newTextInput(id, style) {
|
|
56
|
+
const textInput = new discord_js_1.TextInputBuilder();
|
|
57
|
+
textInput.setCustomId(id);
|
|
58
|
+
textInput.setStyle(style);
|
|
59
|
+
this.modalInputs.set(id, textInput);
|
|
60
|
+
this.modalObject.addComponents(new discord_js_1.ActionRowBuilder().addComponents(textInput));
|
|
61
|
+
return textInput;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Builds the modal object.
|
|
65
|
+
* @param {Record<string, any>} locale The localization object for the modal.
|
|
66
|
+
* @return {ModalBuilder} The built modal object.
|
|
67
|
+
*/
|
|
68
|
+
build(locale) {
|
|
69
|
+
const selfModal = this.modalObject;
|
|
70
|
+
const commandName = this.command.name;
|
|
71
|
+
selfModal.setTitle(locale[`${commandName}.${this.modalId}.title`]);
|
|
72
|
+
this.modalInputs.forEach((input, id) => {
|
|
73
|
+
input.setLabel(locale[`${commandName}.${id}.label`]);
|
|
74
|
+
input.setPlaceholder(locale[`${commandName}.${id}.placeholder`]);
|
|
75
|
+
});
|
|
76
|
+
return selfModal;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Exports
|
|
81
|
+
*/
|
|
82
|
+
exports.default = ModularModal;
|
package/package.json
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-discord-modularcommand",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"discord",
|
|
7
|
+
"js",
|
|
8
|
+
"node"
|
|
9
|
+
],
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"author": "SummerTYT",
|
|
8
12
|
"type": "commonjs",
|
|
9
13
|
"types": "./dist/index.d.ts",
|
|
10
|
-
"files": [
|
|
11
|
-
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/**/*"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.js",
|
|
12
18
|
"scripts": {
|
|
13
19
|
"build": "tsc",
|
|
14
20
|
"prepublish": "npm run build"
|
|
15
21
|
},
|
|
16
22
|
"dependencies": {
|
|
17
|
-
"discord.js": "^14.21.0"
|
|
18
|
-
"typescript": "^5.9.2"
|
|
23
|
+
"discord.js": "^14.21.0"
|
|
19
24
|
},
|
|
20
25
|
"devDependencies": {
|
|
21
|
-
"@types/node": "^24.2.1"
|
|
26
|
+
"@types/node": "^24.2.1",
|
|
27
|
+
"typescript": "^5.9.2"
|
|
22
28
|
}
|
|
23
29
|
}
|
package/index.js
DELETED
|
File without changes
|