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.
@@ -1,9 +1,9 @@
1
1
  import * as chokidar from 'chokidar';
2
2
  import chalk from 'chalk';
3
- import boxen from "boxen";
3
+ import boxen from 'boxen';
4
4
  import * as fs from 'fs';
5
5
  import path from 'path';
6
- import { ButtonInteraction, CommandInteraction, SelectMenuInteraction } from "discord.js";
6
+ import { ButtonInteraction, CommandInteraction, SelectMenuInteraction, } from 'discord.js';
7
7
  export class Module {
8
8
  path;
9
9
  framework;
@@ -24,10 +24,10 @@ export class Module {
24
24
  }
25
25
  async registerCommands() {
26
26
  if (fs.existsSync(path.join(this.path, 'commands'))) {
27
- let files = fs.readdirSync(path.join(this.path, 'commands'));
28
- for (let file of files) {
27
+ const files = fs.readdirSync(path.join(this.path, 'commands'));
28
+ for (const file of files) {
29
29
  if (file.endsWith('.js') || file.endsWith('.ts')) {
30
- let command = await import('file://' + path.join(this.path, 'commands', file)).catch(e => {
30
+ let command = await import('file://' + path.join(this.path, 'commands', file)).catch((e) => {
31
31
  console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} command on module ${this.constructor.name}`);
32
32
  console.error(e + '\n' + e.name + '\n' + e.stack);
33
33
  });
@@ -36,7 +36,6 @@ export class Module {
36
36
  this.commands.set(command.constructor.name.toLowerCase(), command);
37
37
  }
38
38
  }
39
- ;
40
39
  // register watcher
41
40
  if (process.env.DEBUG) {
42
41
  /*
@@ -44,7 +43,12 @@ export class Module {
44
43
  Appart from that, esm module cache invalidation is not working properly
45
44
  and can cause memory leaks and crashes.
46
45
  */
47
- chokidar.watch(path.resolve(path.join(this.path, 'commands')), { ignored: /^\./, persistent: true, ignoreInitial: true })
46
+ chokidar
47
+ .watch(path.resolve(path.join(this.path, 'commands')), {
48
+ ignored: /^\./,
49
+ persistent: true,
50
+ ignoreInitial: true,
51
+ })
48
52
  .on('add', this.onCommandCreated.bind(this))
49
53
  .on('change', this.onCommandChanged.bind(this))
50
54
  //.on('unlink', function(path) {console.log('File', path, 'has been removed');})
@@ -54,26 +58,48 @@ export class Module {
54
58
  }
55
59
  async onCommandCreated(filePath) {
56
60
  if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
57
- let command = await import('file://' + filePath).catch(e => {
58
- console.error('[🆕🔴 ] Error loading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
61
+ let command = await import('file://' + filePath).catch((e) => {
62
+ console.error('[🆕🔴 ] Error loading command ' +
63
+ chalk.blue(filePath
64
+ .replace(/^.*[\\\/]/, '')
65
+ .split('.')
66
+ .slice(0, -1)
67
+ .join('.')));
59
68
  console.log(e + '\n' + e.name + '\n' + e.stack);
60
69
  });
61
70
  command = Object.values(command)[0];
62
71
  command = new command();
63
72
  this.commands.set(command.constructor.name.toLowerCase(), command);
64
- console.debug('[🆕🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' loaded');
73
+ console.debug('[🆕🟢 ] Command ' +
74
+ chalk.blue(filePath
75
+ .replace(/^.*[\\\/]/, '')
76
+ .split('.')
77
+ .slice(0, -1)
78
+ .join('.')) +
79
+ ' loaded');
65
80
  }
66
81
  }
67
82
  async onCommandChanged(filePath) {
68
83
  if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
69
- let command = await import('file://' + filePath + '?update=' + Date.now().toString()).catch(e => {
70
- console.error('[🔄🔴 ] Error reloading command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')));
84
+ let command = await import('file://' + filePath + '?update=' + Date.now().toString()).catch((e) => {
85
+ console.error('[🔄🔴 ] Error reloading command ' +
86
+ chalk.blue(filePath
87
+ .replace(/^.*[\\\/]/, '')
88
+ .split('.')
89
+ .slice(0, -1)
90
+ .join('.')));
71
91
  console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
72
92
  });
73
93
  command = Object.values(command)[0];
74
94
  command = new command();
75
95
  this.commands.set(command.constructor.name.toLowerCase(), command);
76
- console.debug('[🔄🟢 ] Command ' + chalk.blue(filePath.replace(/^.*[\\\/]/, '').split('.').slice(0, -1).join('.')) + ' reloaded');
96
+ console.debug('[🔄🟢 ] Command ' +
97
+ chalk.blue(filePath
98
+ .replace(/^.*[\\\/]/, '')
99
+ .split('.')
100
+ .slice(0, -1)
101
+ .join('.')) +
102
+ ' reloaded');
77
103
  }
78
104
  }
79
105
  onErrorLoadingCommand(error) {
@@ -86,15 +112,19 @@ export class Module {
86
112
  async registerEvents() {
87
113
  if (!fs.existsSync(path.join(this.path, 'events')))
88
114
  return;
89
- let files = fs.readdirSync(path.join(this.path, 'events'));
90
- for (let file of files) {
115
+ const files = fs.readdirSync(path.join(this.path, 'events'));
116
+ for (const file of files) {
91
117
  if (file == 'discord') {
92
- let moduleFileNames = fs.readdirSync(path.join(this.path, 'events', 'discord'));
93
- for (let moduleFileName of moduleFileNames) {
94
- if (moduleFileName.endsWith('.js') || moduleFileName.endsWith('.ts')) {
95
- let event = await import('file://' + path.join(this.path, 'events', 'discord', moduleFileName)).catch(e => {
118
+ const moduleFileNames = fs.readdirSync(path.join(this.path, 'events', 'discord'));
119
+ for (const moduleFileName of moduleFileNames) {
120
+ if (moduleFileName.endsWith('.js') ||
121
+ moduleFileName.endsWith('.ts')) {
122
+ let event = await import('file://' +
123
+ path.join(this.path, 'events', 'discord', moduleFileName)).catch((e) => {
96
124
  console.error(`[🔄🔴 ] Error loading ${moduleFileName.slice(0, -3)} event on module ${this.constructor.name}`);
97
- console.log(boxen(e + '\n' + e.name + '\n' + e.stack, { padding: 1 }));
125
+ console.log(boxen(e + '\n' + e.name + '\n' + e.stack, {
126
+ padding: 1,
127
+ }));
98
128
  });
99
129
  event = Object.values(event)[0];
100
130
  event = new event();
@@ -108,7 +138,8 @@ export class Module {
108
138
  registerDiscordEvent(frameworkEvent) {
109
139
  if (frameworkEvent.disabled)
110
140
  return;
111
- const eventName = frameworkEvent.constructor.name.charAt(0).toLowerCase() + frameworkEvent.constructor.name.slice(1);
141
+ const eventName = frameworkEvent.constructor.name.charAt(0).toLowerCase() +
142
+ frameworkEvent.constructor.name.slice(1);
112
143
  const emitter = this.framework.client;
113
144
  const once = frameworkEvent.once; // A simple variable which returns if the event should run once
114
145
  // Try catch block to throw an error if the code in try{} doesn't work
@@ -121,14 +152,16 @@ export class Module {
121
152
  }
122
153
  }
123
154
  parseEventArgs(args) {
124
- let finalArgs = {
155
+ const finalArgs = {
125
156
  framework: this.framework,
126
157
  client: this.framework.client,
127
158
  };
128
- args.forEach(arg => {
159
+ args.forEach((arg) => {
129
160
  finalArgs[arg.constructor.name.toLowerCase()] = arg;
130
161
  });
131
- let interaction = args.find((arg) => arg instanceof SelectMenuInteraction || arg instanceof CommandInteraction || arg instanceof ButtonInteraction);
162
+ const interaction = args.find((arg) => arg instanceof SelectMenuInteraction ||
163
+ arg instanceof CommandInteraction ||
164
+ arg instanceof ButtonInteraction);
132
165
  if (interaction) {
133
166
  finalArgs['interaction'] = interaction;
134
167
  }
@@ -140,15 +173,19 @@ export class Module {
140
173
  async registerTranslations(subpath = '') {
141
174
  if (!fs.existsSync(path.join(this.path, 'translations', subpath)))
142
175
  return;
143
- let files = fs.readdirSync(path.join(this.path, 'translations', subpath));
144
- for (let file of files) {
176
+ const files = fs.readdirSync(path.join(this.path, 'translations', subpath));
177
+ for (const file of files) {
145
178
  if (file.endsWith('.json')) {
146
- let json = await this.loadTranslationFile(subpath, file);
147
- let lang = file.slice(0, -5);
148
- let baseKey = subpath ? subpath.replaceAll('/', '.').replaceAll('\\', '.') + '.' : '';
179
+ const json = await this.loadTranslationFile(subpath, file);
180
+ const lang = file.slice(0, -5);
181
+ const baseKey = subpath
182
+ ? subpath.replaceAll('/', '.').replaceAll('\\', '.') + '.'
183
+ : '';
149
184
  this.parseTranslation(baseKey, lang, json);
150
185
  }
151
- else if (fs.lstatSync(path.join(this.path, 'translations', subpath, file)).isDirectory()) {
186
+ else if (fs
187
+ .lstatSync(path.join(this.path, 'translations', subpath, file))
188
+ .isDirectory()) {
152
189
  await this.registerTranslations(path.join(subpath, file));
153
190
  }
154
191
  }
@@ -156,11 +193,11 @@ export class Module {
156
193
  async loadTranslationFile(subpath, file) {
157
194
  if (subpath)
158
195
  subpath = subpath + '/';
159
- let json = await import('file://' + `${this.path}/translations/${subpath}${file}`, {
196
+ const json = await import('file://' + `${this.path}/translations/${subpath}${file}`, {
160
197
  assert: {
161
- type: "json",
198
+ type: 'json',
162
199
  },
163
- }).catch(e => {
200
+ }).catch((e) => {
164
201
  console.error(`[🔄🔴 ] Error loading ${file.slice(0, -5)} translations on module ${this.constructor.name}`);
165
202
  console.error(e + '\n' + e.name + '\n' + e.stack);
166
203
  });
@@ -168,7 +205,7 @@ export class Module {
168
205
  }
169
206
  parseTranslation(path, lang, json) {
170
207
  if (typeof json === 'object') {
171
- for (let key in json) {
208
+ for (const key in json) {
172
209
  this.parseTranslation(path + key + '.', lang, json[key]);
173
210
  }
174
211
  }
@@ -179,15 +216,16 @@ export class Module {
179
216
  async registerModels() {
180
217
  if (!fs.existsSync(path.join(this.path, 'models')))
181
218
  return;
182
- let files = fs.readdirSync(path.join(this.path, 'models'));
183
- for (let file of files) {
219
+ const files = fs.readdirSync(path.join(this.path, 'models'));
220
+ for (const file of files) {
184
221
  if (file.endsWith('.json')) {
185
- let modelName = file.slice(0, -5).charAt(0).toUpperCase() + file.slice(0, -5).slice(1);
186
- let modelDefiniton = await import('file://' + `${this.path}/models/${file}`, {
222
+ const modelName = file.slice(0, -5).charAt(0).toUpperCase() +
223
+ file.slice(0, -5).slice(1);
224
+ const modelDefiniton = await import('file://' + `${this.path}/models/${file}`, {
187
225
  assert: {
188
- type: "json",
226
+ type: 'json',
189
227
  },
190
- }).catch(e => {
228
+ }).catch((e) => {
191
229
  console.error(`[🔄🔴 ] Error loading model ${modelName} on module ${this.constructor.name}`);
192
230
  console.error(e, e.name, e.stack);
193
231
  });
@@ -1,5 +1,5 @@
1
- import { Client, SelectMenuInteraction } from "discord.js";
2
- import { ZumitoFramework } from "../ZumitoFramework.js";
1
+ import { Client, SelectMenuInteraction } from 'discord.js';
2
+ import { ZumitoFramework } from '../ZumitoFramework.js';
3
3
  export interface SelectMenuParameters {
4
4
  path: string[];
5
5
  interaction: SelectMenuInteraction;
@@ -10,7 +10,7 @@ export class Translation {
10
10
  text = this.text.get('en');
11
11
  }
12
12
  if (params) {
13
- Object.keys(params).forEach(key => {
13
+ Object.keys(params).forEach((key) => {
14
14
  text = text.replace(`{${key}}`, params[key]);
15
15
  });
16
16
  }
@@ -1,4 +1,4 @@
1
- import { Client } from "discord.js";
1
+ import { Client } from 'discord.js';
2
2
  export declare class EmojiFallback {
3
3
  static getEmoji(client: Client, emojiId: string, fallbackEmoji: any): any;
4
4
  static getEmojiByName(client: Client, emojiName: string, fallbackEmoji: any): any;
@@ -4,11 +4,11 @@ export class EmojiFallback {
4
4
  return emoji?.toString() || fallbackEmoji;
5
5
  }
6
6
  static getEmojiByName(client, emojiName, fallbackEmoji) {
7
- const emoji = client.emojis.cache.find(emoji => emoji.name === emojiName);
7
+ const emoji = client.emojis.cache.find((emoji) => emoji.name === emojiName);
8
8
  return emoji?.toString() || fallbackEmoji;
9
9
  }
10
10
  static getEmojiByIdentifier(client, emojiId, fallbackEmoji) {
11
- const emoji = client.emojis.cache.find(emoji => emoji.id === emojiId);
11
+ const emoji = client.emojis.cache.find((emoji) => emoji.id === emojiId);
12
12
  return emoji?.toString() || fallbackEmoji;
13
13
  }
14
14
  }
package/package.json CHANGED
@@ -1,18 +1,13 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.1.55",
3
+ "version": "1.1.57",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "/dist",
9
- "/plopfile.js",
10
- "/baseModule",
11
- "/plop-templates"
9
+ "/baseModule"
12
10
  ],
13
- "bin": {
14
- "generate": "./templateGenerator.mjs"
15
- },
16
11
  "scripts": {
17
12
  "test": "echo \"Error: no test specified\" && exit 1",
18
13
  "build": "tsc",
@@ -35,8 +30,7 @@
35
30
  "error-stack-parser": "^2.1.4",
36
31
  "express": "^4.18.1",
37
32
  "leven": "^4.0.0",
38
- "mongoose": "^6.6.5",
39
- "plop": "^3.1.1"
33
+ "mongoose": "^6.6.5"
40
34
  },
41
35
  "devDependencies": {
42
36
  "@types/node": "^18.7.16",
@@ -1,17 +0,0 @@
1
- import { Command, CommandParameters } from "zumito-framework";
2
-
3
- export class {{capitalize command}} extends Command {
4
-
5
- execute({ message, interaction, args, client, framework, guildSettings }: CommandParameters): void {
6
- (message || interaction!).reply({
7
- content: "Message content",
8
- });
9
- }
10
-
11
- async selectMenu({ path, interaction, client, framework }: SelectMenuParameters): Promise<void> {
12
- await interaction.deferUpdate();
13
- await interaction.editReply({
14
- content: "Select menu content",
15
- });
16
- }
17
- }
@@ -1,8 +0,0 @@
1
- {
2
- "command": {
3
-
4
- },
5
- "global": {
6
-
7
- }
8
- }
package/plopfile.js DELETED
@@ -1,116 +0,0 @@
1
- module.exports = function (plop) {
2
- plop.setHelper('capitalize', function (text) {
3
- return text.charAt(0).toUpperCase() + text.slice(1);
4
- });
5
- // create your generators here
6
- plop.setGenerator('command', {
7
- description: 'this is a skeleton command file',
8
- prompts: [
9
- {
10
- type: 'input',
11
- name: 'module',
12
- message: 'Name of the module',
13
- },
14
- {
15
- type: 'input',
16
- name: 'command',
17
- message: 'Name of the command',
18
- },
19
- ],
20
- actions: [
21
- {
22
- type: 'add',
23
- path: 'src/modules/{{module}}/commands/{{command}}.js',
24
- templateFile: 'plop-templates/command.js.hbs',
25
- },
26
- ],
27
- });
28
- plop.setGenerator('translation', {
29
- description: 'This generate translation file for a module',
30
- prompts: [
31
- {
32
- type: 'input',
33
- name: 'module',
34
- message: 'Name of the module',
35
- },
36
- {
37
- type: 'choice',
38
- name: 'language',
39
- message: 'Language of the translations',
40
- choices: [
41
- {
42
- name: 'English',
43
- value: 'en',
44
- },
45
- {
46
- name: 'Spanish',
47
- value: 'es',
48
- },
49
- {
50
- name: 'French',
51
- value: 'fr',
52
- },
53
- {
54
- name: 'German',
55
- value: 'de',
56
- },
57
- {
58
- name: 'Italian',
59
- value: 'it',
60
- },
61
- {
62
- name: 'Portuguese',
63
- value: 'pt',
64
- },
65
- {
66
- name: 'Russian',
67
- value: 'ru',
68
- },
69
- {
70
- name: 'Turkish',
71
- value: 'tr',
72
- },
73
- {
74
- name: 'Chinese',
75
- value: 'zh',
76
- },
77
- {
78
- name: 'Japanese',
79
- value: 'ja',
80
- },
81
- {
82
- name: 'Korean',
83
- value: 'ko',
84
- },
85
- {
86
- name: 'Polish',
87
- value: 'pl',
88
- },
89
- {
90
- name: 'Romanian',
91
- value: 'ro',
92
- },
93
- {
94
- name: 'Russian',
95
- value: 'ru',
96
- },
97
- {
98
- name: 'Ukrainian',
99
- value: 'uk',
100
- },
101
- {
102
- name: 'Vietnamese',
103
- value: 'vi',
104
- },
105
- ],
106
- },
107
- ],
108
- actions: [
109
- {
110
- type: 'add',
111
- path: 'src/modules/{{module}}/translations/{{language}}.json',
112
- templateFile: 'plop-templates/translation.json.hbs',
113
- },
114
- ],
115
- });
116
- };
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node --experimental-modules --no-warnings
2
- import path from "node:path";
3
- import minimist from "minimist";
4
- import { Plop, run } from "plop";
5
-
6
- const args = process.argv.slice(2);
7
- const argv = minimist(args);
8
-
9
- import { dirname } from "node:path";
10
- import { fileURLToPath } from "node:url";
11
-
12
- const __dirname = dirname(fileURLToPath(import.meta.url));
13
-
14
- Plop.prepare({
15
- cwd: process.cwd(),
16
- configPath: path.join(__dirname, 'plopfile.js'),
17
- preload: argv.preload || [],
18
- completion: argv.completion,
19
- dest: process.cwd()
20
- }, env => Plop.execute(env, (env) => {
21
- const options = {
22
- ...env,
23
- dest: process.cwd() // this will make the destination path to be based on the cwd when calling the wrapper
24
- }
25
- return run(options, undefined, true)
26
- }));