zumito-framework 1.1.54 → 1.1.56

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 { Translation } from "./types/Translation.js";
1
+ import { Translation } from './types/Translation.js';
2
2
  export declare class TranslationManager {
3
3
  private translations;
4
4
  private defaultLanguage;
@@ -1,4 +1,4 @@
1
- import { Translation } from "./types/Translation.js";
1
+ import { Translation } from './types/Translation.js';
2
2
  export class TranslationManager {
3
3
  translations = new Map();
4
4
  defaultLanguage = 'en';
@@ -1,9 +1,9 @@
1
- import { GuildMember, TextChannel } 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";
1
+ import { GuildMember, TextChannel } 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.
@@ -1,23 +1,23 @@
1
- import { SlashCommandBuilder } from "discord.js";
2
- import { Module } from "./types/Module.js";
1
+ import { SlashCommandBuilder, } from 'discord.js';
2
+ import { Module } from './types/Module.js';
3
3
  import { ApiResponse } from './definitions/ApiResponse.js';
4
- import { baseModule } from "./baseModule/index.js";
5
- import { TranslationManager } from "./TranslationManager.js";
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";
9
+ import { Client } from 'discord.js';
10
10
  // import better-logging
11
- import { betterLogging } from "better-logging";
11
+ import { betterLogging } from 'better-logging';
12
12
  betterLogging(console);
13
13
  import { REST } from '@discordjs/rest';
14
14
  import { Routes } from 'discord-api-types/v9';
15
- import mongoose from "mongoose";
15
+ import mongoose from 'mongoose';
16
16
  import cookieParser from 'cookie-parser';
17
17
  import cors from 'cors';
18
18
  import http from 'http';
19
19
  import * as url from 'url';
20
- import { CommandType } from "./types/CommandType.js";
20
+ import { CommandType } from './types/CommandType.js';
21
21
  /**
22
22
  * @class ZumitoFramework
23
23
  * @classdesc The main class of the framework.
@@ -62,19 +62,22 @@ export class ZumitoFramework {
62
62
  if (settings.logLevel) {
63
63
  console.logLevel = settings.logLevel;
64
64
  }
65
- this.initialize().then(() => {
65
+ this.initialize()
66
+ .then(() => {
66
67
  if (callback)
67
68
  callback(this);
68
- }).catch(err => {
69
+ })
70
+ .catch((err) => {
69
71
  console.error(err, err.message, err.stack, err.name);
70
72
  });
71
73
  }
72
74
  async initialize() {
73
75
  try {
76
+ mongoose.set('strictQuery', true);
74
77
  await mongoose.connect(this.settings.mongoQueryString);
75
78
  }
76
79
  catch (err) {
77
- console.error("[🗄️🔴] Database connection error:", err.message);
80
+ console.error('[🗄️🔴] Database connection error:', err.message);
78
81
  process.exit(1);
79
82
  }
80
83
  finally {
@@ -88,9 +91,9 @@ export class ZumitoFramework {
88
91
  }
89
92
  startApiServer() {
90
93
  this.app = express();
91
- let port = process.env.PORT || '80';
94
+ const port = process.env.PORT || '80';
92
95
  this.app.set('port', port);
93
- var server = http.createServer(this.app);
96
+ const server = http.createServer(this.app);
94
97
  server.listen(port);
95
98
  server.on('error', (err) => {
96
99
  console.log('[🌐🔴] Error starting API web server: ' + err);
@@ -108,12 +111,12 @@ export class ZumitoFramework {
108
111
  //this.app.use("/", indexRouter);
109
112
  //this.app.use("/api/", apiRouter);
110
113
  // throw 404 if URL not found
111
- this.app.all("*", function (req, res) {
112
- return ApiResponse.notFoundResponse(res, "Page not found");
114
+ this.app.all('*', function (req, res) {
115
+ return ApiResponse.notFoundResponse(res, 'Page not found');
113
116
  });
114
117
  this.app.use(function (err, req, res) {
115
118
  if (err.name === 'UnauthorizedError') {
116
- return ApiResponse.unauthorizedResponse(res, "Invalid token");
119
+ return ApiResponse.unauthorizedResponse(res, 'Invalid token');
117
120
  }
118
121
  });
119
122
  }
@@ -129,8 +132,8 @@ export class ZumitoFramework {
129
132
  return;
130
133
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
131
134
  await this.registerModule(__dirname, 'baseModule', baseModule);
132
- let files = fs.readdirSync(modulesFolder);
133
- for (let file of files) {
135
+ const files = fs.readdirSync(modulesFolder);
136
+ for (const file of files) {
134
137
  await this.registerModule(modulesFolder, file);
135
138
  }
136
139
  this.models.forEach((modelDefinition, modelName) => {
@@ -141,17 +144,16 @@ export class ZumitoFramework {
141
144
  async registerModule(modulesFolder, moduleName, module) {
142
145
  if (!module) {
143
146
  if (fs.existsSync(path.join(modulesFolder, moduleName, 'index.js'))) {
144
- module = await import(path.join(modulesFolder, moduleName, 'index.js'));
147
+ module = await import('file://' + path.join(modulesFolder, moduleName, 'index.js'));
145
148
  module = Object.values(module)[0];
146
149
  }
147
150
  else if (fs.existsSync(path.join(modulesFolder, moduleName, 'index.ts'))) {
148
- module = await import(path.join(modulesFolder, moduleName, 'index.ts'));
151
+ module = await import('file://' + path.join(modulesFolder, moduleName, 'index.ts'));
149
152
  module = Object.values(module)[0];
150
153
  }
151
154
  else {
152
155
  module = Module;
153
156
  }
154
- ;
155
157
  }
156
158
  // Create module instance
157
159
  let moduleInstance;
@@ -170,7 +172,10 @@ export class ZumitoFramework {
170
172
  this.commands.set(command.name, command);
171
173
  });
172
174
  }
173
- this.commands = new Map([...this.commands, ...moduleInstance.getCommands()]);
175
+ this.commands = new Map([
176
+ ...this.commands,
177
+ ...moduleInstance.getCommands(),
178
+ ]);
174
179
  // Register module events
175
180
  this.events = new Map([...this.events, ...moduleInstance.getEvents()]);
176
181
  // Register models
@@ -191,7 +196,7 @@ export class ZumitoFramework {
191
196
  }
192
197
  initializeDiscordClient() {
193
198
  this.client = new Client({
194
- intents: this.settings.discordClientOptions.intents
199
+ intents: this.settings.discordClientOptions.intents,
195
200
  });
196
201
  this.client.login(this.settings.discordClientOptions.token);
197
202
  this.client.on('ready', () => {
@@ -203,7 +208,7 @@ export class ZumitoFramework {
203
208
  //log( 'commandLine', commandLine ) ;
204
209
  // Find a unique marker for the space character.
205
210
  // Start with '<SP>' and repeatedly append '@' if necessary to make it unique.
206
- var spaceMarker = '<SP>';
211
+ let spaceMarker = '<SP>';
207
212
  while (commandLine.indexOf(spaceMarker) > -1)
208
213
  spaceMarker += '@';
209
214
  // Protect double-quoted strings.
@@ -212,19 +217,19 @@ export class ZumitoFramework {
212
217
  // o Replace each double-quoted-string with what's inside the qouble-quotes,
213
218
  // after each space character has been replaced with the space-marker above.
214
219
  // o The outer double-quotes will not be present.
215
- var noSpacesInQuotes = commandLine.replace(/"([^"]*)"?/g, (fullMatch, capture) => {
220
+ const noSpacesInQuotes = commandLine.replace(/"([^"]*)"?/g, (fullMatch, capture) => {
216
221
  return capture.replace(/ /g, spaceMarker);
217
222
  });
218
223
  // Now that it is safe to do so, split the command-line at one-or-more spaces.
219
- var mangledParamArray = noSpacesInQuotes.split(/ +/);
224
+ const mangledParamArray = noSpacesInQuotes.split(/ +/);
220
225
  // Create a new array by restoring spaces from any space-markers.
221
- var paramArray = mangledParamArray.map((mangledParam) => {
226
+ const paramArray = mangledParamArray.map((mangledParam) => {
222
227
  return mangledParam.replace(RegExp(spaceMarker, 'g'), ' ');
223
228
  });
224
229
  return paramArray;
225
230
  }
226
231
  async memberHasPermission(member, channel, permission) {
227
- let memberPermission = await channel.permissionsFor(member);
232
+ const memberPermission = await channel.permissionsFor(member);
228
233
  return memberPermission.has(permission);
229
234
  }
230
235
  async getGuildSettings(guildId) {
@@ -240,10 +245,12 @@ export class ZumitoFramework {
240
245
  }
241
246
  async refreshSlashCommands() {
242
247
  const rest = new REST({ version: '10' }).setToken(this.settings.discordClientOptions.token);
243
- let commands = Array.from(this.commands.values())
244
- .filter((command) => command.type == CommandType.slash || command.type == CommandType.separated || command.type == CommandType.any)
248
+ const commands = Array.from(this.commands.values())
249
+ .filter((command) => command.type == CommandType.slash ||
250
+ command.type == CommandType.separated ||
251
+ command.type == CommandType.any)
245
252
  .map((command) => {
246
- let slashCommand = new SlashCommandBuilder()
253
+ const slashCommand = new SlashCommandBuilder()
247
254
  .setName(command.name)
248
255
  .setDescription(this.translations.get('command.' + command.name + '.description', 'en'));
249
256
  if (command.args) {
@@ -268,17 +275,22 @@ export class ZumitoFramework {
268
275
  }
269
276
  slashCommand[method]((option) => {
270
277
  option.setName(arg.name);
271
- option.setDescription(this.translations.get('command.' + command.name + '.args.' + arg.name + '.description', 'en'));
278
+ option.setDescription(this.translations.get('command.' +
279
+ command.name +
280
+ '.args.' +
281
+ arg.name +
282
+ '.description', 'en'));
272
283
  option.setRequired(!arg.optional);
273
284
  if (arg.choices) {
274
285
  // if arg.choices is function, call it
275
286
  if (typeof arg.choices == 'function') {
276
- arg.choices = arg.choices();
287
+ arg.choices =
288
+ arg.choices();
277
289
  }
278
290
  arg.choices.forEach((choice) => {
279
291
  option.addChoices({
280
292
  name: choice.name,
281
- value: choice.value
293
+ value: choice.value,
282
294
  });
283
295
  });
284
296
  }
@@ -293,7 +305,7 @@ export class ZumitoFramework {
293
305
  }
294
306
  }
295
307
  function MergeRecursive(obj1, obj2) {
296
- for (var p in obj2) {
308
+ for (const p in obj2) {
297
309
  try {
298
310
  // Property in destination object set; update its value.
299
311
  if (obj2[p].constructor == Object) {
@@ -1,8 +1,8 @@
1
- import { Command } from "../../../types/Command.js";
2
- import { EventParameters } from "../../../types/EventParameters.js";
3
- import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
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 "../../../types/CommandType.js";
2
- import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
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
- let args = new Map();
15
- commandInstance.args.forEach(arg => {
16
- let option = interaction.options.get(arg.name);
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 "user":
19
+ case 'user':
20
20
  args.set(arg.name, option.user);
21
21
  break;
22
- case "member":
22
+ case 'member':
23
23
  args.set(arg.name, option.member);
24
24
  break;
25
25
  default:
26
- args.set(arg.name, option.value || option.user || option.role || option.channel || option.options || option.message || option.member || option.focused || option.autocomplete || option.attachment);
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 (![CommandType.any, CommandType.separated, CommandType.slash].includes(commandInstance.type))
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 || commandInstance.type === CommandType.slash) {
35
- await commandInstance.executeSlashCommand({ client, interaction, args, framework, guildSettings, trans });
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({ client, interaction, args, framework, guildSettings, trans });
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
- let path = interaction.customId.split('.');
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({ path, interaction, client, framework, guildSettings });
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
- let path = interaction.customId.split('.');
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({ path, interaction, client, framework, guildSettings, trans });
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 "discord.js";
2
- import { EventParameters } from "../../../types/EventParameters.js";
3
- import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
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>>;