zumito-framework 1.1.34 → 1.1.35

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.
@@ -46,4 +46,5 @@ export declare class ZumitoFramework {
46
46
  private initializeDiscordClient;
47
47
  static splitCommandLine(commandLine: any): any;
48
48
  memberHasPermission(member: GuildMember, channel: TextChannel, permission: bigint): Promise<boolean>;
49
+ getGuildSettings(guildId: string): Promise<any>;
49
50
  }
@@ -222,6 +222,13 @@ export class ZumitoFramework {
222
222
  let memberPermission = await channel.permissionsFor(member);
223
223
  return memberPermission.has(permission);
224
224
  }
225
+ async getGuildSettings(guildId) {
226
+ let guild = await this.models.get('Guild').findOne({ guild_id: guildId });
227
+ if (guild == null) {
228
+ guild = await this.models.get('Guild').create({ guild_id: guildId });
229
+ }
230
+ return guild;
231
+ }
225
232
  }
226
233
  function MergeRecursive(obj1, obj2) {
227
234
  for (var p in obj2) {
@@ -3,6 +3,10 @@ import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
3
3
  export class InteractionCreate extends FrameworkEvent {
4
4
  once = false;
5
5
  async execute({ interaction, client, framework }) {
6
+ let guildSettings;
7
+ if (interaction.guildId) {
8
+ guildSettings = await framework.getGuildSettings(interaction.guildId);
9
+ }
6
10
  if (interaction.isCommand()) {
7
11
  if (!framework.commands.has(interaction.commandName))
8
12
  return;
@@ -17,10 +21,10 @@ export class InteractionCreate extends FrameworkEvent {
17
21
  if (![CommandType.any, CommandType.separated, CommandType.slash].includes(commandInstance.type))
18
22
  return;
19
23
  if (commandInstance.type === CommandType.separated || commandInstance.type === CommandType.slash) {
20
- await commandInstance.executeSlashCommand({ client, interaction, args, framework });
24
+ await commandInstance.executeSlashCommand({ client, interaction, args, framework, guildSettings });
21
25
  }
22
26
  else {
23
- await commandInstance.execute({ client, interaction, args, framework });
27
+ await commandInstance.execute({ client, interaction, args, framework, guildSettings });
24
28
  }
25
29
  }
26
30
  else if (interaction.isButton()) {
@@ -29,7 +33,7 @@ export class InteractionCreate extends FrameworkEvent {
29
33
  let path = interaction.customId.split('.');
30
34
  const command = framework.commands.get(path[0]);
31
35
  if (command.selectMenu) {
32
- command.selectMenu({ path, interaction, client, framework });
36
+ command.selectMenu({ path, interaction, client, framework, guildSettings });
33
37
  }
34
38
  }
35
39
  }
@@ -62,6 +62,7 @@ export class MessageCreate extends FrameworkEvent {
62
62
  }
63
63
  }
64
64
  try {
65
+ let guildSettings = await framework.getGuildSettings(message.guildId);
65
66
  let parsedArgs = new Map();
66
67
  args.forEach(function (arg, index) {
67
68
  parsedArgs.set(commandInstance.args?.[index]?.name || index, arg);
@@ -71,6 +72,7 @@ export class MessageCreate extends FrameworkEvent {
71
72
  args: parsedArgs,
72
73
  client: framework.client,
73
74
  framework: framework,
75
+ guildSettings: guildSettings,
74
76
  });
75
77
  if (!message.channel.isDMBased && !message.deletable && (false)) { // false = settings.deleteCommands
76
78
  try {
@@ -0,0 +1,14 @@
1
+ {
2
+ "id": "string",
3
+ "command": {
4
+ "command": "string",
5
+ "args": {
6
+ "type": "array"
7
+ }
8
+ },
9
+ "error": {
10
+ "title": "string",
11
+ "message": "string",
12
+ "stacktrace": "string"
13
+ }
14
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "guild_id": {
3
+ "type": "string",
4
+ "index": true,
5
+ "unique": true
6
+ },
7
+ "lang": {
8
+ "type": "string",
9
+ "default": "en"
10
+ },
11
+ "prefix": {
12
+ "type": "string",
13
+ "default": "z-"
14
+ },
15
+ "public": {
16
+ "type": "boolean",
17
+ "default": false
18
+ },
19
+ "deleteCommands": {
20
+ "type": "boolean",
21
+ "default": false
22
+ }
23
+ }
@@ -3,15 +3,15 @@ import { SelectMenuParameters } from "./SelectMenuParameters.js";
3
3
  export declare abstract class Command {
4
4
  name: string;
5
5
  categories: string[];
6
- aliases?: string[];
7
- examples?: string[];
8
- userPermissions?: bigint[];
9
- botPermissions?: string[];
10
- hidden?: boolean;
11
- adminOnly?: boolean;
12
- nsfw?: boolean;
13
- cooldown?: number;
14
- slashCommand?: boolean;
6
+ aliases: string[];
7
+ examples: string[];
8
+ userPermissions: bigint[];
9
+ botPermissions: string[];
10
+ hidden: boolean;
11
+ adminOnly: boolean;
12
+ nsfw: boolean;
13
+ cooldown: number;
14
+ slashCommand: boolean;
15
15
  dm: boolean;
16
16
  args: CommandArgDefinition[];
17
17
  type: string;
@@ -14,4 +14,5 @@ export interface CommandParameters {
14
14
  args: Map<String, any>;
15
15
  client: Client;
16
16
  framework: ZumitoFramework;
17
+ guildSettings?: any;
17
18
  }
@@ -18,6 +18,7 @@ export class Module {
18
18
  await this.registerCommands();
19
19
  await this.registerEvents();
20
20
  await this.registerTranslations();
21
+ await this.registerModels();
21
22
  // console.error('[🔄🔴 ] Error initializing module ' + this.constructor.name);
22
23
  // console.log(boxen(e + '\n' + e.stack, { padding: 1 }));
23
24
  }
@@ -5,4 +5,5 @@ export interface SelectMenuParameters {
5
5
  interaction: SelectMenuInteraction;
6
6
  client: Client;
7
7
  framework: ZumitoFramework;
8
+ guildSettings?: any;
8
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.1.34",
3
+ "version": "1.1.35",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,8 +35,7 @@
35
35
  "express": "^4.18.1",
36
36
  "leven": "^4.0.0",
37
37
  "mongoose": "^6.5.2",
38
- "plop": "^3.1.1",
39
- "zumito-framework": "^1.1.16"
38
+ "plop": "^3.1.1"
40
39
  },
41
40
  "devDependencies": {
42
41
  "@types/node": "^18.7.16",
@@ -2,7 +2,7 @@ import { Command, CommandParameters } from "zumito-framework";
2
2
 
3
3
  export class {{capitalize command}} extends Command {
4
4
 
5
- execute({ message, interaction, args, client, framework }: CommandParameters): void {
5
+ execute({ message, interaction, args, client, framework, guildSettings }: CommandParameters): void {
6
6
  (message || interaction!).reply({
7
7
  content: "Message content",
8
8
  });