zumito-framework 1.1.47 → 1.1.49

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.
@@ -30,11 +30,19 @@ export class InteractionCreate extends FrameworkEvent {
30
30
  });
31
31
  if (![CommandType.any, CommandType.separated, CommandType.slash].includes(commandInstance.type))
32
32
  return;
33
+ const trans = (key, params) => {
34
+ if (key.startsWith('$')) {
35
+ return framework.translations.get(key.replace('$', ''), guildSettings.lang, params);
36
+ }
37
+ else {
38
+ return framework.translations.get('command.' + commandInstance.name + '.' + key, guildSettings.lang, params);
39
+ }
40
+ };
33
41
  if (commandInstance.type === CommandType.separated || commandInstance.type === CommandType.slash) {
34
- await commandInstance.executeSlashCommand({ client, interaction, args, framework, guildSettings });
42
+ await commandInstance.executeSlashCommand({ client, interaction, args, framework, guildSettings, trans });
35
43
  }
36
44
  else {
37
- await commandInstance.execute({ client, interaction, args, framework, guildSettings });
45
+ await commandInstance.execute({ client, interaction, args, framework, guildSettings, trans });
38
46
  }
39
47
  }
40
48
  else if (interaction.isButton()) {
@@ -42,6 +50,8 @@ export class InteractionCreate extends FrameworkEvent {
42
50
  else if (interaction.isSelectMenu()) {
43
51
  let path = interaction.customId.split('.');
44
52
  const command = framework.commands.get(path[0]);
53
+ if (!command)
54
+ throw new Error(`Command ${path[0]} not found or select menu id bad formatted`);
45
55
  if (command.selectMenu) {
46
56
  command.selectMenu({ path, interaction, client, framework, guildSettings });
47
57
  }
@@ -1,9 +1,9 @@
1
+ import * as url from 'url';
1
2
  import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, PermissionsBitField } from "discord.js";
3
+ import ErrorStackParser from 'error-stack-parser';
2
4
  import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
3
5
  import { ZumitoFramework } from "../../../ZumitoFramework.js";
4
6
  import leven from 'leven';
5
- import ErrorStackParser from 'error-stack-parser';
6
- import * as url from 'url';
7
7
  import path from "path";
8
8
  export class MessageCreate extends FrameworkEvent {
9
9
  once = false;
@@ -99,6 +99,14 @@ export class MessageCreate extends FrameworkEvent {
99
99
  client: framework.client,
100
100
  framework: framework,
101
101
  guildSettings: guildSettings,
102
+ trans: (key, params) => {
103
+ if (key.startsWith('$')) {
104
+ return framework.translations.get(key.replace('$', ''), guildSettings.lang, params);
105
+ }
106
+ else {
107
+ return framework.translations.get('command.' + commandInstance.name + '.' + key, guildSettings.lang, params);
108
+ }
109
+ }
102
110
  });
103
111
  if (!message.channel.isDMBased && !message.deletable && (false)) { // false = settings.deleteCommands
104
112
  try {
@@ -18,7 +18,7 @@ export declare abstract class Command {
18
18
  type: string;
19
19
  constructor();
20
20
  abstract execute({ message, interaction, args, client, framework }: CommandParameters): void;
21
- executePrefixCommand({ message, interaction, args, client, framework }: CommandParameters): void;
22
- executeSlashCommand({ message, interaction, args, client, framework }: CommandParameters): void;
21
+ executePrefixCommand({ message, interaction, args, client, framework, trans }: CommandParameters): void;
22
+ executeSlashCommand({ message, interaction, args, client, framework, trans }: CommandParameters): void;
23
23
  abstract selectMenu({ path, interaction, client, framework }: SelectMenuParameters): void;
24
24
  }
@@ -16,10 +16,10 @@ export class Command {
16
16
  type = CommandType.prefix;
17
17
  constructor() {
18
18
  }
19
- executePrefixCommand({ message, interaction, args, client, framework }) {
20
- this.execute({ message, interaction, args, client, framework });
19
+ executePrefixCommand({ message, interaction, args, client, framework, trans }) {
20
+ this.execute({ message, interaction, args, client, framework, trans });
21
21
  }
22
- executeSlashCommand({ message, interaction, args, client, framework }) {
23
- this.execute({ message, interaction, args, client, framework });
22
+ executeSlashCommand({ message, interaction, args, client, framework, trans }) {
23
+ this.execute({ message, interaction, args, client, framework, trans });
24
24
  }
25
25
  }
@@ -15,4 +15,5 @@ export interface CommandParameters {
15
15
  client: Client;
16
16
  framework: ZumitoFramework;
17
17
  guildSettings?: any;
18
+ trans: Function;
18
19
  }
@@ -145,10 +145,10 @@ export class Module {
145
145
  if (file.endsWith('.json')) {
146
146
  let json = await this.loadTranslationFile(subpath, file);
147
147
  let lang = file.slice(0, -5);
148
- subpath = subpath ? subpath.replaceAll('/', '.') + '.' : '';
149
- this.parseTranslation(subpath, lang, json);
148
+ let baseKey = subpath ? subpath.replaceAll('/', '.').replaceAll('\\', '.') + '.' : '';
149
+ this.parseTranslation(baseKey, lang, json);
150
150
  }
151
- else if (fs.lstatSync(path.join(this.path, 'translations', file)).isDirectory()) {
151
+ else if (fs.lstatSync(path.join(this.path, 'translations', subpath, file)).isDirectory()) {
152
152
  await this.registerTranslations(path.join(subpath, file));
153
153
  }
154
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.1.47",
3
+ "version": "1.1.49",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",