@stelliajs/framework 1.3.0-dev-2 → 1.4.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.
@@ -11,6 +11,9 @@ export class StelliaClient extends Client {
11
11
  environment;
12
12
  constructor(clientOptions, stelliaOptions) {
13
13
  super(clientOptions);
14
+ if (stelliaOptions?.environment) {
15
+ this.environment = stelliaOptions.environment;
16
+ }
14
17
  if (stelliaOptions?.managers.autoCompletes?.directoryPath) {
15
18
  this.managers.autoCompletes = new AutoCompleteManager(this, stelliaOptions.managers.autoCompletes.directoryPath);
16
19
  }
@@ -32,9 +35,6 @@ export class StelliaClient extends Client {
32
35
  if (stelliaOptions?.managers.modals?.directoryPath) {
33
36
  this.managers.modals = new ModalManager(this, stelliaOptions.managers.modals.directoryPath);
34
37
  }
35
- if (stelliaOptions?.environment) {
36
- this.environment = stelliaOptions.environment;
37
- }
38
38
  this.utils = new StelliaUtils(this);
39
39
  process.on("unhandledRejection", (error) => {
40
40
  logger.error(`Unhandled promise rejection: ${error}`);
@@ -44,9 +44,12 @@ export class StelliaUtils {
44
44
  if (!this.client.environment.areGuildsConfigurationEnabled || !this.guildsConfiguration) {
45
45
  return undefined;
46
46
  }
47
- const { guilds, ...general } = this.guildsConfiguration;
47
+ const { guilds, general } = this.guildsConfiguration;
48
48
  const guildConfiguration = guilds[guildId];
49
- return { general, guild: guildConfiguration };
49
+ return {
50
+ general: general,
51
+ guild: guildConfiguration
52
+ };
50
53
  };
51
54
  handleInteraction = async (interaction) => {
52
55
  if (interaction.inCachedGuild()) {
@@ -1,4 +1,4 @@
1
- import { Collection, Events } from "discord.js";
1
+ import { Collection } from "discord.js";
2
2
  import { BaseManager } from "./index.js";
3
3
  import { requiredFiles } from "../utils/index.js";
4
4
  import { logger } from "../utils/logger.js";
@@ -27,7 +27,6 @@ export class EventManager extends BaseManager {
27
27
  await this.loadEventWithoutGuildConfiguration(eventStructure);
28
28
  }
29
29
  }
30
- this.client.on(Events.Error, (error) => logger.error(`Client error: ${error}`));
31
30
  this.setManagerLoaded();
32
31
  }
33
32
  getByCustomId(id) {
@@ -53,16 +52,13 @@ export class EventManager extends BaseManager {
53
52
  }
54
53
  eventHandler = (event, ...args) => {
55
54
  const mainArgument = args[0];
56
- if (!mainArgument) {
57
- const eventStructure = event;
58
- return eventStructure.execute(this.client, this.guildsConfiguration);
59
- }
60
55
  const guildConfiguration = this.getGuildConfiguration(mainArgument);
61
56
  if (guildConfiguration) {
62
57
  const eventStructure = event;
63
58
  return eventStructure.execute(this.client, guildConfiguration, ...args);
64
59
  }
65
- logger.warn(`No guild configuration found for event ${event.data.name} with main argument ${mainArgument}`);
60
+ const eventStructure = event;
61
+ return eventStructure.execute(this.client, this.guildsConfiguration);
66
62
  };
67
63
  async loadEventWithoutGuildConfiguration(eventStructure) {
68
64
  const { name, once } = eventStructure.data;
@@ -1,4 +1,6 @@
1
1
  import { type AutoCompleteManager, type ButtonManager, type CommandManager, type ContextMenuManager, type EventManager, type ModalManager, type SelectMenuManager } from "../managers/index.js";
2
+ import { type Snowflake } from "discord.js";
3
+ import { Locale } from "../utils/translation.js";
2
4
  export type StructureCustomId = string | RegExp;
3
5
  export type InteractionCustomId = string;
4
6
  export declare enum InteractionType {
@@ -24,7 +26,7 @@ export interface ClientEnvironment {
24
26
  areGuildsConfigurationEnabled: boolean;
25
27
  }
26
28
  export interface BaseGuildConfiguration {
27
- locale: string;
29
+ locale: Locale;
28
30
  [key: string]: unknown;
29
31
  }
30
32
  export interface BaseGeneralConfiguration {
@@ -35,7 +37,7 @@ export interface GuildsConfiguration {
35
37
  [key: string]: unknown;
36
38
  };
37
39
  guilds: {
38
- [guildId: string]: BaseGuildConfiguration;
40
+ [guildId in Snowflake]: BaseGuildConfiguration;
39
41
  };
40
42
  }
41
43
  export interface GuildConfiguration {
@@ -1,2 +1,3 @@
1
1
  export * from "./ephemeralReponse.js";
2
2
  export * from "./files.js";
3
+ export * from "./logger.js";
@@ -1,2 +1,3 @@
1
1
  export * from "./ephemeralReponse.js";
2
2
  export * from "./files.js";
3
+ export * from "./logger.js";
@@ -0,0 +1,9 @@
1
+ interface TranslateArgs {
2
+ [key: string]: any;
3
+ }
4
+ export declare enum Locale {
5
+ EN = "en",
6
+ FR = "fr"
7
+ }
8
+ export declare const translateToLocale: (locale: Locale, key: string, args?: TranslateArgs) => Promise<any>;
9
+ export {};
@@ -0,0 +1,10 @@
1
+ import i18next from "i18next";
2
+ export var Locale;
3
+ (function (Locale) {
4
+ Locale["EN"] = "en";
5
+ Locale["FR"] = "fr";
6
+ })(Locale || (Locale = {}));
7
+ export const translateToLocale = async (locale, key, args) => {
8
+ await i18next.changeLanguage(locale);
9
+ return i18next.t(key, { interpolation: { escapeValue: false }, returnObjects: true, ...args });
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelliajs/framework",
3
- "version": "1.3.0-dev-2",
3
+ "version": "1.4.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "scripts": {
@@ -15,8 +15,9 @@
15
15
  "description": "A framework for simplify the creation of discord bots",
16
16
  "keywords": ["discord", "bot", "discordjs", "typescript", "framework"],
17
17
  "dependencies": {
18
- "discord-api-types": "^0.38.10",
18
+ "discord-api-types": "^0.38.11",
19
19
  "discord.js": "^14.19.3",
20
+ "i18next": "^25.2.1",
20
21
  "log-symbols": "^7.0.1"
21
22
  },
22
23
  "devDependencies": {