@spatulox/simplediscordbot 1.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/.env.example +2 -0
- package/LICENSE.md +21 -0
- package/README.md +1 -0
- package/dist/bot/Bot.js +107 -0
- package/dist/bot/BotEnv.js +29 -0
- package/dist/bot/BotLog.js +90 -0
- package/dist/bot/BotMessage.js +79 -0
- package/dist/cli/BaseCLI.js +165 -0
- package/dist/cli/GenerationCLI/ContextMenuGeneratorCLI.js +109 -0
- package/dist/cli/GenerationCLI/GenerationCLI.js +25 -0
- package/dist/cli/GenerationCLI/InteractionGeneratorCLI.js +20 -0
- package/dist/cli/GenerationCLI/ModalGeneratorCLI.js +166 -0
- package/dist/cli/GenerationCLI/SlashCommandsGeneratorCLI.js +221 -0
- package/dist/cli/GenerationCLI.js +36 -0
- package/dist/cli/GuildListManager.js +61 -0
- package/dist/cli/InputCLI.js +25 -0
- package/dist/cli/InteractionCLI/InteractionCLI.js +30 -0
- package/dist/cli/InteractionCLI/InteractionCLIManager.js +80 -0
- package/dist/cli/InteractionCLI.js +109 -0
- package/dist/cli/MainCLI.js +32 -0
- package/dist/cli/type/ContextMenuConfig.js +2 -0
- package/dist/cli/type/InteractionType.js +14 -0
- package/dist/cli/type/SlashCommandConfig.js +2 -0
- package/dist/index.js +31 -0
- package/dist/manager/FileManager.js +136 -0
- package/dist/manager/direct/UserManager.js +76 -0
- package/dist/manager/discord/ChannelManager.js +48 -0
- package/dist/manager/discord/DiscordRegex.js +114 -0
- package/dist/manager/discord/GuildManager.js +67 -0
- package/dist/manager/discord/InviteManager.js +89 -0
- package/dist/manager/discord/RoleManager.js +83 -0
- package/dist/manager/discord/UserManager.js +69 -0
- package/dist/manager/guild/ChannelManager/ForumChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/GuildChannelList.js +20 -0
- package/dist/manager/guild/ChannelManager/GuildChannelManager.js +91 -0
- package/dist/manager/guild/ChannelManager/GuildMessageManager.js +85 -0
- package/dist/manager/guild/ChannelManager/GuildTextChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/GuildVoiceChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/NewsChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/StageChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/ThreadChannelManager.js +34 -0
- package/dist/manager/guild/GuildManager.js +134 -0
- package/dist/manager/guild/GuildUserManager.js +212 -0
- package/dist/manager/guild/InviteManager.js +68 -0
- package/dist/manager/guild/InviteManager_old.js +89 -0
- package/dist/manager/guild/RoleManager.js +83 -0
- package/dist/manager/hadlers_old/builder/ModalManager.js +111 -0
- package/dist/manager/hadlers_old/builder/delete.js +49 -0
- package/dist/manager/hadlers_old/builder/deploy.js +225 -0
- package/dist/manager/hadlers_old/builder/interactions/CommandManager.js +14 -0
- package/dist/manager/hadlers_old/builder/interactions/ContextMenuManager.js +14 -0
- package/dist/manager/hadlers_old/builder/interactions/InteractionBase.js +341 -0
- package/dist/manager/hadlers_old/builder/interactions/InteractionManager.js +65 -0
- package/dist/manager/hadlers_old/builder/list.js +166 -0
- package/dist/manager/messages/EmbedManager.js +131 -0
- package/dist/manager/messages/ReactionManager.js +99 -0
- package/dist/manager/messages/WebhookManager.js +105 -0
- package/dist/type/FolderName.js +9 -0
- package/dist/utils/DiscordRegex.js +116 -0
- package/dist/utils/Log.js +28 -0
- package/dist/utils/SimpleMutex.js +39 -0
- package/dist/utils/network/InternetChecker.js +54 -0
- package/dist/utils/times/UnitTime.js +85 -0
- package/package.json +40 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModalGeneratorCLI = exports.ModalFieldStyle = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
const BaseCLI_1 = require("../BaseCLI");
|
|
6
|
+
const FolderName_1 = require("../../type/FolderName");
|
|
7
|
+
var ModalFieldStyle;
|
|
8
|
+
(function (ModalFieldStyle) {
|
|
9
|
+
// Official TextInputStyle
|
|
10
|
+
ModalFieldStyle[ModalFieldStyle["Short"] = 1] = "Short";
|
|
11
|
+
ModalFieldStyle[ModalFieldStyle["Paragraph"] = 2] = "Paragraph";
|
|
12
|
+
// Custom Styles
|
|
13
|
+
ModalFieldStyle["Number"] = "Number";
|
|
14
|
+
ModalFieldStyle["Phone"] = "Phone";
|
|
15
|
+
ModalFieldStyle["Date"] = "Date";
|
|
16
|
+
})(ModalFieldStyle || (exports.ModalFieldStyle = ModalFieldStyle = {}));
|
|
17
|
+
class ModalGeneratorCLI extends BaseCLI_1.BaseCLI {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.menuSelection = [
|
|
21
|
+
{ label: "Generate Modal", action: () => this },
|
|
22
|
+
{ label: "Back", action: () => this.goBack() },
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
getTitle() {
|
|
26
|
+
return "📝 Modal JSON Generator";
|
|
27
|
+
}
|
|
28
|
+
async execute() {
|
|
29
|
+
const modal = {
|
|
30
|
+
title: '',
|
|
31
|
+
customId: '',
|
|
32
|
+
label: '',
|
|
33
|
+
fields: []
|
|
34
|
+
};
|
|
35
|
+
// 1. Nom du Modal (Title)
|
|
36
|
+
console.clear();
|
|
37
|
+
console.log("🎛️ 1/6 - Modal Title");
|
|
38
|
+
modal.title = await this.requireInput("Enter modal title (max 45 chars): ", val => val.length <= 45);
|
|
39
|
+
// 2. Custom ID
|
|
40
|
+
console.clear();
|
|
41
|
+
console.log("🔑 2/6 - Custom ID");
|
|
42
|
+
modal.customId = await this.requireInput("Enter custom ID (lowercase, no spaces): ", val => /^[a-z0-9_-]+$/.test(val) && val.length <= 100);
|
|
43
|
+
// 3. Label principal (optionnel)
|
|
44
|
+
console.clear();
|
|
45
|
+
console.log("📝 3/6 - Main Label");
|
|
46
|
+
modal.label = (await this.prompt("Enter main label (optional, press Enter to skip): "))?.trim() || '';
|
|
47
|
+
// 4. Nombre de champs
|
|
48
|
+
console.clear();
|
|
49
|
+
console.log("📊 4/6 - Fields");
|
|
50
|
+
console.log("Max 5 fields per modal");
|
|
51
|
+
const fieldCount = parseInt(await this.requireInput("How many fields? (1-5): ", val => {
|
|
52
|
+
const num = parseInt(val);
|
|
53
|
+
return num >= 1 && num <= 5;
|
|
54
|
+
}));
|
|
55
|
+
// 5. Générer chaque champ
|
|
56
|
+
for (let i = 0; i < fieldCount; i++) {
|
|
57
|
+
console.clear();
|
|
58
|
+
console.log(`📝 5/6 - Field ${i + 1}/${fieldCount}`);
|
|
59
|
+
const fieldLabel = await this.requireInput("Field label (max 45 chars): ", val => val.length <= 45);
|
|
60
|
+
const fieldId = await this.requireInput("Field custom ID (lowercase): ", val => /^[a-z0-9_-]+$/.test(val));
|
|
61
|
+
const fieldPlaceholder = (await this.prompt("Placeholder (optional): "))?.trim() || undefined;
|
|
62
|
+
const fieldRequired = await this.yesNoInput("Required field? (y/n): ");
|
|
63
|
+
console.clear();
|
|
64
|
+
console.log("🎨 Field Styles:");
|
|
65
|
+
console.log("1. Short (TextInputStyle.Short)");
|
|
66
|
+
console.log("2. Paragraph (TextInputStyle.Paragraph)");
|
|
67
|
+
console.log("3. Number");
|
|
68
|
+
console.log("4. Phone");
|
|
69
|
+
console.log("5. Date");
|
|
70
|
+
const styleChoice = await this.requireInput("Choose style (1-5): ", val => ["1", "2", "3", "4", "5"].includes(val));
|
|
71
|
+
let style;
|
|
72
|
+
switch (styleChoice) {
|
|
73
|
+
case '1':
|
|
74
|
+
style = ModalFieldStyle.Short;
|
|
75
|
+
break;
|
|
76
|
+
case '2':
|
|
77
|
+
style = ModalFieldStyle.Paragraph;
|
|
78
|
+
break;
|
|
79
|
+
case '3':
|
|
80
|
+
style = ModalFieldStyle.Number;
|
|
81
|
+
break;
|
|
82
|
+
case '4':
|
|
83
|
+
style = ModalFieldStyle.Phone;
|
|
84
|
+
break;
|
|
85
|
+
case '5':
|
|
86
|
+
style = ModalFieldStyle.Date;
|
|
87
|
+
break;
|
|
88
|
+
default: style = ModalFieldStyle.Short;
|
|
89
|
+
}
|
|
90
|
+
// Min/Max length (optional)
|
|
91
|
+
const minLengthInput = await this.prompt("Min length (optional, press Enter): ");
|
|
92
|
+
const maxLengthInput = await this.prompt("Max length (optional, press Enter): ");
|
|
93
|
+
modal.fields.push({
|
|
94
|
+
title: fieldLabel,
|
|
95
|
+
customId: fieldId,
|
|
96
|
+
placeholder: fieldPlaceholder,
|
|
97
|
+
required: fieldRequired,
|
|
98
|
+
style,
|
|
99
|
+
...(minLengthInput && { minLength: parseInt(minLengthInput) }),
|
|
100
|
+
...(maxLengthInput && { maxLength: parseInt(maxLengthInput) })
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
console.clear();
|
|
104
|
+
console.log("💾 6/6 - Save");
|
|
105
|
+
const filename = await this.requireInput("Filename (ex: server-config): ") + ".json";
|
|
106
|
+
await this.saveFile(FolderName_1.FolderName.MODAL, filename, modal);
|
|
107
|
+
return this.showMainMenu();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create modal from declarative config - SIMPLE API !
|
|
111
|
+
*/
|
|
112
|
+
static create(options) {
|
|
113
|
+
const modal = new discord_js_1.ModalBuilder()
|
|
114
|
+
.setCustomId(options.customId)
|
|
115
|
+
.setTitle(options.title.slice(0, 45));
|
|
116
|
+
const actionRows = [];
|
|
117
|
+
for (const field of options.fields) {
|
|
118
|
+
const input = this.buildInput(field);
|
|
119
|
+
const row = new discord_js_1.ActionRowBuilder()
|
|
120
|
+
.addComponents(input);
|
|
121
|
+
actionRows.push(row);
|
|
122
|
+
}
|
|
123
|
+
return modal.addComponents(...actionRows);
|
|
124
|
+
}
|
|
125
|
+
static buildInput(field) {
|
|
126
|
+
const input = new discord_js_1.TextInputBuilder()
|
|
127
|
+
.setCustomId(field.customId)
|
|
128
|
+
.setLabel(field.title.slice(0, 45))
|
|
129
|
+
.setPlaceholder(field.placeholder ?? '')
|
|
130
|
+
.setRequired(field.required ?? false)
|
|
131
|
+
.setMinLength(field.minLength ?? 0)
|
|
132
|
+
.setMaxLength(field.maxLength ?? 400);
|
|
133
|
+
// Mapper les styles custom
|
|
134
|
+
switch (field.style) {
|
|
135
|
+
case 'Number':
|
|
136
|
+
input.setStyle(discord_js_1.TextInputStyle.Short).setPlaceholder('Enter a number');
|
|
137
|
+
break;
|
|
138
|
+
case 'Phone':
|
|
139
|
+
input.setStyle(discord_js_1.TextInputStyle.Short).setPlaceholder('Enter a phone number : +33 6 12 34 56 78');
|
|
140
|
+
break;
|
|
141
|
+
case 'Date':
|
|
142
|
+
input.setStyle(discord_js_1.TextInputStyle.Short).setPlaceholder('Enter a date : yyyy-mm-dd');
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
input.setStyle(field.style);
|
|
146
|
+
}
|
|
147
|
+
return input;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Quick helpers
|
|
151
|
+
*/
|
|
152
|
+
static simple(option) {
|
|
153
|
+
return this.create({
|
|
154
|
+
title: option.title,
|
|
155
|
+
customId: option.customId,
|
|
156
|
+
label: option.label,
|
|
157
|
+
fields: [{
|
|
158
|
+
title: option.label,
|
|
159
|
+
customId: 'input',
|
|
160
|
+
placeholder: option.placeholder,
|
|
161
|
+
style: ModalFieldStyle.Short
|
|
162
|
+
}]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.ModalGeneratorCLI = ModalGeneratorCLI;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SlashCommandGeneratorCLI = void 0;
|
|
4
|
+
const BaseCLI_1 = require("../BaseCLI");
|
|
5
|
+
const FolderName_1 = require("../../type/FolderName");
|
|
6
|
+
const discord_js_1 = require("discord.js");
|
|
7
|
+
const DiscordRegex_1 = require("../../utils/DiscordRegex");
|
|
8
|
+
class SlashCommandGeneratorCLI extends BaseCLI_1.BaseCLI {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.menuSelection = [
|
|
12
|
+
{ label: "Generate Slash Command", action: () => this },
|
|
13
|
+
{ label: "Back", action: () => this.goBack() },
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
getTitle() {
|
|
17
|
+
return "📝 Slash Command JSON Generator";
|
|
18
|
+
}
|
|
19
|
+
async execute() {
|
|
20
|
+
const config = {
|
|
21
|
+
type: 1,
|
|
22
|
+
name: "",
|
|
23
|
+
description: "",
|
|
24
|
+
options: [],
|
|
25
|
+
dm_permission: false,
|
|
26
|
+
default_member_permissions: undefined,
|
|
27
|
+
default_member_permissions_string: undefined,
|
|
28
|
+
integration_types: [0, 1],
|
|
29
|
+
contexts: [0]
|
|
30
|
+
};
|
|
31
|
+
// 1. Command Name
|
|
32
|
+
console.clear();
|
|
33
|
+
console.log("📝 1/12 - Command Name");
|
|
34
|
+
config.name = await this.requireInput("Enter command name (lowercase, no spaces): ", val => /^[a-z_-]{1,32}$/.test(val));
|
|
35
|
+
// 2. Command Description
|
|
36
|
+
console.clear();
|
|
37
|
+
console.log("📄 2/12 - Command Description");
|
|
38
|
+
config.description = await this.requireInput("Enter command description (1-100 chars): ", val => val.length >= 1 && val.length <= 100);
|
|
39
|
+
// 3. Member Permissions
|
|
40
|
+
console.clear();
|
|
41
|
+
console.log("🔐 3/12 - Permissions");
|
|
42
|
+
console.log("📋 Valid permissions:\n", Object.keys(discord_js_1.PermissionFlagsBits).join(', '));
|
|
43
|
+
const permsInput = await this.requireInput("Default member permissions (comma separated, or 'none'): ", (val) => {
|
|
44
|
+
if (!val || val.toLowerCase() === "none" || val === '')
|
|
45
|
+
return true;
|
|
46
|
+
const permissions = val.split(",").map(p => p.trim());
|
|
47
|
+
const invalidPerms = permissions.filter(perm => !(perm in discord_js_1.PermissionFlagsBits));
|
|
48
|
+
if (invalidPerms.length > 0) {
|
|
49
|
+
console.log(`❌ Invalid: ${invalidPerms.join(', ')}`);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}, true);
|
|
54
|
+
if (permsInput && permsInput.toLowerCase() !== "none") {
|
|
55
|
+
config.default_member_permissions_string = permsInput.split(",").map(p => p.trim());
|
|
56
|
+
}
|
|
57
|
+
// 4. DM Permission
|
|
58
|
+
console.clear();
|
|
59
|
+
console.log("💬 4/12 - DM Permission");
|
|
60
|
+
config.dm_permission = (await this.yesNoInput("Allow in DMs? (y/n): "));
|
|
61
|
+
// 5. Integration Types
|
|
62
|
+
console.clear();
|
|
63
|
+
console.log("🔗 5/12 - Integration Types");
|
|
64
|
+
console.log("0 => GUILD_INSTALL, 1 => USER_INSTALL (comma separated, or 'all')");
|
|
65
|
+
const intInput = await this.requireInput("Integration types: ");
|
|
66
|
+
if (intInput.toLowerCase() === "all") {
|
|
67
|
+
config.integration_types = [0, 1];
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
config.integration_types = intInput.split(",").map(i => parseInt(i.trim())).filter(i => !isNaN(i));
|
|
71
|
+
}
|
|
72
|
+
// 6. Contexts
|
|
73
|
+
console.clear();
|
|
74
|
+
console.log("🌐 6/12 - Contexts");
|
|
75
|
+
console.log("0 => Server, 1 => Bot DMs, 2 => Group/Other DMs (comma separated, or 'server')");
|
|
76
|
+
const ctxInput = await this.requireInput("Contexts: ", undefined, true);
|
|
77
|
+
if (!ctxInput || ctxInput.trim() === "") {
|
|
78
|
+
config.contexts = [0, 1, 2];
|
|
79
|
+
}
|
|
80
|
+
else if (ctxInput.toLowerCase() === "all") {
|
|
81
|
+
config.contexts = [0, 1, 2];
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
config.contexts = ctxInput.split(",").map(i => parseInt(i.trim())).filter(i => !isNaN(i));
|
|
85
|
+
}
|
|
86
|
+
// 7. Add Subcommands/Groups?
|
|
87
|
+
console.clear();
|
|
88
|
+
console.log("📂 7/12 - Structure");
|
|
89
|
+
const addStructure = await this.yesNoInput("Add subcommands or groups? (y/n): ");
|
|
90
|
+
if (addStructure) {
|
|
91
|
+
await this.addCommandStructure(config);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Add basic options if no structure
|
|
95
|
+
await this.addSimpleOptions(config);
|
|
96
|
+
}
|
|
97
|
+
// 8. Guild IDs (optional)
|
|
98
|
+
console.clear();
|
|
99
|
+
console.log("🏠 8/12 - Guild IDs (optional)");
|
|
100
|
+
const guildInput = await this.requireInput("Guild IDs (comma separated, or 'none'): ", (val) => {
|
|
101
|
+
if (!val || val.toLowerCase() === "none")
|
|
102
|
+
return true;
|
|
103
|
+
const ids = val.split(",").map(id => id.trim());
|
|
104
|
+
const invalidIds = ids.filter(id => !DiscordRegex_1.DiscordRegex.GUILD_ID.test(id));
|
|
105
|
+
if (invalidIds.length > 0) {
|
|
106
|
+
console.log(`❌ Invalid Guild IDs: ${invalidIds.join(', ')}`);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
}, true);
|
|
111
|
+
if (guildInput && guildInput.toLowerCase() !== "none") {
|
|
112
|
+
config.guildID = guildInput.split(",").map(id => id.trim());
|
|
113
|
+
}
|
|
114
|
+
// 9. Filename
|
|
115
|
+
console.clear();
|
|
116
|
+
console.log("💾 9/12 - Filename");
|
|
117
|
+
const filename = (await this.requireInput("Filename (without .json): ")) + ".json";
|
|
118
|
+
await this.saveFile(FolderName_1.FolderName.SLASH_COMMANDS, filename, config);
|
|
119
|
+
}
|
|
120
|
+
async addCommandStructure(config) {
|
|
121
|
+
console.clear();
|
|
122
|
+
console.log("📁 Structure Type");
|
|
123
|
+
console.log("1 => Add Sub Command Group");
|
|
124
|
+
console.log("2 => Add Sub Command");
|
|
125
|
+
const structureType = parseInt(await this.requireInput("Type (1 or 2): ", val => ["1", "2"].includes(val)));
|
|
126
|
+
if (structureType === 1) {
|
|
127
|
+
// Sub Command Group
|
|
128
|
+
const groupName = await this.requireInput("Group name: ");
|
|
129
|
+
const groupDesc = await this.requireInput("Group description: ");
|
|
130
|
+
config.options = config.options || [];
|
|
131
|
+
config.options.push({
|
|
132
|
+
type: 2,
|
|
133
|
+
name: groupName,
|
|
134
|
+
description: groupDesc,
|
|
135
|
+
options: []
|
|
136
|
+
});
|
|
137
|
+
await this.addSubCommands(config.options[config.options.length - 1].options);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Direct Sub Command
|
|
141
|
+
await this.addSubCommands(config.options);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async addSubCommands(options) {
|
|
145
|
+
let continueAdding = true;
|
|
146
|
+
while (continueAdding) {
|
|
147
|
+
console.clear();
|
|
148
|
+
console.log("➕ Add Subcommand");
|
|
149
|
+
const name = await this.requireInput("Subcommand name: ");
|
|
150
|
+
const desc = await this.requireInput("Subcommand description: ");
|
|
151
|
+
const subCmd = { type: 1, name, description: desc, options: [] };
|
|
152
|
+
await this.addSubCommandOptions(subCmd.options);
|
|
153
|
+
options.push(subCmd);
|
|
154
|
+
continueAdding = await this.yesNoInput("Add another subcommand? (y/n): ");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async addSubCommandOptions(options) {
|
|
158
|
+
let continueAdding = await this.yesNoInput("Add options to this subcommand? (y/n): ");
|
|
159
|
+
while (continueAdding) {
|
|
160
|
+
console.clear();
|
|
161
|
+
console.log("Option Types:\n1=SUB_COMMAND,2=SUB_GROUP,3=STRING,4=INTEGER,5=BOOLEAN,6=USER,7=CHANNEL,8=ROLE,9=MENTIONNABLE,10=NUMBER");
|
|
162
|
+
const type = parseInt(await this.requireInput("Option type (3-10): ", val => {
|
|
163
|
+
const n = parseInt(val);
|
|
164
|
+
return n >= 3 && n <= 10;
|
|
165
|
+
}));
|
|
166
|
+
const name = await this.requireInput("Option name: ");
|
|
167
|
+
const description = await this.requireInput("Option description: ");
|
|
168
|
+
const required = await this.yesNoInput("Required? (y/n): ");
|
|
169
|
+
const option = { type, name, description, required };
|
|
170
|
+
if ([3, 4, 10].includes(type)) {
|
|
171
|
+
// String, Integer, Number
|
|
172
|
+
option.choices = await this.addChoices();
|
|
173
|
+
}
|
|
174
|
+
if (type === 3) { // String
|
|
175
|
+
option.min_length = parseInt(await this.prompt("Min length (optional, Enter=skip): ")) || undefined;
|
|
176
|
+
option.max_length = parseInt(await this.prompt("Max length (optional, Enter=skip): ")) || undefined;
|
|
177
|
+
}
|
|
178
|
+
else if ([4, 10].includes(type)) { // Int/Number
|
|
179
|
+
option.min_value = parseFloat(await this.prompt("Min value (optional, Enter=skip): ")) || undefined;
|
|
180
|
+
option.max_value = parseFloat(await this.prompt("Max value (optional, Enter=skip): ")) || undefined;
|
|
181
|
+
}
|
|
182
|
+
else if (type === 7) { // Channel
|
|
183
|
+
option.channel_types = await this.addChannelTypes();
|
|
184
|
+
}
|
|
185
|
+
options.push(option);
|
|
186
|
+
continueAdding = await this.yesNoInput("Add another option? (y/n): ");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async addChoices() {
|
|
190
|
+
const choices = [];
|
|
191
|
+
let continueAdding = await this.yesNoInput("Add choices? (y/n): ");
|
|
192
|
+
while (continueAdding && choices.length < 25) {
|
|
193
|
+
const name = await this.requireInput("Choice name: ");
|
|
194
|
+
const value = await this.requireInput("Choice value: ");
|
|
195
|
+
choices.push({ name, value });
|
|
196
|
+
continueAdding = await this.yesNoInput("Add another choice? (y/n): ");
|
|
197
|
+
}
|
|
198
|
+
return choices.length > 0 ? choices : undefined;
|
|
199
|
+
}
|
|
200
|
+
async addChannelTypes() {
|
|
201
|
+
console.log("Channel types: 0=text, 2=voice, 4=category, 5=announcement, 10=thread, 11=public-thread, 12=private-thread");
|
|
202
|
+
const input = await this.requireInput("Channel types (comma sep, or Enter=none): ", undefined, true);
|
|
203
|
+
return input ? input.split(",").map(i => parseInt(i.trim())).filter(i => !isNaN(i)) : undefined;
|
|
204
|
+
}
|
|
205
|
+
async addSimpleOptions(config) {
|
|
206
|
+
console.clear();
|
|
207
|
+
console.log("➕ Simple Options");
|
|
208
|
+
let continueAdding = await this.yesNoInput("Add options? (y/n): ");
|
|
209
|
+
config.options = [];
|
|
210
|
+
while (continueAdding) {
|
|
211
|
+
console.log("Quick option types: 3=string,4=int,5=bool,6=user,7=channel,8=role,9=mentionnable,10=number");
|
|
212
|
+
const type = parseInt(await this.requireInput("Type (3-10): ", val => ["3", "4", "5", "6", "7", "8", "9", "10"].includes(val)));
|
|
213
|
+
const name = await this.requireInput("Name: ");
|
|
214
|
+
const desc = await this.requireInput("Description: ");
|
|
215
|
+
const required = await this.yesNoInput("Required?: ");
|
|
216
|
+
config.options.push({ type, name, description: desc, required });
|
|
217
|
+
continueAdding = await this.yesNoInput("Another option? (y/n): ");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.SlashCommandGeneratorCLI = SlashCommandGeneratorCLI;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerationCLI = void 0;
|
|
4
|
+
const BaseCLI_1 = require("./BaseCLI");
|
|
5
|
+
class GenerationCLI extends BaseCLI_1.BaseCLI {
|
|
6
|
+
getTitle() {
|
|
7
|
+
return '⚙️ Generation Manager CLI';
|
|
8
|
+
}
|
|
9
|
+
async showMainMenu() {
|
|
10
|
+
console.clear();
|
|
11
|
+
console.log(this.getTitle());
|
|
12
|
+
console.log('═'.repeat(40));
|
|
13
|
+
console.log('1. Generate Slash Command Template');
|
|
14
|
+
console.log('2. Generate Context Menu Template');
|
|
15
|
+
console.log('3. Generate All Templates');
|
|
16
|
+
console.log('4. Back');
|
|
17
|
+
console.log('═'.repeat(40));
|
|
18
|
+
const choice = await this.prompt('Choose an option: ');
|
|
19
|
+
switch (choice) {
|
|
20
|
+
case '1':
|
|
21
|
+
console.log('Slash template generation - TODO');
|
|
22
|
+
break;
|
|
23
|
+
case '2':
|
|
24
|
+
console.log('Context menu template - TODO');
|
|
25
|
+
break;
|
|
26
|
+
case '3':
|
|
27
|
+
console.log('All templates - TODO');
|
|
28
|
+
break;
|
|
29
|
+
case '4':
|
|
30
|
+
case 'exit': return this.goBack();
|
|
31
|
+
}
|
|
32
|
+
await this.prompt('Press Enter to continue...');
|
|
33
|
+
return this.showMainMenu();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.GenerationCLI = GenerationCLI;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildListManager = void 0;
|
|
4
|
+
const BaseCLI_1 = require("./BaseCLI");
|
|
5
|
+
const rest_1 = require("@discordjs/rest");
|
|
6
|
+
const v10_1 = require("discord-api-types/v10");
|
|
7
|
+
class GuildListManager extends BaseCLI_1.BaseCLI {
|
|
8
|
+
constructor(clientId, token) {
|
|
9
|
+
super();
|
|
10
|
+
this.guilds = [];
|
|
11
|
+
this.menuSelection = [
|
|
12
|
+
{ label: "List guilds", action: () => this.list() },
|
|
13
|
+
{ label: "Choose guild", action: () => this.chooseGuild() },
|
|
14
|
+
{ label: "Back", action: () => this.goBack() },
|
|
15
|
+
];
|
|
16
|
+
this.clientId = clientId;
|
|
17
|
+
this.token = token;
|
|
18
|
+
this.rest = new rest_1.REST({ version: '10' }).setToken(token);
|
|
19
|
+
}
|
|
20
|
+
getTitle() {
|
|
21
|
+
return "Guilds Selection";
|
|
22
|
+
}
|
|
23
|
+
async execute() {
|
|
24
|
+
throw new Error("Method not implemented.");
|
|
25
|
+
}
|
|
26
|
+
async list(printResult = true) {
|
|
27
|
+
console.clear();
|
|
28
|
+
if (printResult)
|
|
29
|
+
console.log(`${this.getTitle()}\n`);
|
|
30
|
+
try {
|
|
31
|
+
this.guilds = await this.rest.get(v10_1.Routes.userGuilds());
|
|
32
|
+
if (printResult) {
|
|
33
|
+
console.table(this.guilds.map((g, i) => ({
|
|
34
|
+
Index: i,
|
|
35
|
+
"Guild ID": g.id,
|
|
36
|
+
Nom: g.name
|
|
37
|
+
})));
|
|
38
|
+
console.log(`\n📋 ${this.guilds.length} guild(s) found\n`);
|
|
39
|
+
}
|
|
40
|
+
return this.guilds;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error(`Error when listing guilds: ${error}`);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async chooseGuild() {
|
|
48
|
+
await this.list();
|
|
49
|
+
if (!this.guilds.length) {
|
|
50
|
+
console.log("No available Guild\n");
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const indexStr = await this.requireInput("Enter guild index (0-" + (this.guilds.length - 1) + "): ", (val) => {
|
|
54
|
+
const num = Number(val);
|
|
55
|
+
return !isNaN(num) && num >= 0 && num < this.guilds.length;
|
|
56
|
+
}, false);
|
|
57
|
+
const index = Number(indexStr);
|
|
58
|
+
return this.guilds[index] ?? null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.GuildListManager = GuildListManager;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const BaseCLI_1 = require("./BaseCLI");
|
|
4
|
+
/*import {BaseClient} from "discord.js";
|
|
5
|
+
|
|
6
|
+
/*class SimpleDiscordBotCLI extends BaseCLI {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
protected getTitle(): string {
|
|
11
|
+
throw new Error("Method not implemented.");
|
|
12
|
+
}
|
|
13
|
+
protected showManagersMenu(): Promise<void> {
|
|
14
|
+
throw new Error("Method not implemented.");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async start(): Promise<void> {
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
}*/
|
|
25
|
+
new BaseCLI_1.BaseCLI();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InteractionCLI = void 0;
|
|
4
|
+
const BaseCLI_1 = require("../BaseCLI");
|
|
5
|
+
const BotEnv_1 = require("../../bot/BotEnv");
|
|
6
|
+
const InteractionManager_1 = require("../../manager/handlers/interactions/InteractionManager");
|
|
7
|
+
const InteractionCLIManager_1 = require("./InteractionCLIManager");
|
|
8
|
+
class InteractionCLI extends BaseCLI_1.BaseCLI {
|
|
9
|
+
getTitle() {
|
|
10
|
+
return '🔄 Interaction Manager CLI';
|
|
11
|
+
}
|
|
12
|
+
constructor(parent) {
|
|
13
|
+
super(parent);
|
|
14
|
+
this.managers = {};
|
|
15
|
+
this.menuSelection = [
|
|
16
|
+
{ label: "Command Manager", action: () => new InteractionCLIManager_1.InteractionManagerCLI(this, this.managers["CommandManager"], "CommandManager") },
|
|
17
|
+
{ label: "ContextMenu Manager", action: () => new InteractionCLIManager_1.InteractionManagerCLI(this, this.managers["ContextMenuManager"], "ContextMenuManager") },
|
|
18
|
+
//{ label: "All Interaction Manager", action: () => new InteractionManagerCLI(this, this.managers["InteractionManager"], "InteractionManager") },
|
|
19
|
+
{ label: 'Back', action: () => this.goBack() },
|
|
20
|
+
];
|
|
21
|
+
const { clientId, token } = BotEnv_1.BotEnv;
|
|
22
|
+
this.managers['CommandManager'] = new InteractionManager_1.CommandManager(clientId, token);
|
|
23
|
+
this.managers['ContextMenuManager'] = new InteractionManager_1.ContextMenuManager(clientId, token);
|
|
24
|
+
//this.managers['InteractionManager'] = new AllInteractionManager(clientId, token);
|
|
25
|
+
}
|
|
26
|
+
async execute() {
|
|
27
|
+
throw new Error("Method not implemented.");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.InteractionCLI = InteractionCLI;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InteractionManagerCLI = void 0;
|
|
4
|
+
const BaseCLI_1 = require("../BaseCLI");
|
|
5
|
+
const GuildListManager_1 = require("../GuildListManager");
|
|
6
|
+
const BotEnv_1 = require("../../bot/BotEnv");
|
|
7
|
+
class InteractionManagerCLI extends BaseCLI_1.BaseCLI {
|
|
8
|
+
getTitle() {
|
|
9
|
+
return `${this.managerKey} - ${this.manager.folderPath}`;
|
|
10
|
+
}
|
|
11
|
+
constructor(parent, manager, managerKey) {
|
|
12
|
+
super(parent);
|
|
13
|
+
this.menuSelection = [
|
|
14
|
+
{ label: `List Global commands`, action: () => this.listRemote() },
|
|
15
|
+
{ label: "List commands per GuildID", action: async () => this.guildListRemote(await new GuildListManager_1.GuildListManager(BotEnv_1.BotEnv.clientId, BotEnv_1.BotEnv.token).chooseGuild()) },
|
|
16
|
+
{ label: "List commands per Guild", action: async () => this.guildListAllRemote() },
|
|
17
|
+
{ label: "Deploy local", action: () => this.handleDeploy() },
|
|
18
|
+
{ label: "Update remote", action: () => this.handleUpdate() },
|
|
19
|
+
{ label: "Delete remote", action: () => this.handleDelete() },
|
|
20
|
+
{ label: 'Back', action: () => this.goBack() },
|
|
21
|
+
];
|
|
22
|
+
this.manager = manager;
|
|
23
|
+
this.managerKey = managerKey;
|
|
24
|
+
}
|
|
25
|
+
execute() {
|
|
26
|
+
throw new Error("Method not implemented.");
|
|
27
|
+
}
|
|
28
|
+
async listRemote() {
|
|
29
|
+
await this.manager.list();
|
|
30
|
+
}
|
|
31
|
+
async guildListRemote(guild) {
|
|
32
|
+
if (!guild) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await this.manager.listGuild(guild.id);
|
|
36
|
+
}
|
|
37
|
+
async guildListAllRemote() {
|
|
38
|
+
await this.manager.listAllGuilds(await new GuildListManager_1.GuildListManager(BotEnv_1.BotEnv.clientId, BotEnv_1.BotEnv.token).list(false));
|
|
39
|
+
}
|
|
40
|
+
async handleDeploy() {
|
|
41
|
+
const selected = await this.selectCommands(this.manager, false);
|
|
42
|
+
if (selected.length === 0)
|
|
43
|
+
return;
|
|
44
|
+
await this.manager.deploy(selected);
|
|
45
|
+
}
|
|
46
|
+
async handleUpdate() {
|
|
47
|
+
const selected = await this.selectCommands(this.manager);
|
|
48
|
+
if (selected.length === 0)
|
|
49
|
+
return;
|
|
50
|
+
await this.manager.update(selected);
|
|
51
|
+
}
|
|
52
|
+
async handleDelete() {
|
|
53
|
+
const selected = await this.selectCommands(this.manager);
|
|
54
|
+
if (selected.length === 0)
|
|
55
|
+
return;
|
|
56
|
+
await this.manager.delete(selected);
|
|
57
|
+
}
|
|
58
|
+
async selectCommands(manager, remote = true) {
|
|
59
|
+
const handlerManagerType = `${manager.folderPath}(s)`;
|
|
60
|
+
const commandList = remote ? await manager.list() : await manager.listFromFile();
|
|
61
|
+
if (!commandList?.length) {
|
|
62
|
+
console.log(`No ${handlerManagerType} found`);
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
const input = await this.prompt('Enter numbers (ex: 1,3,5 or "all" or "exit"): ');
|
|
66
|
+
if (input.toLowerCase() === 'all')
|
|
67
|
+
return commandList;
|
|
68
|
+
if (input.toLowerCase() === 'exit')
|
|
69
|
+
return [];
|
|
70
|
+
const indices = input.split(',').map(i => parseInt(i.trim())).filter(i => !isNaN(i));
|
|
71
|
+
const selected = commandList.filter((cmd) => indices.includes(cmd.index));
|
|
72
|
+
if (selected.length === 0) {
|
|
73
|
+
console.log('Invalid number');
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
console.log(`${selected.length} selected ${handlerManagerType}`);
|
|
77
|
+
return selected;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.InteractionManagerCLI = InteractionManagerCLI;
|