zumito-framework 1.1.56 → 1.1.58
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GuildMember, TextChannel } from 'discord.js';
|
|
1
|
+
import { GuildMember, TextChannel, Client } from 'discord.js';
|
|
2
2
|
import { Command } from './types/Command.js';
|
|
3
3
|
import { FrameworkSettings } from './types/FrameworkSettings.js';
|
|
4
4
|
import { Module } from './types/Module.js';
|
|
@@ -8,13 +8,18 @@ import { TranslationManager } from './TranslationManager.js';
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { SlashCommandBuilder, } from 'discord.js';
|
|
1
|
+
import { SlashCommandBuilder, Client, } from 'discord.js';
|
|
2
2
|
import { Module } from './types/Module.js';
|
|
3
3
|
import { ApiResponse } from './definitions/ApiResponse.js';
|
|
4
4
|
import { baseModule } from './baseModule/index.js';
|
|
@@ -6,7 +6,6 @@ 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
10
|
import { betterLogging } from 'better-logging';
|
|
12
11
|
betterLogging(console);
|
|
@@ -22,10 +21,15 @@ import { CommandType } from './types/CommandType.js';
|
|
|
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;
|
|
@@ -71,6 +66,14 @@ export class ZumitoFramework {
|
|
|
71
66
|
console.error(err, err.message, err.stack, err.name);
|
|
72
67
|
});
|
|
73
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
|
+
*/
|
|
74
77
|
async initialize() {
|
|
75
78
|
try {
|
|
76
79
|
mongoose.set('strictQuery', true);
|
|
@@ -89,6 +92,10 @@ export class ZumitoFramework {
|
|
|
89
92
|
await this.registerModules();
|
|
90
93
|
await this.refreshSlashCommands();
|
|
91
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Initializes and starts the API server using ExpressJS.
|
|
97
|
+
* Sets up middleware, routes, and error handling for the server.
|
|
98
|
+
*/
|
|
92
99
|
startApiServer() {
|
|
93
100
|
this.app = express();
|
|
94
101
|
const port = process.env.PORT || '80';
|
|
@@ -120,6 +127,13 @@ export class ZumitoFramework {
|
|
|
120
127
|
}
|
|
121
128
|
});
|
|
122
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
|
+
*/
|
|
123
137
|
async registerModules() {
|
|
124
138
|
let modulesFolder;
|
|
125
139
|
if (fs.existsSync(`${process.cwd()}/modules`)) {
|
|
@@ -194,6 +208,11 @@ export class ZumitoFramework {
|
|
|
194
208
|
|
|
195
209
|
*/
|
|
196
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
|
+
*/
|
|
197
216
|
initializeDiscordClient() {
|
|
198
217
|
this.client = new Client({
|
|
199
218
|
intents: this.settings.discordClientOptions.intents,
|
|
@@ -204,6 +223,19 @@ export class ZumitoFramework {
|
|
|
204
223
|
console.log('[🤖🟢] Discord client ready');
|
|
205
224
|
});
|
|
206
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
|
+
*/
|
|
207
239
|
static splitCommandLine(commandLine) {
|
|
208
240
|
//log( 'commandLine', commandLine ) ;
|
|
209
241
|
// Find a unique marker for the space character.
|
|
@@ -228,10 +260,48 @@ export class ZumitoFramework {
|
|
|
228
260
|
});
|
|
229
261
|
return paramArray;
|
|
230
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
|
+
*/
|
|
231
278
|
async memberHasPermission(member, channel, permission) {
|
|
232
279
|
const memberPermission = await channel.permissionsFor(member);
|
|
233
280
|
return memberPermission.has(permission);
|
|
234
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
|
+
*/
|
|
235
305
|
async getGuildSettings(guildId) {
|
|
236
306
|
const Guild = this.models.get('Guild');
|
|
237
307
|
let guild = await Guild.findOne({ guild_id: guildId }).exec();
|
|
@@ -115,7 +115,8 @@ export class MessageCreate extends FrameworkEvent {
|
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
117
|
});
|
|
118
|
-
if (!message.channel.isDMBased && !message.deletable
|
|
118
|
+
if (!message.channel.isDMBased && !message.deletable) {
|
|
119
|
+
return; // TODO: test if this works
|
|
119
120
|
// false = settings.deleteCommands
|
|
120
121
|
try {
|
|
121
122
|
message.delete().catch(function () {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<br />
|
|
15
15
|
<div align="center">
|
|
16
16
|
<a href="https://github.com/ZumitoTeam/zumito-framework">
|
|
17
|
-
<img src="https://media.discordapp.net/attachments/964297459327184906/1066399583896342649/d05ce5c0de25fd9afb4f5492f31f21fe.png" alt="Logo" width="80" height="80"
|
|
17
|
+
<img src="https://media.discordapp.net/attachments/964297459327184906/1066399583896342649/d05ce5c0de25fd9afb4f5492f31f21fe.png" alt="Logo" width="80" height="80"/>
|
|
18
18
|
</a>
|
|
19
19
|
|
|
20
20
|
<h3 align="center">Zumito framework</h3>
|