zumito-framework 1.8.5 → 1.10.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.
package/dist/index.d.ts CHANGED
@@ -30,7 +30,8 @@ import { InteractionHandler } from './services/handlers/InteractionHandler.js';
30
30
  import { CommandManager } from './services/managers/CommandManager.js';
31
31
  import { ErrorType } from './definitions/ErrorType.js';
32
32
  import { InviteUrlGenerator } from './services/utilities/InviteUrlGenerator.js';
33
+ import { PrefixResolver } from './services/utilities/PrefixResolver.js';
33
34
  export { ModalSubmitParameters } from './definitions/parameters/ModalSubmitParameters.js';
34
35
  export { CommandBinds } from './definitions/commands/CommandBinds.js';
35
36
  export { Injectable } from './definitions/decorators/Injectable.decorator.js';
36
- export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, ButtonPressed, ButtonPressedParams, TextFormatter, EmojiFallback, DatabaseConfigLoader, PresenceDataRule, RuledPresenceData, StatusManagerOptions, discord, EventParameters, ServiceContainer, GuildDataGetter, SlashCommandRefresher, CommandParser, ErrorHandler, ErrorType, Route, RouteMethod, InteractionHandler, CommandManager, InviteUrlGenerator };
37
+ export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, ButtonPressed, ButtonPressedParams, TextFormatter, EmojiFallback, DatabaseConfigLoader, PresenceDataRule, RuledPresenceData, StatusManagerOptions, discord, EventParameters, ServiceContainer, GuildDataGetter, SlashCommandRefresher, CommandParser, ErrorHandler, ErrorType, Route, RouteMethod, InteractionHandler, CommandManager, InviteUrlGenerator, PrefixResolver, };
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ import { InteractionHandler } from './services/handlers/InteractionHandler.js';
23
23
  import { CommandManager } from './services/managers/CommandManager.js';
24
24
  import { ErrorType } from './definitions/ErrorType.js';
25
25
  import { InviteUrlGenerator } from './services/utilities/InviteUrlGenerator.js';
26
+ import { PrefixResolver } from './services/utilities/PrefixResolver.js';
26
27
  export { Injectable } from './definitions/decorators/Injectable.decorator.js';
27
28
  ServiceContainer.addService(TextFormatter, []);
28
29
  ServiceContainer.addService(EmojiFallback, [discord.Client.name, TranslationManager.name]);
@@ -32,5 +33,6 @@ ServiceContainer.addService(CommandParser, []);
32
33
  ServiceContainer.addService(SlashCommandRefresher, [ZumitoFramework.name]);
33
34
  ServiceContainer.addService(InteractionHandler, []);
34
35
  ServiceContainer.addService(InviteUrlGenerator, []);
36
+ ServiceContainer.addService(PrefixResolver, []);
35
37
  ServiceContainer.addService(ErrorHandler, ['ZumitoFramework']);
36
- export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback, DatabaseConfigLoader, discord, ServiceContainer, GuildDataGetter, SlashCommandRefresher, CommandParser, ErrorHandler, ErrorType, Route, RouteMethod, InteractionHandler, CommandManager, InviteUrlGenerator };
38
+ export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback, DatabaseConfigLoader, discord, ServiceContainer, GuildDataGetter, SlashCommandRefresher, CommandParser, ErrorHandler, ErrorType, Route, RouteMethod, InteractionHandler, CommandManager, InviteUrlGenerator, PrefixResolver, };
@@ -1,7 +1,7 @@
1
1
  import { REST } from '@discordjs/rest';
2
2
  import { Routes } from 'discord-api-types/v9';
3
3
  import { CommandType } from "../definitions/commands/CommandType";
4
- import { SlashCommandBuilder } from "discord.js";
4
+ import { InteractionContextType, SlashCommandBuilder } from "discord.js";
5
5
  export class SlashCommandRefresher {
6
6
  framework;
7
7
  constructor(framework) {
@@ -34,6 +34,13 @@ export class SlashCommandRefresher {
34
34
  slashCommand
35
35
  .setName(command.name)
36
36
  .setDescription(this.framework.translations.get('command.' + command.name + '.description', 'en'));
37
+ if (slashCommand instanceof SlashCommandBuilder) {
38
+ slashCommand.setContexts([
39
+ InteractionContextType.BotDM,
40
+ InteractionContextType.Guild,
41
+ InteractionContextType.PrivateChannel,
42
+ ]);
43
+ }
37
44
  if (command.args) {
38
45
  command.args.forEach((arg) => {
39
46
  let method;
@@ -30,15 +30,17 @@ export class GuildDataGetter {
30
30
  async getGuildSettings(guildId) {
31
31
  const collection = this.framework.database.collection('guilds');
32
32
  let guild = await collection.findOne({ guild_id: guildId });
33
- guild = {
34
- _id: new ObjectId(),
35
- guild_id: guildId,
36
- lang: 'en',
37
- prefix: 'z-',
38
- public: false,
39
- deleteCommands: false
40
- };
41
- await collection.insertOne(guild);
33
+ if (!guild) {
34
+ guild = {
35
+ _id: new ObjectId(),
36
+ guild_id: guildId,
37
+ lang: 'en',
38
+ prefix: null,
39
+ public: false,
40
+ deleteCommands: false
41
+ };
42
+ await collection.insertOne(guild);
43
+ }
42
44
  return guild;
43
45
  }
44
46
  }
@@ -0,0 +1,20 @@
1
+ import { ZumitoFramework } from "../../ZumitoFramework";
2
+ import { GuildDataGetter } from "./GuildDataGetter";
3
+ export declare class PrefixResolver {
4
+ private framework;
5
+ private guildDataGetter;
6
+ constructor(framework?: ZumitoFramework, guildDataGetter?: GuildDataGetter);
7
+ /**
8
+ * Resolve the prefix for a given context (guildId or DM).
9
+ * Priority:
10
+ * 1. Guild DB prefix (if exists and not null)
11
+ * 2. process.env.BOTPREFIX
12
+ * 3. framework.settings.defaultPrefix
13
+ * 4. 'z-'
14
+ * @param context { guildId?: string, userId?: string }
15
+ */
16
+ resolvePrefix(context: {
17
+ guildId?: string;
18
+ userId?: string;
19
+ }): Promise<string>;
20
+ }
@@ -0,0 +1,39 @@
1
+ import { ZumitoFramework } from "../../ZumitoFramework";
2
+ import { ServiceContainer } from "../ServiceContainer";
3
+ import { GuildDataGetter } from "./GuildDataGetter";
4
+ export class PrefixResolver {
5
+ framework;
6
+ guildDataGetter;
7
+ constructor(framework = ServiceContainer.getService(ZumitoFramework), guildDataGetter = ServiceContainer.getService(GuildDataGetter)) {
8
+ this.framework = framework;
9
+ this.guildDataGetter = guildDataGetter;
10
+ }
11
+ /**
12
+ * Resolve the prefix for a given context (guildId or DM).
13
+ * Priority:
14
+ * 1. Guild DB prefix (if exists and not null)
15
+ * 2. process.env.BOTPREFIX
16
+ * 3. framework.settings.defaultPrefix
17
+ * 4. 'z-'
18
+ * @param context { guildId?: string, userId?: string }
19
+ */
20
+ async resolvePrefix(context) {
21
+ // 1. Guild DB prefix
22
+ if (context.guildId) {
23
+ const guild = await this.guildDataGetter.getGuildSettings(context.guildId);
24
+ if (guild && guild.prefix) {
25
+ return guild.prefix;
26
+ }
27
+ }
28
+ // 2. Env var
29
+ if (process.env.DEFAULT_PREFIX) {
30
+ return process.env.DEFAULT_PREFIX;
31
+ }
32
+ // 3. Framework config
33
+ if (this.framework.settings?.defaultPrefix) {
34
+ return this.framework.settings.defaultPrefix;
35
+ }
36
+ // 4. Hardcoded fallback
37
+ return "z-";
38
+ }
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.8.5",
3
+ "version": "1.10.0",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",