zumito-framework 1.1.71 → 1.1.72-dev-update-pull-request-ci.0

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.
Files changed (76) hide show
  1. package/dist/ZumitoFramework.d.ts +20 -12
  2. package/dist/ZumitoFramework.js +36 -61
  3. package/dist/{types → definitions}/Module.d.ts +6 -8
  4. package/dist/definitions/Module.js +129 -0
  5. package/dist/{types → definitions}/Translation.d.ts +0 -1
  6. package/dist/{types → definitions}/Translation.js +0 -1
  7. package/dist/{types → definitions/commands}/Command.d.ts +1 -1
  8. package/dist/{types → definitions/commands}/CommandParameters.d.ts +1 -1
  9. package/dist/{types → definitions/parameters}/EventParameters.d.ts +1 -1
  10. package/dist/{types/Commands → definitions/parameters}/SelectMenu.d.ts +1 -1
  11. package/dist/{types → definitions/parameters}/SelectMenuParameters.d.ts +1 -1
  12. package/dist/index.d.ts +21 -21
  13. package/dist/index.js +13 -13
  14. package/dist/{baseModule/events/discord/interactionCreate.d.ts → modules/core/baseModule/events/discord/InteractionCreate.d.ts} +3 -3
  15. package/dist/{baseModule/events/discord/interactionCreate.js → modules/core/baseModule/events/discord/InteractionCreate.js} +28 -21
  16. package/dist/{baseModule/events/discord/messageCreate.d.ts → modules/core/baseModule/events/discord/MessageCreate.d.ts} +3 -3
  17. package/dist/{baseModule/events/discord/messageCreate.js → modules/core/baseModule/events/discord/MessageCreate.js} +8 -10
  18. package/dist/{baseModule → modules/core/baseModule}/models/Guild.d.ts +1 -1
  19. package/dist/{baseModule → modules/core/baseModule}/models/Guild.js +1 -1
  20. package/dist/services/CommandManager.d.ts +40 -0
  21. package/dist/services/CommandManager.js +160 -0
  22. package/dist/services/EventManager.d.ts +8 -0
  23. package/dist/services/EventManager.js +27 -0
  24. package/dist/services/InteractionIdGenerator.d.ts +13 -0
  25. package/dist/services/InteractionIdGenerator.js +40 -0
  26. package/dist/services/ModuleManager.d.ts +17 -0
  27. package/dist/services/ModuleManager.js +78 -0
  28. package/dist/{managers → services}/StatusManager.d.ts +1 -1
  29. package/dist/services/TranslationManager.d.ts +34 -0
  30. package/dist/services/TranslationManager.js +122 -0
  31. package/package.json +9 -4
  32. package/dist/TranslationManager.d.ts +0 -15
  33. package/dist/TranslationManager.js +0 -41
  34. package/dist/baseModule/BaseModule.d.ts +0 -6
  35. package/dist/baseModule/BaseModule.js +0 -16
  36. package/dist/baseModule/index.d.ts +0 -7
  37. package/dist/baseModule/index.js +0 -19
  38. package/dist/types/Commands.d.ts +0 -23
  39. package/dist/types/Commands.js +0 -26
  40. package/dist/types/Module.js +0 -211
  41. /package/dist/{types → definitions}/DatabaseModel.d.ts +0 -0
  42. /package/dist/{types → definitions}/DatabaseModel.js +0 -0
  43. /package/dist/{types → definitions}/FrameworkEvent.d.ts +0 -0
  44. /package/dist/{types → definitions}/FrameworkEvent.js +0 -0
  45. /package/dist/{types → definitions}/FrameworkSettings.d.ts +0 -0
  46. /package/dist/{types → definitions}/FrameworkSettings.js +0 -0
  47. /package/dist/{types → definitions}/StatusManagerOptions.d.ts +0 -0
  48. /package/dist/{types → definitions}/StatusManagerOptions.js +0 -0
  49. /package/dist/definitions/{ApiResponse.d.ts → api/ApiResponse.d.ts} +0 -0
  50. /package/dist/definitions/{ApiResponse.js → api/ApiResponse.js} +0 -0
  51. /package/dist/{types → definitions/commands}/Command.js +0 -0
  52. /package/dist/{types → definitions/commands}/CommandArgDefinition.d.ts +0 -0
  53. /package/dist/{types → definitions/commands}/CommandArgDefinition.js +0 -0
  54. /package/dist/{types → definitions/commands}/CommandArguments.d.ts +0 -0
  55. /package/dist/{types → definitions/commands}/CommandArguments.js +0 -0
  56. /package/dist/{types → definitions/commands}/CommandChoiceDefinition.d.ts +0 -0
  57. /package/dist/{types → definitions/commands}/CommandChoiceDefinition.js +0 -0
  58. /package/dist/{types → definitions/commands}/CommandParameters.js +0 -0
  59. /package/dist/{types → definitions/commands}/CommandType.d.ts +0 -0
  60. /package/dist/{types → definitions/commands}/CommandType.js +0 -0
  61. /package/dist/{types/Commands → definitions/parameters}/ButtonPressed.d.ts +0 -0
  62. /package/dist/{types/Commands → definitions/parameters}/ButtonPressed.js +0 -0
  63. /package/dist/{types/Commands → definitions/parameters}/ButtonPressedParams.d.ts +0 -0
  64. /package/dist/{types/Commands → definitions/parameters}/ButtonPressedParams.js +0 -0
  65. /package/dist/{types → definitions/parameters}/EventParameters.js +0 -0
  66. /package/dist/{types/Commands → definitions/parameters}/SelectMenu.js +0 -0
  67. /package/dist/{types → definitions/parameters}/SelectMenuParameters.js +0 -0
  68. /package/dist/{utils → services}/DatabaseConfigLoader.d.ts +0 -0
  69. /package/dist/{utils → services}/DatabaseConfigLoader.js +0 -0
  70. /package/dist/{utils → services}/EmojiFallback.d.ts +0 -0
  71. /package/dist/{utils → services}/EmojiFallback.js +0 -0
  72. /package/dist/{managers → services}/EmojiManager.d.ts +0 -0
  73. /package/dist/{managers → services}/EmojiManager.js +0 -0
  74. /package/dist/{managers → services}/StatusManager.js +0 -0
  75. /package/dist/{utils → services}/TextFormatter.d.ts +0 -0
  76. /package/dist/{utils → services}/TextFormatter.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.1.71",
3
+ "version": "1.1.72-dev-update-pull-request-ci.0",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "publish-npm": "npm publish",
17
17
  "docs": "typedoc --out docs src"
18
18
  },
19
- "author": "fernandomema",
19
+ "author": "ZumitoTeam",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
22
  "@discordjs/rest": "^1.7.0",
@@ -42,6 +42,7 @@
42
42
  "@typescript-eslint/parser": "^5.48.2",
43
43
  "eslint": "^8.32.0",
44
44
  "eslint-config-prettier": "^8.6.0",
45
+ "eslint-plugin-check-file": "^2.2.0",
45
46
  "eslint-plugin-prettier": "^4.2.1",
46
47
  "prettier": "^2.8.3",
47
48
  "typedoc": "^0.23.14",
@@ -54,8 +55,12 @@
54
55
  },
55
56
  "typesVersions": {
56
57
  "*": {
57
- ".": ["dist/index.d.ts"],
58
- "discord": ["dist/discord/index.d.ts"]
58
+ ".": [
59
+ "dist/index.d.ts"
60
+ ],
61
+ "discord": [
62
+ "dist/discord/index.d.ts"
63
+ ]
59
64
  }
60
65
  },
61
66
  "repository": {
@@ -1,15 +0,0 @@
1
- import { Translation } from './types/Translation.js';
2
- export declare class TranslationManager {
3
- private translations;
4
- private defaultLanguage;
5
- private languages;
6
- constructor();
7
- get(key: string, language?: string, params?: any): string;
8
- set(key: string, language: string, text: string): void;
9
- has(key: string): boolean;
10
- getAll(): Map<string, Translation>;
11
- setAll(translations: Map<string, Translation>): void;
12
- getDefaultLanguage(): string;
13
- setDefaultLanguage(language: string): void;
14
- getLanguages(): string[];
15
- }
@@ -1,41 +0,0 @@
1
- import { Translation } from './types/Translation.js';
2
- export class TranslationManager {
3
- translations = new Map();
4
- defaultLanguage = 'en';
5
- languages = [];
6
- constructor() { }
7
- get(key, language, params) {
8
- if (this.translations.has(key)) {
9
- return this.translations.get(key).get(language, params);
10
- }
11
- else {
12
- return key;
13
- }
14
- }
15
- set(key, language, text) {
16
- if (!this.translations.has(key)) {
17
- this.translations.set(key, new Translation());
18
- }
19
- this.translations.get(key).set(language, text);
20
- if (!this.languages.includes(language))
21
- this.languages.push(language);
22
- }
23
- has(key) {
24
- return this.translations.has(key);
25
- }
26
- getAll() {
27
- return this.translations;
28
- }
29
- setAll(translations) {
30
- this.translations = translations;
31
- }
32
- getDefaultLanguage() {
33
- return this.defaultLanguage;
34
- }
35
- setDefaultLanguage(language) {
36
- this.defaultLanguage = language;
37
- }
38
- getLanguages() {
39
- return this.languages;
40
- }
41
- }
@@ -1,6 +0,0 @@
1
- import { Module } from "../types/Module";
2
- import { ZumitoFramework } from "../ZumitoFramework";
3
- export declare class baseModule extends Module {
4
- constructor(modulePath: string, framework: ZumitoFramework);
5
- registerEvents(): void;
6
- }
@@ -1,16 +0,0 @@
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 {
8
- constructor(modulePath, framework) {
9
- super(modulePath, framework);
10
- }
11
- registerEvents() {
12
- this.events.set('interactionCreate', new interactionCreate_1.InteractionCreate());
13
- this.events.set('messageCreate', new messageCreate_1.MessageCreate());
14
- }
15
- }
16
- exports.baseModule = baseModule;
@@ -1,7 +0,0 @@
1
- import { Module } from '../types/Module.js';
2
- import { ZumitoFramework } from '../ZumitoFramework.js';
3
- export declare class baseModule extends Module {
4
- constructor(modulePath: string, framework: ZumitoFramework);
5
- registerEvents(): Promise<any>;
6
- registerModels(): Promise<void>;
7
- }
@@ -1,19 +0,0 @@
1
- import { Module } from '../types/Module.js';
2
- import { InteractionCreate } from './events/discord/interactionCreate.js';
3
- import { MessageCreate } from './events/discord/messageCreate.js';
4
- import { Guild } from './models/Guild.js';
5
- export class baseModule extends Module {
6
- constructor(modulePath, framework) {
7
- super(modulePath, framework);
8
- }
9
- async registerEvents() {
10
- this.events.set('interactionCreate', new InteractionCreate());
11
- this.events.set('messageCreate', new MessageCreate());
12
- this.events.forEach((event) => {
13
- this.registerDiscordEvent(event);
14
- });
15
- }
16
- async registerModels() {
17
- this.models.push(new Guild(this.framework));
18
- }
19
- }
@@ -1,23 +0,0 @@
1
- import { CommandParameters } from "./CommandParameters";
2
- import { SelectMenuParameters } from "./SelectMenuParameters";
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
- }
@@ -1,26 +0,0 @@
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,211 +0,0 @@
1
- import * as chokidar from 'chokidar';
2
- import chalk from 'chalk';
3
- import boxen from 'boxen';
4
- import * as fs from 'fs';
5
- import path from 'path';
6
- import { ButtonInteraction, CommandInteraction, StringSelectMenuInteraction, } from 'discord.js';
7
- export class Module {
8
- path;
9
- framework;
10
- commands = new Map();
11
- events = new Map();
12
- models = [];
13
- constructor(path, framework) {
14
- this.path = path;
15
- this.framework = framework;
16
- }
17
- async initialize() {
18
- await this.registerCommands();
19
- await this.registerEvents();
20
- await this.registerTranslations();
21
- await this.registerModels();
22
- }
23
- async registerCommands() {
24
- if (fs.existsSync(path.join(this.path, 'commands'))) {
25
- const files = fs.readdirSync(path.join(this.path, 'commands'));
26
- for (const file of files) {
27
- if (file.endsWith('.js') || file.endsWith('.ts')) {
28
- let command = await import('file://' + path.join(this.path, 'commands', file)).catch((e) => {
29
- console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} command on module ${this.constructor.name}`);
30
- console.error(e + '\n' + e.name + '\n' + e.stack);
31
- });
32
- command = Object.values(command)[0];
33
- command = new command();
34
- this.commands.set(command.constructor.name.toLowerCase(), command);
35
- }
36
- }
37
- // register watcher
38
- if (process.env.DEBUG) {
39
- /*
40
- Debug only cause in prod environment commands should't be changed.
41
- Appart from that, esm module cache invalidation is not working properly
42
- and can cause memory leaks and crashes.
43
- */
44
- chokidar
45
- .watch(path.resolve(path.join(this.path, 'commands')), {
46
- ignored: /^\./,
47
- persistent: true,
48
- ignoreInitial: true,
49
- })
50
- .on('add', this.onCommandCreated.bind(this))
51
- .on('change', this.onCommandChanged.bind(this))
52
- //.on('unlink', function(path) {console.log('File', path, 'has been removed');})
53
- .on('error', this.onErrorLoadingCommand.bind(this));
54
- }
55
- }
56
- }
57
- async onCommandCreated(filePath) {
58
- if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
59
- let command = await import('file://' + filePath).catch(e => {
60
- console.error('[🆕🔴 ] Error loading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
61
- console.log(e + '\n' + e.name + '\n' + e.stack);
62
- });
63
- command = Object.values(command)[0];
64
- command = new command();
65
- this.framework.commands.set(command.constructor.name.toLowerCase(), command);
66
- console.debug('[🆕🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' loaded');
67
- }
68
- }
69
- async onCommandChanged(filePath) {
70
- if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
71
- let command = await import('file://' + filePath + '?update=' + Date.now().toString()).catch(e => {
72
- console.error('[🔄🔴 ] Error reloading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
73
- console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
74
- });
75
- command = Object.values(command)[0];
76
- command = new command();
77
- this.framework.commands.set(command.constructor.name.toLowerCase(), command);
78
- console.debug('[🔄🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' reloaded');
79
- }
80
- }
81
- onErrorLoadingCommand(error) {
82
- console.error('[🔄🔴 ] Error reloading command');
83
- console.log(boxen(error + '\n' + error.stack, { padding: 1 }));
84
- }
85
- getCommands() {
86
- return this.commands;
87
- }
88
- async registerEvents() {
89
- if (!fs.existsSync(path.join(this.path, 'events')))
90
- return;
91
- const files = fs.readdirSync(path.join(this.path, 'events'));
92
- for (const file of files) {
93
- if (file == 'discord') {
94
- const moduleFileNames = fs.readdirSync(path.join(this.path, 'events', 'discord'));
95
- for (const moduleFileName of moduleFileNames) {
96
- if (moduleFileName.endsWith('.js') ||
97
- moduleFileName.endsWith('.ts')) {
98
- let event = await import('file://' +
99
- path.join(this.path, 'events', 'discord', moduleFileName)).catch((e) => {
100
- console.error(`[🔄🔴 ] Error loading ${moduleFileName.slice(0, -3)} event on module ${this.constructor.name}`);
101
- console.log(boxen(e + '\n' + e.name + '\n' + e.stack, {
102
- padding: 1,
103
- }));
104
- });
105
- event = Object.values(event)[0];
106
- event = new event();
107
- this.events.set(event.constructor.name.toLowerCase(), event);
108
- this.registerDiscordEvent(event);
109
- }
110
- }
111
- }
112
- }
113
- }
114
- registerDiscordEvent(frameworkEvent) {
115
- if (frameworkEvent.disabled)
116
- return;
117
- const eventName = frameworkEvent.constructor.name.charAt(0).toLowerCase() +
118
- frameworkEvent.constructor.name.slice(1);
119
- const emitter = this.framework.client;
120
- const once = frameworkEvent.once; // A simple variable which returns if the event should run once
121
- // Try catch block to throw an error if the code in try{} doesn't work
122
- try {
123
- emitter[once ? 'once' : 'on'](eventName, (...args) => frameworkEvent.execute(this.parseEventArgs(args))); // Run the event using the above defined emitter (client)
124
- }
125
- catch (error) {
126
- console.log(error, error.message, error, name);
127
- console.error(error.stack); // If there is an error, console log the error stack message
128
- }
129
- }
130
- parseEventArgs(args) {
131
- const finalArgs = {
132
- framework: this.framework,
133
- client: this.framework.client,
134
- };
135
- args.forEach((arg) => {
136
- finalArgs[arg.constructor.name.toLowerCase()] = arg;
137
- });
138
- const interaction = args.find((arg) => arg instanceof StringSelectMenuInteraction ||
139
- arg instanceof CommandInteraction ||
140
- arg instanceof ButtonInteraction);
141
- if (interaction) {
142
- finalArgs['interaction'] = interaction;
143
- }
144
- return finalArgs;
145
- }
146
- getEvents() {
147
- return this.events;
148
- }
149
- async registerTranslations(subpath = '') {
150
- if (!fs.existsSync(path.join(this.path, 'translations', subpath)))
151
- return;
152
- const files = fs.readdirSync(path.join(this.path, 'translations', subpath));
153
- for (const file of files) {
154
- if (file.endsWith('.json')) {
155
- const json = await this.loadTranslationFile(subpath, file);
156
- const lang = file.slice(0, -5);
157
- const baseKey = subpath
158
- ? subpath.replaceAll('/', '.').replaceAll('\\', '.') + '.'
159
- : '';
160
- this.parseTranslation(baseKey, lang, json);
161
- }
162
- else if (fs
163
- .lstatSync(path.join(this.path, 'translations', subpath, file))
164
- .isDirectory()) {
165
- await this.registerTranslations(path.join(subpath, file));
166
- }
167
- }
168
- }
169
- async loadTranslationFile(subpath, file) {
170
- if (subpath)
171
- subpath = subpath + '/';
172
- const json = await import('file://' + `${this.path}/translations/${subpath}${file}`, {
173
- assert: {
174
- type: 'json',
175
- },
176
- }).catch((e) => {
177
- console.error(`[🔄🔴 ] Error loading ${file.slice(0, -5)} translations on module ${this.constructor.name}`);
178
- console.error(e + '\n' + e.name + '\n' + e.stack);
179
- });
180
- return json.default;
181
- }
182
- parseTranslation(path, lang, json) {
183
- if (typeof json === 'object') {
184
- for (const key in json) {
185
- this.parseTranslation(path + key + '.', lang, json[key]);
186
- }
187
- }
188
- else {
189
- this.framework.translations.set(path.slice(0, -1), lang, json);
190
- }
191
- }
192
- async registerModels() {
193
- if (!fs.existsSync(path.join(this.path, 'models')))
194
- return;
195
- const files = fs.readdirSync(path.join(this.path, 'models'));
196
- for (const file of files) {
197
- if (file.endsWith('.ts') || file.endsWith('.js')) {
198
- let model = await import('file://' + `${this.path}/models/${file}`).catch((e) => {
199
- console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} model on module ${this.constructor.name}`);
200
- console.error(e + '\n' + e.name + '\n' + e.stack);
201
- });
202
- model = Object.values(model)[0];
203
- model = new model();
204
- this.models.push(model);
205
- }
206
- }
207
- }
208
- getModels() {
209
- return this.models;
210
- }
211
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes