zumito-framework 1.1.30 → 1.1.33

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";
1
+ import { Translation } from "./types/Translation.js";
2
2
  export declare class TranslationManager {
3
3
  private translations;
4
4
  private defaultLanguage;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TranslationManager = void 0;
4
- const Translation_1 = require("./types/Translation");
5
- class TranslationManager {
1
+ import { Translation } from "./types/Translation.js";
2
+ export class TranslationManager {
6
3
  translations = new Map();
7
4
  defaultLanguage = 'en';
8
5
  constructor() { }
@@ -11,7 +8,7 @@ class TranslationManager {
11
8
  }
12
9
  set(key, language, text) {
13
10
  if (!this.translations.has(key)) {
14
- this.translations.set(key, new Translation_1.Translation());
11
+ this.translations.set(key, new Translation());
15
12
  }
16
13
  this.translations.get(key).set(language, text);
17
14
  }
@@ -31,4 +28,3 @@ class TranslationManager {
31
28
  this.defaultLanguage = language;
32
29
  }
33
30
  }
34
- exports.TranslationManager = TranslationManager;
@@ -1,9 +1,9 @@
1
1
  import { GuildMember, TextChannel } from "discord.js";
2
- import { Command } from "./types/Commands";
3
- import { FrameworkSettings } from "./types/FrameworkSettings";
4
- import { Module } from "./types/Module";
5
- import { FrameworkEvent } from "./types/FrameworkEvent";
6
- import { TranslationManager } from "./TranslationManager";
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,21 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZumitoFramework = void 0;
4
- const Module_1 = require("./types/Module");
5
- const ApiResponse_1 = require("./definitions/ApiResponse");
6
- const baseModule_1 = require("./baseModule");
7
- const TranslationManager_1 = require("./TranslationManager");
8
- const express = require("express");
9
- const fs = require('fs');
10
- const path = require('path');
11
- const { Collection, Client } = require('discord.js');
12
- require('better-logging')(console);
13
- const { REST } = require('@discordjs/rest');
14
- const { Routes } = require('discord-api-types/v9');
15
- var mongoose = require("mongoose");
16
- var cookieParser = require("cookie-parser");
17
- var cors = require("cors");
18
- var http = require('http');
1
+ import { Module } from "./types/Module.js";
2
+ import { ApiResponse } from './definitions/ApiResponse.js';
3
+ import { baseModule } from "./baseModule/index.js";
4
+ import { TranslationManager } from "./TranslationManager.js";
5
+ import express from 'express';
6
+ import * as fs from 'fs';
7
+ import path from 'path';
8
+ import { Client } from "discord.js";
9
+ // import better-logging
10
+ import { betterLogging } from "better-logging";
11
+ betterLogging(console);
12
+ import mongoose from "mongoose";
13
+ import cookieParser from 'cookie-parser';
14
+ import cors from 'cors';
15
+ import http from 'http';
19
16
  /**
20
17
  * @class ZumitoFramework
21
18
  * @classdesc The main class of the framework.
@@ -25,13 +22,13 @@ var http = require('http');
25
22
  * @property {Collection<string, Module>} modules - The modules loaded in the framework.
26
23
  * @property {Collection<string, Command>} commands - The commands loaded in the framework.
27
24
  */
28
- class ZumitoFramework {
25
+ export class ZumitoFramework {
29
26
  client;
30
27
  settings;
31
28
  modules;
32
29
  commands;
33
30
  events;
34
- translations = new TranslationManager_1.TranslationManager();
31
+ translations = new TranslationManager();
35
32
  routes;
36
33
  models;
37
34
  database;
@@ -55,24 +52,25 @@ class ZumitoFramework {
55
52
  this.modules = new Map();
56
53
  this.commands = new Map();
57
54
  this.events = new Map();
58
- this.translations = new TranslationManager_1.TranslationManager();
55
+ this.translations = new TranslationManager();
56
+ this.models = new Map();
59
57
  this.initialize().then(() => {
60
58
  if (callback)
61
59
  callback();
62
60
  }).catch(err => {
63
- console.error(err);
61
+ console.error(err, err.message, err.stack, err.name);
64
62
  });
65
63
  }
66
64
  async initialize() {
67
65
  try {
68
- await mongoose.connect(this.settings.mongoQueryString, { useNewUrlParser: true, useUnifiedTopology: true });
66
+ await mongoose.connect(this.settings.mongoQueryString);
69
67
  }
70
68
  catch (err) {
71
- console.error("[] Database connection error:", err.message);
69
+ console.error("[🗄️🔴] Database connection error:", err.message);
72
70
  process.exit(1);
73
71
  }
74
72
  finally {
75
- console.log('[] Database connection successful');
73
+ console.log('[🗄️🟢] Database connection successful');
76
74
  this.database = mongoose.connection;
77
75
  }
78
76
  this.initializeDiscordClient();
@@ -86,10 +84,10 @@ class ZumitoFramework {
86
84
  var server = http.createServer(this.app);
87
85
  server.listen(port);
88
86
  server.on('error', (err) => {
89
- console.log('[] Error starting API web server: ' + err);
87
+ console.log('[🌐🔴] Error starting API web server: ' + err);
90
88
  });
91
89
  server.on('listening', () => {
92
- console.log('[] API web server listening on port ' + port);
90
+ console.log('[🌐🟢] API web server listening on port ' + port);
93
91
  });
94
92
  this.app.use(express.json());
95
93
  this.app.use(express.urlencoded({ extended: false }));
@@ -102,11 +100,11 @@ class ZumitoFramework {
102
100
  //this.app.use("/api/", apiRouter);
103
101
  // throw 404 if URL not found
104
102
  this.app.all("*", function (req, res) {
105
- return ApiResponse_1.ApiResponse.notFoundResponse(res, "Page not found");
103
+ return ApiResponse.notFoundResponse(res, "Page not found");
106
104
  });
107
105
  this.app.use(function (err, req, res) {
108
106
  if (err.name === 'UnauthorizedError') {
109
- return ApiResponse_1.ApiResponse.unauthorizedResponse(res, "Invalid token");
107
+ return ApiResponse.unauthorizedResponse(res, "Invalid token");
110
108
  }
111
109
  });
112
110
  }
@@ -120,7 +118,7 @@ class ZumitoFramework {
120
118
  }
121
119
  else
122
120
  return;
123
- this.registerModule(__dirname, 'baseModule', baseModule_1.baseModule);
121
+ this.registerModule(path.resolve(), 'baseModule', baseModule);
124
122
  fs.readdirSync(modulesFolder).forEach(file => {
125
123
  this.registerModule(modulesFolder, file);
126
124
  });
@@ -129,24 +127,31 @@ class ZumitoFramework {
129
127
  this.models.set(modelName, mongoose.model(modelName, schema));
130
128
  });
131
129
  }
132
- registerModule(modulesFolder, moduleName, module) {
130
+ async registerModule(modulesFolder, moduleName, module) {
133
131
  if (!module) {
134
132
  if (fs.existsSync(path.join(modulesFolder, moduleName, 'index.js'))) {
135
- module = require(path.join(modulesFolder, moduleName, 'index.js'));
133
+ module = await import(path.join(modulesFolder, moduleName, 'index.js'));
136
134
  module = Object.values(module)[0];
137
135
  }
138
136
  else if (fs.existsSync(path.join(modulesFolder, moduleName, 'index.ts'))) {
139
- module = require(path.join(modulesFolder, moduleName, 'index.ts'));
137
+ module = await import(path.join(modulesFolder, moduleName, 'index.ts'));
140
138
  module = Object.values(module)[0];
141
139
  }
142
140
  else {
143
- module = Module_1.Module;
141
+ module = Module;
144
142
  }
145
143
  ;
146
144
  }
147
145
  // Create module instance
148
- let moduleInstance = new module(path.join(modulesFolder, moduleName), this);
149
- this.modules.set(moduleInstance.constructor.name, moduleInstance);
146
+ let moduleInstance;
147
+ try {
148
+ moduleInstance = new module(path.join(modulesFolder, moduleName), this);
149
+ await moduleInstance.initialize();
150
+ this.modules.set(moduleInstance.constructor.name, moduleInstance);
151
+ }
152
+ catch (err) {
153
+ console.error(`[📦🔴] Error loading module ${moduleName}: ${err.message}`);
154
+ }
150
155
  // Register module commands
151
156
  this.commands = new Map([...this.commands, ...moduleInstance.getCommands()]);
152
157
  // Register module events
@@ -172,6 +177,10 @@ class ZumitoFramework {
172
177
  intents: this.settings.discordClientOptions.intents
173
178
  });
174
179
  this.client.login(this.settings.discordClientOptions.token);
180
+ this.client.on('ready', () => {
181
+ // Bot emoji
182
+ console.log('[🤖🟢] Discord client ready');
183
+ });
175
184
  }
176
185
  static splitCommandLine(commandLine) {
177
186
  //log( 'commandLine', commandLine ) ;
@@ -202,7 +211,6 @@ class ZumitoFramework {
202
211
  return memberPermission.has(permission);
203
212
  }
204
213
  }
205
- exports.ZumitoFramework = ZumitoFramework;
206
214
  function MergeRecursive(obj1, obj2) {
207
215
  for (var p in obj2) {
208
216
  try {
@@ -1,5 +1,5 @@
1
- import { EventParameters } from "../../../types/EventParameters";
2
- import { FrameworkEvent } from "../../../types/FrameworkEvent";
1
+ import { EventParameters } from "../../../types/EventParameters.js";
2
+ import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
3
3
  export declare class InteractionCreate extends FrameworkEvent {
4
4
  once: boolean;
5
5
  execute({ interaction, client, framework }: EventParameters): Promise<void>;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InteractionCreate = void 0;
4
- const CommandType_1 = require("../../../types/CommandType");
5
- const FrameworkEvent_1 = require("../../../types/FrameworkEvent");
6
- class InteractionCreate extends FrameworkEvent_1.FrameworkEvent {
1
+ import { CommandType } from "../../../types/CommandType.js";
2
+ import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
3
+ export class InteractionCreate extends FrameworkEvent {
7
4
  once = false;
8
5
  async execute({ interaction, client, framework }) {
9
6
  if (interaction.isCommand()) {
@@ -17,9 +14,9 @@ class InteractionCreate extends FrameworkEvent_1.FrameworkEvent {
17
14
  args.set(arg.name, option.value || option.user || option.role || option.channel || option.options || option.message || option.member || option.focused || option.autocomplete || option.attachment);
18
15
  }
19
16
  });
20
- if (![CommandType_1.CommandType.any, CommandType_1.CommandType.separated, CommandType_1.CommandType.slash].includes(commandInstance.type))
17
+ if (![CommandType.any, CommandType.separated, CommandType.slash].includes(commandInstance.type))
21
18
  return;
22
- if (commandInstance.type === CommandType_1.CommandType.separated || commandInstance.type === CommandType_1.CommandType.slash) {
19
+ if (commandInstance.type === CommandType.separated || commandInstance.type === CommandType.slash) {
23
20
  await commandInstance.executeSlashCommand({ client, interaction, args, framework });
24
21
  }
25
22
  else {
@@ -37,4 +34,3 @@ class InteractionCreate extends FrameworkEvent_1.FrameworkEvent {
37
34
  }
38
35
  }
39
36
  }
40
- exports.InteractionCreate = InteractionCreate;
@@ -1,5 +1,5 @@
1
- import { EventParameters } from "../../../types/EventParameters";
2
- import { FrameworkEvent } from "../../../types/FrameworkEvent";
1
+ import { EventParameters } from "../../../types/EventParameters.js";
2
+ import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
3
3
  export declare class MessageCreate extends FrameworkEvent {
4
4
  once: boolean;
5
5
  execute({ message, client, framework }: EventParameters): Promise<import("discord.js").Message<boolean>>;
@@ -1,21 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageCreate = void 0;
4
- const discord_js_1 = require("discord.js");
5
- const FrameworkEvent_1 = require("../../../types/FrameworkEvent");
6
- const ZumitoFramework_1 = require("../../../ZumitoFramework");
7
- class MessageCreate extends FrameworkEvent_1.FrameworkEvent {
1
+ import { PermissionsBitField } from "discord.js";
2
+ import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
3
+ import { ZumitoFramework } from "../../../ZumitoFramework.js";
4
+ export class MessageCreate extends FrameworkEvent {
8
5
  once = false;
9
6
  async execute({ message, client, framework }) {
10
7
  let channel = message.channel;
11
8
  let prefix = framework.settings.defaultPrefix;
12
- const args = ZumitoFramework_1.ZumitoFramework.splitCommandLine(message.content.slice(prefix.length));
9
+ const args = ZumitoFramework.splitCommandLine(message.content.slice(prefix.length));
13
10
  const command = args.shift().toLowerCase();
14
11
  let commandInstance;
15
12
  if (message.content.startsWith(prefix)) {
16
13
  if (!framework.commands.has(command)) {
17
14
  let commandNames = Array.from(framework.commands.keys());
18
- var autocorrect = require('autocorrect')({ words: commandNames });
15
+ var autocorrect = await import('autocorrect');
16
+ autocorrect = autocorrect({ words: commandNames });
19
17
  var correctedCommand = autocorrect(command);
20
18
  if (framework.commands.has(correctedCommand)) {
21
19
  commandInstance = framework.commands.get(correctedCommand);
@@ -31,7 +29,7 @@ class MessageCreate extends FrameworkEvent_1.FrameworkEvent {
31
29
  return;
32
30
  if (commandInstance.adminOnly || commandInstance.permissions.length > 0) {
33
31
  let denied = false;
34
- if (framework.memberHasPermission(message.member, message.channel, discord_js_1.PermissionsBitField.Flags.Administrator) || message.member.id != message.guild.ownerId) {
32
+ if (framework.memberHasPermission(message.member, message.channel, PermissionsBitField.Flags.Administrator) || message.member.id != message.guild.ownerId) {
35
33
  if (commandInstance.permissions.length > 0) {
36
34
  commandInstance.permissions.forEach(permission => {
37
35
  if (!framework.memberHasPermission(message.member, message.channel, permission)) {
@@ -52,7 +50,7 @@ class MessageCreate extends FrameworkEvent_1.FrameworkEvent {
52
50
  if (message.channel.isTextBased) {
53
51
  let channel = message.channel;
54
52
  // Check command is nsfw and if channel is allowed
55
- if (commandInstance.nsfw && !channel.nsfw && !channel.permissionsFor(message.member).has(discord_js_1.PermissionsBitField.Flags.Administrator) && message.member.id != message.guild.ownerId) {
53
+ if (commandInstance.nsfw && !channel.nsfw && !channel.permissionsFor(message.member).has(PermissionsBitField.Flags.Administrator) && message.member.id != message.guild.ownerId) {
56
54
  return message.reply({
57
55
  content: 'This command is nsfw and this channel is not nsfw.',
58
56
  allowedMentions: {
@@ -104,4 +102,3 @@ class MessageCreate extends FrameworkEvent_1.FrameworkEvent {
104
102
  }
105
103
  }
106
104
  }
107
- exports.MessageCreate = MessageCreate;
@@ -1,6 +1,6 @@
1
- import { Module } from "../types/Module";
2
- import { ZumitoFramework } from "../ZumitoFramework";
1
+ import { Module } from "../types/Module.js";
2
+ import { ZumitoFramework } from "../ZumitoFramework.js";
3
3
  export declare class baseModule extends Module {
4
4
  constructor(modulePath: string, framework: ZumitoFramework);
5
- registerEvents(): void;
5
+ asyncregisterEvents(): any;
6
6
  }
@@ -1,19 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.baseModule = void 0;
4
- const Module_1 = require("../types/Module");
5
- const interactionCreate_1 = require("./events/discord/interactionCreate");
6
- const messageCreate_1 = require("./events/discord/messageCreate");
7
- class baseModule extends Module_1.Module {
1
+ import { Module } from "../types/Module.js";
2
+ import { InteractionCreate } from "./events/discord/interactionCreate.js";
3
+ import { MessageCreate } from "./events/discord/messageCreate.js";
4
+ export class baseModule extends Module {
8
5
  constructor(modulePath, framework) {
9
6
  super(modulePath, framework);
10
7
  }
11
- registerEvents() {
12
- this.events.set('interactionCreate', new interactionCreate_1.InteractionCreate());
13
- this.events.set('messageCreate', new messageCreate_1.MessageCreate());
8
+ asyncregisterEvents() {
9
+ this.events.set('interactionCreate', new InteractionCreate());
10
+ this.events.set('messageCreate', new MessageCreate());
14
11
  this.events.forEach(event => {
15
12
  this.registerDiscordEvent(event);
16
13
  });
17
14
  }
18
15
  }
19
- exports.baseModule = baseModule;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiResponse = void 0;
4
- class ApiResponse {
1
+ export class ApiResponse {
5
2
  static notFoundResponse(res, msg) {
6
3
  let data = {
7
4
  message: msg,
@@ -17,4 +14,3 @@ class ApiResponse {
17
14
  }
18
15
  ;
19
16
  }
20
- exports.ApiResponse = ApiResponse;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,11 @@
1
- export { ZumitoFramework } from './ZumitoFramework';
2
- export { FrameworkSettings } from './types/FrameworkSettings';
3
- export { Command } from './types/Commands';
4
- export { Module } from './types/Module';
5
- export { CommandParameters } from './types/CommandParameters';
6
- export { CommandArguments } from './types/CommandArguments';
1
+ import { ZumitoFramework } from './ZumitoFramework.js';
2
+ import { FrameworkSettings } from './types/FrameworkSettings.js';
3
+ import { Command } from './types/Command.js';
4
+ import { Module } from './types/Module.js';
5
+ import { CommandParameters } from './types/CommandParameters.js';
6
+ import { CommandArguments } from './types/CommandArguments.js';
7
+ import { FrameworkEvent } from './types/FrameworkEvent.js';
8
+ import { Translation } from './types/Translation.js';
9
+ import { TranslationManager } from './TranslationManager.js';
10
+ import { ApiResponse } from './definitions/ApiResponse.js';
11
+ export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse };
package/dist/index.js CHANGED
@@ -1,11 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandArguments = exports.Module = exports.Command = exports.ZumitoFramework = void 0;
4
- var ZumitoFramework_1 = require("./ZumitoFramework");
5
- Object.defineProperty(exports, "ZumitoFramework", { enumerable: true, get: function () { return ZumitoFramework_1.ZumitoFramework; } });
6
- var Commands_1 = require("./types/Commands");
7
- Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return Commands_1.Command; } });
8
- var Module_1 = require("./types/Module");
9
- Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return Module_1.Module; } });
10
- var CommandArguments_1 = require("./types/CommandArguments");
11
- Object.defineProperty(exports, "CommandArguments", { enumerable: true, get: function () { return CommandArguments_1.CommandArguments; } });
1
+ import { ZumitoFramework } from './ZumitoFramework.js';
2
+ import { Command } from './types/Command.js';
3
+ import { Module } from './types/Module.js';
4
+ import { CommandArguments } from './types/CommandArguments.js';
5
+ import { FrameworkEvent } from './types/FrameworkEvent.js';
6
+ import { Translation } from './types/Translation.js';
7
+ import { TranslationManager } from './TranslationManager.js';
8
+ import { ApiResponse } from './definitions/ApiResponse.js';
9
+ export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse };
@@ -0,0 +1,23 @@
1
+ import { CommandParameters } from "./CommandParameters.js";
2
+ import { SelectMenuParameters } from "./SelectMenuParameters.js";
3
+ export declare abstract class Command {
4
+ name: string;
5
+ categories: string[];
6
+ aliases?: string[];
7
+ examples?: string[];
8
+ permissions?: bigint[];
9
+ botPermissions?: string[];
10
+ hidden?: boolean;
11
+ adminOnly?: boolean;
12
+ nsfw?: boolean;
13
+ cooldown?: number;
14
+ slashCommand?: boolean;
15
+ dm: boolean;
16
+ args: CommandArgDefinition[];
17
+ type: string;
18
+ constructor();
19
+ abstract execute({ message, interaction, args, client, framework }: CommandParameters): void;
20
+ executePrefixCommand({ message, interaction, args, client, framework }: CommandParameters): void;
21
+ executeSlashCommand({ message, interaction, args, client, framework }: CommandParameters): void;
22
+ selectMenu({ path, interaction, client, framework }: SelectMenuParameters): void;
23
+ }
@@ -0,0 +1,26 @@
1
+ import { CommandType } from "./CommandType.js";
2
+ export class Command {
3
+ name = this.constructor.name.toLowerCase();
4
+ categories = [];
5
+ aliases = [];
6
+ examples = [];
7
+ permissions = [];
8
+ botPermissions = [];
9
+ hidden = false;
10
+ adminOnly = false;
11
+ nsfw = false;
12
+ cooldown = 0;
13
+ slashCommand = false;
14
+ dm = false;
15
+ args = [];
16
+ type = CommandType.prefix;
17
+ constructor() {
18
+ }
19
+ executePrefixCommand({ message, interaction, args, client, framework }) {
20
+ this.execute({ message, interaction, args, client, framework });
21
+ }
22
+ executeSlashCommand({ message, interaction, args, client, framework }) {
23
+ this.execute({ message, interaction, args, client, framework });
24
+ }
25
+ selectMenu({ path, interaction, client, framework }) { }
26
+ }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandArguments = void 0;
4
- class CommandArguments {
1
+ export class CommandArguments {
5
2
  args = {};
6
3
  constructor(args = {}) {
7
4
  this.args = args;
@@ -16,4 +13,3 @@ class CommandArguments {
16
13
  return new CommandArguments(interaction.options);
17
14
  }
18
15
  }
19
- exports.CommandArguments = CommandArguments;
@@ -1,5 +1,5 @@
1
1
  import { Client, Interaction, Message } from "discord.js";
2
- import { ZumitoFramework } from "../ZumitoFramework";
2
+ import { ZumitoFramework } from "../ZumitoFramework.js";
3
3
  /**
4
4
  * @class CommandParameters
5
5
  * @classdesc Parameters passed to a command execution.
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandType = void 0;
4
- exports.CommandType = {
1
+ export const CommandType = {
5
2
  prefix: 'prefix',
6
3
  slash: 'slash',
7
4
  separated: 'separated',
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Command = void 0;
4
- const CommandType_1 = require("./CommandType");
5
- class Command {
1
+ import { CommandType } from "./CommandType";
2
+ export class Command {
6
3
  name = this.constructor.name.toLowerCase();
7
4
  categories = [];
8
5
  aliases = [];
@@ -16,7 +13,7 @@ class Command {
16
13
  slashCommand = false;
17
14
  dm = false;
18
15
  args = [];
19
- type = CommandType_1.CommandType.prefix;
16
+ type = CommandType.prefix;
20
17
  constructor() {
21
18
  }
22
19
  executePrefixCommand({ message, interaction, args, client, framework }) {
@@ -27,4 +24,3 @@ class Command {
27
24
  }
28
25
  selectMenu({ path, interaction, client, framework }) { }
29
26
  }
30
- exports.Command = Command;
@@ -1,5 +1,5 @@
1
1
  import { Client, Interaction, Message } from "discord.js";
2
- import { ZumitoFramework } from "../ZumitoFramework";
2
+ import { ZumitoFramework } from "../ZumitoFramework.js";
3
3
  export interface EventParameters {
4
4
  message?: Message;
5
5
  interaction?: Interaction;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FrameworkEvent = void 0;
4
- class FrameworkEvent {
1
+ export class FrameworkEvent {
5
2
  once = false;
6
3
  disabled = false;
7
4
  }
8
- exports.FrameworkEvent = FrameworkEvent;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,6 +1,6 @@
1
- import { ZumitoFramework } from "../ZumitoFramework";
2
- import { Command } from "./Commands";
3
- import { FrameworkEvent } from "./FrameworkEvent";
1
+ import { ZumitoFramework } from "../ZumitoFramework.js";
2
+ import { Command } from "./Command.js";
3
+ import { FrameworkEvent } from "./FrameworkEvent.js";
4
4
  export declare abstract class Module {
5
5
  protected path: string;
6
6
  protected framework: ZumitoFramework;
@@ -8,14 +8,18 @@ export declare abstract class Module {
8
8
  protected events: Map<string, FrameworkEvent>;
9
9
  protected models: Map<string, any>;
10
10
  constructor(path: any, framework: any);
11
- registerCommands(): void;
11
+ initialize(): Promise<void>;
12
+ registerCommands(): Promise<void>;
13
+ onCommandCreated(filePath: string): void;
14
+ onCommandChanged(filePath: string): void;
15
+ onErrorLoadingCommand(error: Error): void;
12
16
  getCommands(): Map<string, Command>;
13
- registerEvents(): void;
17
+ registerEvents(): Promise<void>;
14
18
  registerDiscordEvent(frameworkEvent: FrameworkEvent): void;
15
19
  parseEventArgs(args: any[]): any;
16
20
  getEvents(): Map<string, FrameworkEvent>;
17
- registerTranslations(): void;
21
+ registerTranslations(): Promise<void>;
18
22
  parseTranslation(path: string, lang: string, json: any): any;
19
- registerModels(): void;
23
+ registerModels(): Promise<void>;
20
24
  getModels(): Map<string, any>;
21
25
  }
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Module = void 0;
4
- const mongoose = require("mongoose");
5
- const fs = require('fs');
6
- const path = require('path');
7
- class Module {
1
+ import * as chokidar from 'chokidar';
2
+ import boxen from "boxen";
3
+ import * as fs from 'fs';
4
+ import path from 'path';
5
+ export class Module {
8
6
  path;
9
7
  framework;
10
8
  commands = new Map();
@@ -13,41 +11,72 @@ class Module {
13
11
  constructor(path, framework) {
14
12
  this.path = path;
15
13
  this.framework = framework;
16
- this.registerCommands();
17
- this.registerEvents();
18
- this.registerTranslations();
19
14
  }
20
- registerCommands() {
15
+ async initialize() {
16
+ await this.registerCommands();
17
+ await this.registerEvents();
18
+ await this.registerTranslations();
19
+ }
20
+ async registerCommands() {
21
21
  if (!fs.existsSync(path.join(this.path, 'commands')))
22
22
  return;
23
- fs.readdirSync(path.join(this.path, 'commands')).forEach(file => {
23
+ let files = fs.readdirSync(path.join(this.path, 'commands'));
24
+ for (let file of files) {
24
25
  if (file.endsWith('.js') || file.endsWith('.ts')) {
25
- let command = require(`${this.path}/commands/${file}`);
26
+ let command = await import('file://' + path.join(this.path, 'commands', file));
26
27
  command = Object.values(command)[0];
27
28
  command = new command();
28
29
  this.commands.set(command.constructor.name.toLowerCase(), command);
29
30
  }
30
- });
31
+ }
32
+ ;
33
+ // register watcher
34
+ if (process.env.DEBUG) {
35
+ chokidar.watch(path.resolve(path.join(this.path, 'commands')), { ignored: /^\./, persistent: true, ignoreInitial: true })
36
+ .on('add', this.onCommandCreated.bind(this))
37
+ .on('change', this.onCommandChanged.bind(this))
38
+ //.on('unlink', function(path) {console.log('File', path, 'has been removed');})
39
+ .on('error', this.onErrorLoadingCommand.bind(this));
40
+ }
41
+ }
42
+ onCommandCreated(filePath) {
43
+ console.log(filePath);
44
+ // GRreen dot emoji
45
+ // try {
46
+ // delete require.cache[path.resolve(path.join(this.path, 'commands', path))];
47
+ // console.debug('[🔄🟢 ] Command ' + chalk.blue(path.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' reloaded');
48
+ // } catch(e) {
49
+ // console.error('[🔄🔴 ] Error reloading command ' + chalk.blue(path.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
50
+ // console.log(boxen(e + '\n' + e.stack, { padding: 1 }));
51
+ // }
52
+ }
53
+ onCommandChanged(filePath) {
54
+ }
55
+ onErrorLoadingCommand(error) {
56
+ console.error('[🔄🔴 ] Error reloading command');
57
+ console.log(boxen(error + '\n' + error.stack, { padding: 1 }));
31
58
  }
32
59
  getCommands() {
33
60
  return this.commands;
34
61
  }
35
- registerEvents() {
62
+ async registerEvents() {
36
63
  if (!fs.existsSync(path.join(this.path, 'events')))
37
64
  return;
38
- fs.readdirSync(path.join(this.path, 'events')).forEach(file => {
65
+ let files = fs.readdirSync(path.join(this.path, 'events'));
66
+ for (let file of files) {
39
67
  if (file == 'discord') {
40
- fs.readdirSync(path.join(this.path, 'events', 'discord')).forEach(moduleFileName => {
68
+ let moduleFileNames = fs.readdirSync(path.join(this.path, 'events', 'discord'));
69
+ for (let moduleFileName of moduleFileNames) {
41
70
  if (moduleFileName.endsWith('.js') || moduleFileName.endsWith('.ts')) {
42
- let event = require(path.join(this.path, 'events', 'discord', moduleFileName));
71
+ let event = await import('file://' + path.join(this.path, 'events', 'discord', moduleFileName));
43
72
  event = Object.values(event)[0];
44
73
  event = new event();
45
74
  this.events.set(event.constructor.name.toLowerCase(), event);
46
75
  this.registerDiscordEvent(event);
47
76
  }
48
- });
77
+ }
49
78
  }
50
- });
79
+ }
51
80
  }
52
81
  registerDiscordEvent(frameworkEvent) {
53
82
  if (frameworkEvent.disabled)
@@ -60,6 +89,7 @@ class Module {
60
89
  emitter[once ? 'once' : 'on'](eventName, (...args) => frameworkEvent.execute(this.parseEventArgs(args))); // Run the event using the above defined emitter (client)
61
90
  }
62
91
  catch (error) {
92
+ console.log(error, error.message, error, name);
63
93
  console.error(error.stack); // If there is an error, console log the error stack message
64
94
  }
65
95
  }
@@ -76,16 +106,25 @@ class Module {
76
106
  getEvents() {
77
107
  return this.events;
78
108
  }
79
- registerTranslations() {
109
+ async registerTranslations() {
80
110
  if (!fs.existsSync(path.join(this.path, 'translations')))
81
111
  return;
82
- fs.readdirSync(path.join(this.path, 'translations')).forEach(file => {
112
+ let files = fs.readdirSync(path.join(this.path, 'translations'));
113
+ for (let file of files) {
83
114
  if (file.endsWith('.json')) {
84
- let json = require(`${this.path}/translations/${file}`);
115
+ console.log('load ' + file);
116
+ let json = await import('file://' + `${this.path}/translations/${file}`, {
117
+ assert: {
118
+ type: "json",
119
+ },
120
+ }).catch(e => {
121
+ console.error(`[🔄🔴 ] Error loading ${file.slice(0, -5)} translations on module ${this.constructor.name}`);
122
+ console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
123
+ });
85
124
  let lang = file.slice(0, -5);
86
125
  this.parseTranslation('', lang, json);
87
126
  }
88
- });
127
+ }
89
128
  }
90
129
  parseTranslation(path, lang, json) {
91
130
  if (typeof json === 'object') {
@@ -94,22 +133,30 @@ class Module {
94
133
  }
95
134
  }
96
135
  else {
97
- this.framework.translations.set(path, lang, json);
136
+ this.framework.translations.set(path.slice(0, -1), lang, json);
98
137
  }
99
138
  }
100
- registerModels() {
139
+ async registerModels() {
101
140
  if (!fs.existsSync(path.join(this.path, 'models')))
102
141
  return;
103
- fs.readdirSync(path.join(this.path, 'models')).forEach(file => {
142
+ let files = fs.readdirSync(path.join(this.path, 'models'));
143
+ for (let file of files) {
104
144
  if (file.endsWith('.json')) {
105
145
  let modelName = file.slice(0, -5).charAt(0).toUpperCase() + file.slice(0, -5).slice(1);
106
- let modelDefiniton = require(`${this.path}/models/${file}`);
146
+ console.log('load ' + file);
147
+ let modelDefiniton = await import('file://' + `${this.path}/models/${file}`, {
148
+ assert: {
149
+ type: "json",
150
+ },
151
+ }).catch(e => {
152
+ console.error(`[🔄🔴 ] Error loading model ${modelName} on module ${this.constructor.name}`);
153
+ console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
154
+ });
107
155
  this.models.set(modelName, modelDefiniton);
108
156
  }
109
- });
157
+ }
110
158
  }
111
159
  getModels() {
112
160
  return this.models;
113
161
  }
114
162
  }
115
- exports.Module = Module;
@@ -1,5 +1,5 @@
1
1
  import { Client, Interaction } from "discord.js";
2
- import { ZumitoFramework } from "../ZumitoFramework";
2
+ import { ZumitoFramework } from "../ZumitoFramework.js";
3
3
  export interface SelectMenuParameters {
4
4
  path: string[];
5
5
  interaction: Interaction;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Translation = void 0;
4
- class Translation {
1
+ export class Translation {
5
2
  text = new Map();
6
3
  constructor() { }
7
4
  get(language, params) {
@@ -32,4 +29,3 @@ class Translation {
32
29
  this.text = text;
33
30
  }
34
31
  }
35
- exports.Translation = Translation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.1.30",
3
+ "version": "1.1.33",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,13 @@
23
23
  "license": "ISC",
24
24
  "dependencies": {
25
25
  "@types/express": "^4.17.13",
26
+ "autocorrect": "^1.2.0",
26
27
  "better-logging": "^5.0.0",
28
+ "boxen": "^7.0.0",
29
+ "chalk": "^4.1.2",
30
+ "chokidar": "^3.5.3",
31
+ "cookie-parser": "^1.4.6",
32
+ "cors": "^2.8.5",
27
33
  "discord.js": "^14.2.0",
28
34
  "express": "^4.18.1",
29
35
  "mongoose": "^6.5.2",
@@ -31,7 +37,9 @@
31
37
  "zumito-framework": "^1.1.16"
32
38
  },
33
39
  "devDependencies": {
40
+ "@types/node": "^18.7.16",
34
41
  "typedoc": "^0.23.10",
35
42
  "typescript": "^4.7.4"
36
- }
43
+ },
44
+ "type": "module"
37
45
  }