zumito-framework 1.1.51 → 1.1.52

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,6 +1,8 @@
1
+ import { Command } from "../../../types/Command.js";
1
2
  import { EventParameters } from "../../../types/EventParameters.js";
2
3
  import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
3
4
  export declare class InteractionCreate extends FrameworkEvent {
4
5
  once: boolean;
5
6
  execute({ interaction, client, framework }: EventParameters): Promise<void>;
7
+ getTransMethod(commandInstance: Command, framework: any, guildSettings: any): (key: string, params?: any) => any;
6
8
  }
@@ -30,14 +30,7 @@ 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
+ const trans = this.getTransMethod(commandInstance, guildSettings, framework);
41
34
  if (commandInstance.type === CommandType.separated || commandInstance.type === CommandType.slash) {
42
35
  await commandInstance.executeSlashCommand({ client, interaction, args, framework, guildSettings, trans });
43
36
  }
@@ -46,6 +39,15 @@ export class InteractionCreate extends FrameworkEvent {
46
39
  }
47
40
  }
48
41
  else if (interaction.isButton()) {
42
+ interaction = interaction;
43
+ let path = interaction.customId.split('.');
44
+ const commandInstance = framework.commands.get(path[0]);
45
+ if (!commandInstance)
46
+ throw new Error(`Command ${path[0]} not found or button id bad formatted`);
47
+ // If the command has impements ButtonPress class then execute the method
48
+ if (commandInstance.constructor.prototype.hasOwnProperty('buttonPressed')) {
49
+ commandInstance.buttonPressed({ path, interaction, client, framework, guildSettings });
50
+ }
49
51
  }
50
52
  else if (interaction.isSelectMenu()) {
51
53
  let path = interaction.customId.split('.');
@@ -65,4 +67,14 @@ export class InteractionCreate extends FrameworkEvent {
65
67
  }
66
68
  }
67
69
  }
70
+ getTransMethod(commandInstance, framework, guildSettings) {
71
+ return (key, params) => {
72
+ if (key.startsWith('$')) {
73
+ return framework.translations.get(key.replace('$', ''), guildSettings.lang, params);
74
+ }
75
+ else {
76
+ return framework.translations.get('command.' + commandInstance.name + '.' + key, guildSettings.lang, params);
77
+ }
78
+ };
79
+ }
68
80
  }
package/dist/index.d.ts CHANGED
@@ -14,4 +14,6 @@ import { Translation } from './types/Translation.js';
14
14
  import { TranslationManager } from './TranslationManager.js';
15
15
  import { ZumitoFramework } from './ZumitoFramework.js';
16
16
  import { EmojiFallback } from './utils/EmojiFallback.js';
17
- export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, TextFormatter, EmojiFallback };
17
+ import { ButtonPressed } from './types/Commands/ButtonPressed.js';
18
+ import { ButtonPressedParams } from './types/Commands/ButtonPressedParams.js';
19
+ export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, ButtonPressed, ButtonPressedParams, TextFormatter, EmojiFallback };
package/dist/index.js CHANGED
@@ -9,4 +9,5 @@ import { Translation } from './types/Translation.js';
9
9
  import { TranslationManager } from './TranslationManager.js';
10
10
  import { ZumitoFramework } from './ZumitoFramework.js';
11
11
  import { EmojiFallback } from './utils/EmojiFallback.js';
12
- export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, TextFormatter, EmojiFallback };
12
+ import { ButtonPressed } from './types/Commands/ButtonPressed.js';
13
+ export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback };
@@ -0,0 +1,4 @@
1
+ import { ButtonPressedParams } from "./ButtonPressedParams";
2
+ export declare abstract class ButtonPressed {
3
+ abstract buttonPressed({}: ButtonPressedParams): void;
4
+ }
@@ -0,0 +1,2 @@
1
+ export class ButtonPressed {
2
+ }
@@ -0,0 +1,10 @@
1
+ import { ButtonInteraction, Client } from "discord.js";
2
+ import { ZumitoFramework } from "../../ZumitoFramework";
3
+ export interface ButtonPressedParams {
4
+ path: string[];
5
+ interaction: ButtonInteraction;
6
+ client: Client;
7
+ framework: ZumitoFramework;
8
+ guildSettings?: any;
9
+ trans: (key: string, params?: any) => string;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -3,7 +3,7 @@ import chalk from 'chalk';
3
3
  import boxen from "boxen";
4
4
  import * as fs from 'fs';
5
5
  import path from 'path';
6
- import { CommandInteraction, SelectMenuInteraction } from "discord.js";
6
+ import { ButtonInteraction, CommandInteraction, SelectMenuInteraction } from "discord.js";
7
7
  export class Module {
8
8
  path;
9
9
  framework;
@@ -128,7 +128,7 @@ export class Module {
128
128
  args.forEach(arg => {
129
129
  finalArgs[arg.constructor.name.toLowerCase()] = arg;
130
130
  });
131
- let interaction = args.find((arg) => arg instanceof SelectMenuInteraction || arg instanceof CommandInteraction);
131
+ let interaction = args.find((arg) => arg instanceof SelectMenuInteraction || arg instanceof CommandInteraction || arg instanceof ButtonInteraction);
132
132
  if (interaction) {
133
133
  finalArgs['interaction'] = interaction;
134
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.1.51",
3
+ "version": "1.1.52",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",