zumito-framework 1.1.55 → 1.1.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/TranslationManager.d.ts +1 -1
- package/dist/TranslationManager.js +1 -1
- package/dist/ZumitoFramework.d.ts +95 -24
- package/dist/ZumitoFramework.js +129 -48
- package/dist/baseModule/events/discord/interactionCreate.d.ts +4 -4
- package/dist/baseModule/events/discord/interactionCreate.js +58 -17
- package/dist/baseModule/events/discord/messageCreate.d.ts +3 -3
- package/dist/baseModule/events/discord/messageCreate.js +89 -61
- package/dist/baseModule/index.d.ts +2 -2
- package/dist/baseModule/index.js +4 -4
- package/dist/definitions/ApiResponse.js +2 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/managers/EmojiManager.d.ts +1 -1
- package/dist/types/Command.d.ts +7 -7
- package/dist/types/Command.js +4 -5
- package/dist/types/CommandArguments.d.ts +1 -1
- package/dist/types/CommandParameters.d.ts +3 -3
- package/dist/types/Commands/ButtonPressed.d.ts +1 -1
- package/dist/types/Commands/ButtonPressedParams.d.ts +2 -2
- package/dist/types/EventParameters.d.ts +2 -2
- package/dist/types/Module.d.ts +3 -3
- package/dist/types/Module.js +78 -40
- package/dist/types/SelectMenuParameters.d.ts +2 -2
- package/dist/types/Translation.js +1 -1
- package/dist/utils/EmojiFallback.d.ts +1 -1
- package/dist/utils/EmojiFallback.js +2 -2
- package/package.json +3 -9
- package/plop-templates/command.js.hbs +0 -17
- package/plop-templates/translation.json.hbs +0 -8
- package/plopfile.js +0 -116
- package/templateGenerator.mjs +0 -26
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import { GuildMember, TextChannel } from
|
|
2
|
-
import { Command } from
|
|
3
|
-
import { FrameworkSettings } from
|
|
4
|
-
import { Module } from
|
|
5
|
-
import { FrameworkEvent } from
|
|
6
|
-
import { TranslationManager } from
|
|
1
|
+
import { GuildMember, TextChannel, Client } from 'discord.js';
|
|
2
|
+
import { Command } from './types/Command.js';
|
|
3
|
+
import { FrameworkSettings } from './types/FrameworkSettings.js';
|
|
4
|
+
import { Module } from './types/Module.js';
|
|
5
|
+
import { FrameworkEvent } from './types/FrameworkEvent.js';
|
|
6
|
+
import { TranslationManager } from './TranslationManager.js';
|
|
7
7
|
/**
|
|
8
8
|
* @class ZumitoFramework
|
|
9
9
|
* @classdesc The main class of the framework.
|
|
10
10
|
*
|
|
11
|
-
* @property {FrameworkSettings} settings - The settings
|
|
12
|
-
* @property {Client} client - The
|
|
13
|
-
* @property {
|
|
14
|
-
* @property {
|
|
11
|
+
* @property {FrameworkSettings} settings - The settings for the framework.
|
|
12
|
+
* @property {Client} client - The discord client instance.
|
|
13
|
+
* @property {Map<string, Module>} modules - The modules loaded in the framework.
|
|
14
|
+
* @property {Map<string, Command>} commands - The commands loaded in the framework.
|
|
15
|
+
* @property {Map<string, FrameworkEvent>} events - The events loaded in the framework.
|
|
16
|
+
* @property {TranslationManager} translations - The Translation Manager for the framework.
|
|
17
|
+
* @property {Map<string, any>} models - The database models loaded in the framework.
|
|
18
|
+
* @property {mongoose.Connection} database - The connection to the MongoDB database.
|
|
19
|
+
* @property {express.Application} app - The ExpressJS application for the API server.
|
|
15
20
|
*/
|
|
16
21
|
export declare class ZumitoFramework {
|
|
17
|
-
client:
|
|
22
|
+
client: Client;
|
|
18
23
|
settings: FrameworkSettings;
|
|
19
24
|
modules: Map<string, Module>;
|
|
20
25
|
commands: Map<string, Command>;
|
|
@@ -26,26 +31,92 @@ export declare class ZumitoFramework {
|
|
|
26
31
|
app: any;
|
|
27
32
|
/**
|
|
28
33
|
* @constructor
|
|
29
|
-
* @
|
|
30
|
-
* @param {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
34
|
+
* @param {FrameworkSettings} settings - The settings to use for the framework.
|
|
35
|
+
* @param {(framework: ZumitoFramework) => void} [callback] - A callback to be called when the framework has finished initializing.
|
|
36
|
+
*/
|
|
37
|
+
constructor(settings: FrameworkSettings, callback?: (framework: any) => void);
|
|
38
|
+
/**
|
|
39
|
+
* Initializes the framework.
|
|
40
|
+
* Connects to the MongoDB database, starts the Discord client, and runs API server.
|
|
41
|
+
* It also loads the modules from the project's modules folder.
|
|
42
|
+
* @async
|
|
43
|
+
* @private
|
|
44
|
+
* @returns {Promise<void>}
|
|
45
|
+
*/
|
|
46
|
+
private initialize;
|
|
47
|
+
/**
|
|
48
|
+
* Initializes and starts the API server using ExpressJS.
|
|
49
|
+
* Sets up middleware, routes, and error handling for the server.
|
|
40
50
|
*/
|
|
41
|
-
constructor(settings: FrameworkSettings, callback?: Function);
|
|
42
|
-
initialize(): Promise<void>;
|
|
43
51
|
startApiServer(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Register all modules in the 'modules' folder.
|
|
54
|
+
* Scans the specified folder for module files and calls the `registerModule` method for each file.
|
|
55
|
+
* Also, it loads the baseModule in the framework.
|
|
56
|
+
* @private
|
|
57
|
+
* @returns {Promise<void>}
|
|
58
|
+
*/
|
|
44
59
|
private registerModules;
|
|
45
60
|
private registerModule;
|
|
61
|
+
/**
|
|
62
|
+
* Initializes the Discord client using the Discord.js library.
|
|
63
|
+
* Logs in to the Discord API using the provided token and logs a message when the client is ready.
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
46
66
|
private initializeDiscordClient;
|
|
67
|
+
/**
|
|
68
|
+
* From a command-line string, returns an array of parameters.
|
|
69
|
+
* @param commandLine
|
|
70
|
+
* @returns {string[]}
|
|
71
|
+
* @private
|
|
72
|
+
* @static
|
|
73
|
+
* @example
|
|
74
|
+
* // returns ['a', 'b', 'c']
|
|
75
|
+
* splitCommandLine('a b c');
|
|
76
|
+
* @example
|
|
77
|
+
* // returns ['a', 'b c']
|
|
78
|
+
* splitCommandLine('a "b c"');
|
|
79
|
+
*/
|
|
47
80
|
static splitCommandLine(commandLine: any): any;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if a member has a permission in a channel.
|
|
83
|
+
* @param member
|
|
84
|
+
* @param channel
|
|
85
|
+
* @param permission
|
|
86
|
+
* @returns {Promise<boolean>}
|
|
87
|
+
* @public
|
|
88
|
+
* @example
|
|
89
|
+
* // returns true if the member has the permission
|
|
90
|
+
* memberHasPermission(member, channel, Permissions.FLAGS.MANAGE_MESSAGES);
|
|
91
|
+
* @example
|
|
92
|
+
* // returns true if the member has the permission
|
|
93
|
+
* memberHasPermission(member, channel, Permissions.FLAGS.MANAGE_MESSAGES | Permissions.FLAGS.MANAGE_CHANNELS);
|
|
94
|
+
* @example
|
|
95
|
+
*/
|
|
48
96
|
memberHasPermission(member: GuildMember, channel: TextChannel, permission: bigint): Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Gets the guild settings from the database.
|
|
99
|
+
* If the guild is not in the database, it is added.
|
|
100
|
+
* @param guildId
|
|
101
|
+
* @returns {Promise<any>}
|
|
102
|
+
* @public
|
|
103
|
+
* @async
|
|
104
|
+
* @example
|
|
105
|
+
* // returns the guild settings
|
|
106
|
+
* getGuildSettings('123456789012345678');
|
|
107
|
+
* @example
|
|
108
|
+
* // returns the guild settings
|
|
109
|
+
* getGuildSettings(guild.id);
|
|
110
|
+
* @example
|
|
111
|
+
* // returns the guild settings
|
|
112
|
+
* getGuildSettings(message.guild.id);
|
|
113
|
+
* @example
|
|
114
|
+
* // returns the guild settings
|
|
115
|
+
* getGuildSettings(interaction.guild.id);
|
|
116
|
+
* @example
|
|
117
|
+
* // returns the guild settings
|
|
118
|
+
* getGuildSettings(interaction.guildId);
|
|
119
|
+
*/
|
|
49
120
|
getGuildSettings(guildId: string): Promise<any>;
|
|
50
121
|
refreshSlashCommands(): Promise<void>;
|
|
51
122
|
}
|
package/dist/ZumitoFramework.js
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
import { SlashCommandBuilder } from
|
|
2
|
-
import { Module } from
|
|
1
|
+
import { SlashCommandBuilder, Client, } from 'discord.js';
|
|
2
|
+
import { Module } from './types/Module.js';
|
|
3
3
|
import { ApiResponse } from './definitions/ApiResponse.js';
|
|
4
|
-
import { baseModule } from
|
|
5
|
-
import { TranslationManager } from
|
|
4
|
+
import { baseModule } from './baseModule/index.js';
|
|
5
|
+
import { TranslationManager } from './TranslationManager.js';
|
|
6
6
|
import express from 'express';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import { Client } from "discord.js";
|
|
10
9
|
// import better-logging
|
|
11
|
-
import { betterLogging } from
|
|
10
|
+
import { betterLogging } from 'better-logging';
|
|
12
11
|
betterLogging(console);
|
|
13
12
|
import { REST } from '@discordjs/rest';
|
|
14
13
|
import { Routes } from 'discord-api-types/v9';
|
|
15
|
-
import mongoose from
|
|
14
|
+
import mongoose from 'mongoose';
|
|
16
15
|
import cookieParser from 'cookie-parser';
|
|
17
16
|
import cors from 'cors';
|
|
18
17
|
import http from 'http';
|
|
19
18
|
import * as url from 'url';
|
|
20
|
-
import { CommandType } from
|
|
19
|
+
import { CommandType } from './types/CommandType.js';
|
|
21
20
|
/**
|
|
22
21
|
* @class ZumitoFramework
|
|
23
22
|
* @classdesc The main class of the framework.
|
|
24
23
|
*
|
|
25
|
-
* @property {FrameworkSettings} settings - The settings
|
|
26
|
-
* @property {Client} client - The
|
|
27
|
-
* @property {
|
|
28
|
-
* @property {
|
|
24
|
+
* @property {FrameworkSettings} settings - The settings for the framework.
|
|
25
|
+
* @property {Client} client - The discord client instance.
|
|
26
|
+
* @property {Map<string, Module>} modules - The modules loaded in the framework.
|
|
27
|
+
* @property {Map<string, Command>} commands - The commands loaded in the framework.
|
|
28
|
+
* @property {Map<string, FrameworkEvent>} events - The events loaded in the framework.
|
|
29
|
+
* @property {TranslationManager} translations - The Translation Manager for the framework.
|
|
30
|
+
* @property {Map<string, any>} models - The database models loaded in the framework.
|
|
31
|
+
* @property {mongoose.Connection} database - The connection to the MongoDB database.
|
|
32
|
+
* @property {express.Application} app - The ExpressJS application for the API server.
|
|
29
33
|
*/
|
|
30
34
|
export class ZumitoFramework {
|
|
31
35
|
client;
|
|
@@ -40,17 +44,8 @@ export class ZumitoFramework {
|
|
|
40
44
|
app;
|
|
41
45
|
/**
|
|
42
46
|
* @constructor
|
|
43
|
-
* @
|
|
44
|
-
* @param {
|
|
45
|
-
* @example new ZumitoFramework({
|
|
46
|
-
* prefix: '!',
|
|
47
|
-
* discordClientOptions: {
|
|
48
|
-
* token: 'token',
|
|
49
|
-
* clientId: 'clientId',
|
|
50
|
-
* intents: 0
|
|
51
|
-
* }
|
|
52
|
-
* });
|
|
53
|
-
* @public
|
|
47
|
+
* @param {FrameworkSettings} settings - The settings to use for the framework.
|
|
48
|
+
* @param {(framework: ZumitoFramework) => void} [callback] - A callback to be called when the framework has finished initializing.
|
|
54
49
|
*/
|
|
55
50
|
constructor(settings, callback) {
|
|
56
51
|
this.settings = settings;
|
|
@@ -62,20 +57,30 @@ export class ZumitoFramework {
|
|
|
62
57
|
if (settings.logLevel) {
|
|
63
58
|
console.logLevel = settings.logLevel;
|
|
64
59
|
}
|
|
65
|
-
this.initialize()
|
|
60
|
+
this.initialize()
|
|
61
|
+
.then(() => {
|
|
66
62
|
if (callback)
|
|
67
63
|
callback(this);
|
|
68
|
-
})
|
|
64
|
+
})
|
|
65
|
+
.catch((err) => {
|
|
69
66
|
console.error(err, err.message, err.stack, err.name);
|
|
70
67
|
});
|
|
71
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Initializes the framework.
|
|
71
|
+
* Connects to the MongoDB database, starts the Discord client, and runs API server.
|
|
72
|
+
* It also loads the modules from the project's modules folder.
|
|
73
|
+
* @async
|
|
74
|
+
* @private
|
|
75
|
+
* @returns {Promise<void>}
|
|
76
|
+
*/
|
|
72
77
|
async initialize() {
|
|
73
78
|
try {
|
|
74
79
|
mongoose.set('strictQuery', true);
|
|
75
80
|
await mongoose.connect(this.settings.mongoQueryString);
|
|
76
81
|
}
|
|
77
82
|
catch (err) {
|
|
78
|
-
console.error(
|
|
83
|
+
console.error('[🗄️🔴] Database connection error:', err.message);
|
|
79
84
|
process.exit(1);
|
|
80
85
|
}
|
|
81
86
|
finally {
|
|
@@ -87,11 +92,15 @@ export class ZumitoFramework {
|
|
|
87
92
|
await this.registerModules();
|
|
88
93
|
await this.refreshSlashCommands();
|
|
89
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Initializes and starts the API server using ExpressJS.
|
|
97
|
+
* Sets up middleware, routes, and error handling for the server.
|
|
98
|
+
*/
|
|
90
99
|
startApiServer() {
|
|
91
100
|
this.app = express();
|
|
92
|
-
|
|
101
|
+
const port = process.env.PORT || '80';
|
|
93
102
|
this.app.set('port', port);
|
|
94
|
-
|
|
103
|
+
const server = http.createServer(this.app);
|
|
95
104
|
server.listen(port);
|
|
96
105
|
server.on('error', (err) => {
|
|
97
106
|
console.log('[🌐🔴] Error starting API web server: ' + err);
|
|
@@ -109,15 +118,22 @@ export class ZumitoFramework {
|
|
|
109
118
|
//this.app.use("/", indexRouter);
|
|
110
119
|
//this.app.use("/api/", apiRouter);
|
|
111
120
|
// throw 404 if URL not found
|
|
112
|
-
this.app.all(
|
|
113
|
-
return ApiResponse.notFoundResponse(res,
|
|
121
|
+
this.app.all('*', function (req, res) {
|
|
122
|
+
return ApiResponse.notFoundResponse(res, 'Page not found');
|
|
114
123
|
});
|
|
115
124
|
this.app.use(function (err, req, res) {
|
|
116
125
|
if (err.name === 'UnauthorizedError') {
|
|
117
|
-
return ApiResponse.unauthorizedResponse(res,
|
|
126
|
+
return ApiResponse.unauthorizedResponse(res, 'Invalid token');
|
|
118
127
|
}
|
|
119
128
|
});
|
|
120
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Register all modules in the 'modules' folder.
|
|
132
|
+
* Scans the specified folder for module files and calls the `registerModule` method for each file.
|
|
133
|
+
* Also, it loads the baseModule in the framework.
|
|
134
|
+
* @private
|
|
135
|
+
* @returns {Promise<void>}
|
|
136
|
+
*/
|
|
121
137
|
async registerModules() {
|
|
122
138
|
let modulesFolder;
|
|
123
139
|
if (fs.existsSync(`${process.cwd()}/modules`)) {
|
|
@@ -130,8 +146,8 @@ export class ZumitoFramework {
|
|
|
130
146
|
return;
|
|
131
147
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
132
148
|
await this.registerModule(__dirname, 'baseModule', baseModule);
|
|
133
|
-
|
|
134
|
-
for (
|
|
149
|
+
const files = fs.readdirSync(modulesFolder);
|
|
150
|
+
for (const file of files) {
|
|
135
151
|
await this.registerModule(modulesFolder, file);
|
|
136
152
|
}
|
|
137
153
|
this.models.forEach((modelDefinition, modelName) => {
|
|
@@ -152,7 +168,6 @@ export class ZumitoFramework {
|
|
|
152
168
|
else {
|
|
153
169
|
module = Module;
|
|
154
170
|
}
|
|
155
|
-
;
|
|
156
171
|
}
|
|
157
172
|
// Create module instance
|
|
158
173
|
let moduleInstance;
|
|
@@ -171,7 +186,10 @@ export class ZumitoFramework {
|
|
|
171
186
|
this.commands.set(command.name, command);
|
|
172
187
|
});
|
|
173
188
|
}
|
|
174
|
-
this.commands = new Map([
|
|
189
|
+
this.commands = new Map([
|
|
190
|
+
...this.commands,
|
|
191
|
+
...moduleInstance.getCommands(),
|
|
192
|
+
]);
|
|
175
193
|
// Register module events
|
|
176
194
|
this.events = new Map([...this.events, ...moduleInstance.getEvents()]);
|
|
177
195
|
// Register models
|
|
@@ -190,9 +208,14 @@ export class ZumitoFramework {
|
|
|
190
208
|
|
|
191
209
|
*/
|
|
192
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Initializes the Discord client using the Discord.js library.
|
|
213
|
+
* Logs in to the Discord API using the provided token and logs a message when the client is ready.
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
193
216
|
initializeDiscordClient() {
|
|
194
217
|
this.client = new Client({
|
|
195
|
-
intents: this.settings.discordClientOptions.intents
|
|
218
|
+
intents: this.settings.discordClientOptions.intents,
|
|
196
219
|
});
|
|
197
220
|
this.client.login(this.settings.discordClientOptions.token);
|
|
198
221
|
this.client.on('ready', () => {
|
|
@@ -200,11 +223,24 @@ export class ZumitoFramework {
|
|
|
200
223
|
console.log('[🤖🟢] Discord client ready');
|
|
201
224
|
});
|
|
202
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* From a command-line string, returns an array of parameters.
|
|
228
|
+
* @param commandLine
|
|
229
|
+
* @returns {string[]}
|
|
230
|
+
* @private
|
|
231
|
+
* @static
|
|
232
|
+
* @example
|
|
233
|
+
* // returns ['a', 'b', 'c']
|
|
234
|
+
* splitCommandLine('a b c');
|
|
235
|
+
* @example
|
|
236
|
+
* // returns ['a', 'b c']
|
|
237
|
+
* splitCommandLine('a "b c"');
|
|
238
|
+
*/
|
|
203
239
|
static splitCommandLine(commandLine) {
|
|
204
240
|
//log( 'commandLine', commandLine ) ;
|
|
205
241
|
// Find a unique marker for the space character.
|
|
206
242
|
// Start with '<SP>' and repeatedly append '@' if necessary to make it unique.
|
|
207
|
-
|
|
243
|
+
let spaceMarker = '<SP>';
|
|
208
244
|
while (commandLine.indexOf(spaceMarker) > -1)
|
|
209
245
|
spaceMarker += '@';
|
|
210
246
|
// Protect double-quoted strings.
|
|
@@ -213,21 +249,59 @@ export class ZumitoFramework {
|
|
|
213
249
|
// o Replace each double-quoted-string with what's inside the qouble-quotes,
|
|
214
250
|
// after each space character has been replaced with the space-marker above.
|
|
215
251
|
// o The outer double-quotes will not be present.
|
|
216
|
-
|
|
252
|
+
const noSpacesInQuotes = commandLine.replace(/"([^"]*)"?/g, (fullMatch, capture) => {
|
|
217
253
|
return capture.replace(/ /g, spaceMarker);
|
|
218
254
|
});
|
|
219
255
|
// Now that it is safe to do so, split the command-line at one-or-more spaces.
|
|
220
|
-
|
|
256
|
+
const mangledParamArray = noSpacesInQuotes.split(/ +/);
|
|
221
257
|
// Create a new array by restoring spaces from any space-markers.
|
|
222
|
-
|
|
258
|
+
const paramArray = mangledParamArray.map((mangledParam) => {
|
|
223
259
|
return mangledParam.replace(RegExp(spaceMarker, 'g'), ' ');
|
|
224
260
|
});
|
|
225
261
|
return paramArray;
|
|
226
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Checks if a member has a permission in a channel.
|
|
265
|
+
* @param member
|
|
266
|
+
* @param channel
|
|
267
|
+
* @param permission
|
|
268
|
+
* @returns {Promise<boolean>}
|
|
269
|
+
* @public
|
|
270
|
+
* @example
|
|
271
|
+
* // returns true if the member has the permission
|
|
272
|
+
* memberHasPermission(member, channel, Permissions.FLAGS.MANAGE_MESSAGES);
|
|
273
|
+
* @example
|
|
274
|
+
* // returns true if the member has the permission
|
|
275
|
+
* memberHasPermission(member, channel, Permissions.FLAGS.MANAGE_MESSAGES | Permissions.FLAGS.MANAGE_CHANNELS);
|
|
276
|
+
* @example
|
|
277
|
+
*/
|
|
227
278
|
async memberHasPermission(member, channel, permission) {
|
|
228
|
-
|
|
279
|
+
const memberPermission = await channel.permissionsFor(member);
|
|
229
280
|
return memberPermission.has(permission);
|
|
230
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Gets the guild settings from the database.
|
|
284
|
+
* If the guild is not in the database, it is added.
|
|
285
|
+
* @param guildId
|
|
286
|
+
* @returns {Promise<any>}
|
|
287
|
+
* @public
|
|
288
|
+
* @async
|
|
289
|
+
* @example
|
|
290
|
+
* // returns the guild settings
|
|
291
|
+
* getGuildSettings('123456789012345678');
|
|
292
|
+
* @example
|
|
293
|
+
* // returns the guild settings
|
|
294
|
+
* getGuildSettings(guild.id);
|
|
295
|
+
* @example
|
|
296
|
+
* // returns the guild settings
|
|
297
|
+
* getGuildSettings(message.guild.id);
|
|
298
|
+
* @example
|
|
299
|
+
* // returns the guild settings
|
|
300
|
+
* getGuildSettings(interaction.guild.id);
|
|
301
|
+
* @example
|
|
302
|
+
* // returns the guild settings
|
|
303
|
+
* getGuildSettings(interaction.guildId);
|
|
304
|
+
*/
|
|
231
305
|
async getGuildSettings(guildId) {
|
|
232
306
|
const Guild = this.models.get('Guild');
|
|
233
307
|
let guild = await Guild.findOne({ guild_id: guildId }).exec();
|
|
@@ -241,10 +315,12 @@ export class ZumitoFramework {
|
|
|
241
315
|
}
|
|
242
316
|
async refreshSlashCommands() {
|
|
243
317
|
const rest = new REST({ version: '10' }).setToken(this.settings.discordClientOptions.token);
|
|
244
|
-
|
|
245
|
-
.filter((command) => command.type == CommandType.slash ||
|
|
318
|
+
const commands = Array.from(this.commands.values())
|
|
319
|
+
.filter((command) => command.type == CommandType.slash ||
|
|
320
|
+
command.type == CommandType.separated ||
|
|
321
|
+
command.type == CommandType.any)
|
|
246
322
|
.map((command) => {
|
|
247
|
-
|
|
323
|
+
const slashCommand = new SlashCommandBuilder()
|
|
248
324
|
.setName(command.name)
|
|
249
325
|
.setDescription(this.translations.get('command.' + command.name + '.description', 'en'));
|
|
250
326
|
if (command.args) {
|
|
@@ -269,17 +345,22 @@ export class ZumitoFramework {
|
|
|
269
345
|
}
|
|
270
346
|
slashCommand[method]((option) => {
|
|
271
347
|
option.setName(arg.name);
|
|
272
|
-
option.setDescription(this.translations.get('command.' +
|
|
348
|
+
option.setDescription(this.translations.get('command.' +
|
|
349
|
+
command.name +
|
|
350
|
+
'.args.' +
|
|
351
|
+
arg.name +
|
|
352
|
+
'.description', 'en'));
|
|
273
353
|
option.setRequired(!arg.optional);
|
|
274
354
|
if (arg.choices) {
|
|
275
355
|
// if arg.choices is function, call it
|
|
276
356
|
if (typeof arg.choices == 'function') {
|
|
277
|
-
arg.choices =
|
|
357
|
+
arg.choices =
|
|
358
|
+
arg.choices();
|
|
278
359
|
}
|
|
279
360
|
arg.choices.forEach((choice) => {
|
|
280
361
|
option.addChoices({
|
|
281
362
|
name: choice.name,
|
|
282
|
-
value: choice.value
|
|
363
|
+
value: choice.value,
|
|
283
364
|
});
|
|
284
365
|
});
|
|
285
366
|
}
|
|
@@ -294,7 +375,7 @@ export class ZumitoFramework {
|
|
|
294
375
|
}
|
|
295
376
|
}
|
|
296
377
|
function MergeRecursive(obj1, obj2) {
|
|
297
|
-
for (
|
|
378
|
+
for (const p in obj2) {
|
|
298
379
|
try {
|
|
299
380
|
// Property in destination object set; update its value.
|
|
300
381
|
if (obj2[p].constructor == Object) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import { EventParameters } from
|
|
3
|
-
import { FrameworkEvent } from
|
|
1
|
+
import { Command } from '../../../types/Command.js';
|
|
2
|
+
import { EventParameters } from '../../../types/EventParameters.js';
|
|
3
|
+
import { FrameworkEvent } from '../../../types/FrameworkEvent.js';
|
|
4
4
|
export declare class InteractionCreate extends FrameworkEvent {
|
|
5
5
|
once: boolean;
|
|
6
|
-
execute({ interaction, client, framework }: EventParameters): Promise<void>;
|
|
6
|
+
execute({ interaction, client, framework, }: EventParameters): Promise<void>;
|
|
7
7
|
getTransMethod(commandInstance: Command, framework: any, guildSettings: any): (key: string, params?: any) => any;
|
|
8
8
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CommandType } from
|
|
2
|
-
import { FrameworkEvent } from
|
|
1
|
+
import { CommandType } from '../../../types/CommandType.js';
|
|
2
|
+
import { FrameworkEvent } from '../../../types/FrameworkEvent.js';
|
|
3
3
|
export class InteractionCreate extends FrameworkEvent {
|
|
4
4
|
once = false;
|
|
5
|
-
async execute({ interaction, client, framework }) {
|
|
5
|
+
async execute({ interaction, client, framework, }) {
|
|
6
6
|
let guildSettings;
|
|
7
7
|
if (interaction.guildId) {
|
|
8
8
|
guildSettings = await framework.getGuildSettings(interaction.guildId);
|
|
@@ -11,46 +11,80 @@ export class InteractionCreate extends FrameworkEvent {
|
|
|
11
11
|
if (!framework.commands.has(interaction.commandName))
|
|
12
12
|
return;
|
|
13
13
|
const commandInstance = framework.commands.get(interaction.commandName);
|
|
14
|
-
|
|
15
|
-
commandInstance.args.forEach(arg => {
|
|
16
|
-
|
|
14
|
+
const args = new Map();
|
|
15
|
+
commandInstance.args.forEach((arg) => {
|
|
16
|
+
const option = interaction.options.get(arg.name);
|
|
17
17
|
if (option) {
|
|
18
18
|
switch (arg.type) {
|
|
19
|
-
case
|
|
19
|
+
case 'user':
|
|
20
20
|
args.set(arg.name, option.user);
|
|
21
21
|
break;
|
|
22
|
-
case
|
|
22
|
+
case 'member':
|
|
23
23
|
args.set(arg.name, option.member);
|
|
24
24
|
break;
|
|
25
25
|
default:
|
|
26
|
-
args.set(arg.name, option.value ||
|
|
26
|
+
args.set(arg.name, option.value ||
|
|
27
|
+
option.user ||
|
|
28
|
+
option.role ||
|
|
29
|
+
option.channel ||
|
|
30
|
+
option.options ||
|
|
31
|
+
option.message ||
|
|
32
|
+
option.member ||
|
|
33
|
+
option.focused ||
|
|
34
|
+
option.autocomplete ||
|
|
35
|
+
option.attachment);
|
|
27
36
|
break;
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
39
|
});
|
|
31
|
-
if (![
|
|
40
|
+
if (![
|
|
41
|
+
CommandType.any,
|
|
42
|
+
CommandType.separated,
|
|
43
|
+
CommandType.slash,
|
|
44
|
+
].includes(commandInstance.type))
|
|
32
45
|
return;
|
|
33
46
|
const trans = this.getTransMethod(commandInstance, guildSettings, framework);
|
|
34
|
-
if (commandInstance.type === CommandType.separated ||
|
|
35
|
-
|
|
47
|
+
if (commandInstance.type === CommandType.separated ||
|
|
48
|
+
commandInstance.type === CommandType.slash) {
|
|
49
|
+
await commandInstance.executeSlashCommand({
|
|
50
|
+
client,
|
|
51
|
+
interaction,
|
|
52
|
+
args,
|
|
53
|
+
framework,
|
|
54
|
+
guildSettings,
|
|
55
|
+
trans,
|
|
56
|
+
});
|
|
36
57
|
}
|
|
37
58
|
else {
|
|
38
|
-
await commandInstance.execute({
|
|
59
|
+
await commandInstance.execute({
|
|
60
|
+
client,
|
|
61
|
+
interaction,
|
|
62
|
+
args,
|
|
63
|
+
framework,
|
|
64
|
+
guildSettings,
|
|
65
|
+
trans,
|
|
66
|
+
});
|
|
39
67
|
}
|
|
40
68
|
}
|
|
41
69
|
else if (interaction.isButton()) {
|
|
42
70
|
interaction = interaction;
|
|
43
|
-
|
|
71
|
+
const path = interaction.customId.split('.');
|
|
44
72
|
const commandInstance = framework.commands.get(path[0]);
|
|
45
73
|
if (!commandInstance)
|
|
46
74
|
throw new Error(`Command ${path[0]} not found or button id bad formatted`);
|
|
47
75
|
// If the command has impements ButtonPress class then execute the method
|
|
48
76
|
if (commandInstance.constructor.prototype.hasOwnProperty('buttonPressed')) {
|
|
49
|
-
commandInstance.buttonPressed({
|
|
77
|
+
commandInstance.buttonPressed({
|
|
78
|
+
path,
|
|
79
|
+
interaction,
|
|
80
|
+
client,
|
|
81
|
+
framework,
|
|
82
|
+
guildSettings,
|
|
83
|
+
});
|
|
50
84
|
}
|
|
51
85
|
}
|
|
52
86
|
else if (interaction.isSelectMenu()) {
|
|
53
|
-
|
|
87
|
+
const path = interaction.customId.split('.');
|
|
54
88
|
const commandInstance = framework.commands.get(path[0]);
|
|
55
89
|
if (!commandInstance)
|
|
56
90
|
throw new Error(`Command ${path[0]} not found or select menu id bad formatted`);
|
|
@@ -63,7 +97,14 @@ export class InteractionCreate extends FrameworkEvent {
|
|
|
63
97
|
}
|
|
64
98
|
};
|
|
65
99
|
if (commandInstance.selectMenu) {
|
|
66
|
-
commandInstance.selectMenu({
|
|
100
|
+
commandInstance.selectMenu({
|
|
101
|
+
path,
|
|
102
|
+
interaction,
|
|
103
|
+
client,
|
|
104
|
+
framework,
|
|
105
|
+
guildSettings,
|
|
106
|
+
trans,
|
|
107
|
+
});
|
|
67
108
|
}
|
|
68
109
|
}
|
|
69
110
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ActionRowBuilder, EmbedBuilder } from
|
|
2
|
-
import { EventParameters } from
|
|
3
|
-
import { FrameworkEvent } from
|
|
1
|
+
import { ActionRowBuilder, EmbedBuilder } from 'discord.js';
|
|
2
|
+
import { EventParameters } from '../../../types/EventParameters.js';
|
|
3
|
+
import { FrameworkEvent } from '../../../types/FrameworkEvent.js';
|
|
4
4
|
export declare class MessageCreate extends FrameworkEvent {
|
|
5
5
|
once: boolean;
|
|
6
6
|
execute({ message, client, framework }: EventParameters): Promise<import("discord.js").Message<boolean>>;
|