trivious 1.3.22 → 1.3.24

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.cts CHANGED
@@ -650,6 +650,12 @@ interface TriviousClientOptions extends ClientOptions {
650
650
  * @type {Record<string, PermissionLevel>}
651
651
  */
652
652
  rolePermissions?: Record<string, PermissionLevel>;
653
+ /**
654
+ * Discord user Ids of the bot owner(s)
655
+ *
656
+ * @type {string[]}
657
+ */
658
+ botOwnerIds?: string[];
653
659
  }
654
660
 
655
661
  /**
@@ -746,6 +752,14 @@ declare class ModuleRegistry extends BaseRegistry<Module> {
746
752
  */
747
753
  declare class EventRegistry extends BaseRegistry<Event> {
748
754
  protected items: Collection<string, Event<keyof ClientEvents>>;
755
+ /**
756
+ * Load all preset events, can be overridden by user-provided events.
757
+ *
758
+ * @async
759
+ * @protected
760
+ * @returns {Promise<this>}
761
+ */
762
+ protected loadPresetEvents(): Promise<this>;
749
763
  /**
750
764
  * Load all events.
751
765
  *
@@ -926,7 +940,7 @@ declare class TriviousClient extends Client {
926
940
  * @private
927
941
  * @type {TriviousClientOptions}
928
942
  */
929
- private _options;
943
+ readonly _options: TriviousClientOptions;
930
944
  /**
931
945
  * Creates an instance of TriviousClient.
932
946
  *
package/dist/index.d.ts CHANGED
@@ -650,6 +650,12 @@ interface TriviousClientOptions extends ClientOptions {
650
650
  * @type {Record<string, PermissionLevel>}
651
651
  */
652
652
  rolePermissions?: Record<string, PermissionLevel>;
653
+ /**
654
+ * Discord user Ids of the bot owner(s)
655
+ *
656
+ * @type {string[]}
657
+ */
658
+ botOwnerIds?: string[];
653
659
  }
654
660
 
655
661
  /**
@@ -746,6 +752,14 @@ declare class ModuleRegistry extends BaseRegistry<Module> {
746
752
  */
747
753
  declare class EventRegistry extends BaseRegistry<Event> {
748
754
  protected items: Collection<string, Event<keyof ClientEvents>>;
755
+ /**
756
+ * Load all preset events, can be overridden by user-provided events.
757
+ *
758
+ * @async
759
+ * @protected
760
+ * @returns {Promise<this>}
761
+ */
762
+ protected loadPresetEvents(): Promise<this>;
749
763
  /**
750
764
  * Load all events.
751
765
  *
@@ -926,7 +940,7 @@ declare class TriviousClient extends Client {
926
940
  * @private
927
941
  * @type {TriviousClientOptions}
928
942
  */
929
- private _options;
943
+ readonly _options: TriviousClientOptions;
930
944
  /**
931
945
  * Creates an instance of TriviousClient.
932
946
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'util';
2
- import { Collection, SlashCommandSubcommandBuilder, Client, REST, Routes, SlashCommandBuilder, ContextMenuCommandBuilder, InteractionContextType, ButtonInteraction, ModalSubmitInteraction } from 'discord.js';
2
+ import { Collection, SlashCommandSubcommandBuilder, Client, REST, Routes, SlashCommandBuilder, ContextMenuCommandBuilder, InteractionContextType } from 'discord.js';
3
3
  import { existsSync, promises } from 'fs';
4
4
  import path, { dirname, join, resolve } from 'path';
5
5
  import { fileURLToPath, pathToFileURL } from 'url';
@@ -488,16 +488,16 @@ var getPermissionLevel = (client, member) => {
488
488
 
489
489
  // src/shared/utility/functions.ts
490
490
  var __filename$1 = fileURLToPath(import.meta.url);
491
- var __dirname$1 = dirname(__filename$1);
491
+ var __dirname2 = dirname(__filename$1);
492
492
  var getPackageRoot = () => {
493
- let dir = __dirname$1;
493
+ let dir = __dirname2;
494
494
  while (dir !== dirname(dir)) {
495
495
  if (existsSync(join(dir, "package.json")) || existsSync(join(dir, "node_modules"))) {
496
496
  return dir;
497
497
  }
498
498
  dir = dirname(dir);
499
499
  }
500
- return __dirname$1;
500
+ return __dirname2;
501
501
  };
502
502
  var FRAMEWORK_PACKAGE_ROOT = getPackageRoot();
503
503
  function getCorePath(options) {
@@ -541,10 +541,9 @@ async function exists(path2) {
541
541
  }
542
542
  function hasPermission(client, options) {
543
543
  const { permission, user, member } = options;
544
- if (user) {
545
- if (permission === 5 /* BOT_OWNER */) return user.id === "424764032667484171";
546
- return true;
547
- }
544
+ if (permission === 5 /* BOT_OWNER */ && client._options.botOwnerIds)
545
+ return user ? client._options.botOwnerIds.includes(user.id) : member ? client._options.botOwnerIds.includes(member.id) : false;
546
+ if (user) return true;
548
547
  if (member) {
549
548
  const memberPermission = getPermissionLevel(client, member);
550
549
  return memberPermission >= permission;
@@ -697,69 +696,28 @@ var ComponentRegistry = class extends BaseRegistry {
697
696
  return this;
698
697
  }
699
698
  };
700
- var interactionCreate_default = {
701
- name: "interactionCreate",
702
- execute: async (client, interaction) => {
703
- if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
704
- const { commandName } = interaction;
705
- const registeredCommands = client.registries.commands.get();
706
- const command = registeredCommands.get(commandName);
707
- if (!command) {
708
- await interaction.reply({
709
- content: `Command is outdated, inactive or does not have a handler!`,
710
- flags: ["Ephemeral"]
711
- });
712
- return;
713
- }
714
- const requiredPermission = command.metadata.permission;
715
- const hasPermission2 = await command.validateGuildPermission(
716
- client,
717
- interaction,
718
- requiredPermission
719
- );
720
- if (!hasPermission2) return;
721
- if (!("execute" in command)) {
722
- await command.reply(interaction, { content: "Command does not have a way to execute! Ensure the command is a SlashCommand or ContextMenuCommand!" });
723
- return;
724
- }
725
- await command.reply(interaction, { content: "Processing command..." });
726
- if (interaction.isChatInputCommand() && command.isSlashCommand()) {
727
- await command.execute(client, interaction);
728
- } else if (interaction.isContextMenuCommand() && command.isContextMenuCommand()) {
729
- await command.execute(client, interaction);
730
- }
731
- } else if (interaction.isMessageComponent() || interaction.isModalSubmit()) {
732
- const { componentType, tags, data } = deconstructCustomId(interaction.customId);
733
- if (componentType === "button" /* Button */ && !(interaction instanceof ButtonInteraction))
734
- return;
735
- if (componentType === "modal" /* Modal */ && !(interaction instanceof ModalSubmitInteraction))
736
- return;
737
- if (tags.includes("awaited")) return;
738
- const registeredComponents = client.registries.components.get();
739
- const component = registeredComponents.get(data);
740
- if (!component) {
741
- await interaction.reply({
742
- content: `Command is outdated, inactive or does not have a handler!`,
743
- flags: ["Ephemeral"]
744
- });
745
- return;
746
- }
747
- const requiredPermission = component.metadata.permission;
748
- const hasPermission2 = await component.validateGuildPermission(
749
- client,
750
- interaction,
751
- requiredPermission
752
- );
753
- if (!hasPermission2) return;
754
- if (!interaction.isModalSubmit()) await interaction.deferUpdate();
755
- await component.execute(client, interaction);
756
- }
757
- }
758
- };
759
-
760
- // src/core/registry/event.registry.ts
761
699
  var EventRegistry = class extends BaseRegistry {
762
700
  items = new Collection();
701
+ /**
702
+ * Load all preset events, can be overridden by user-provided events.
703
+ *
704
+ * @async
705
+ * @protected
706
+ * @returns {Promise<this>}
707
+ */
708
+ async loadPresetEvents() {
709
+ const directory = join(__dirname, "../events");
710
+ const entries = await promises.readdir(directory, { withFileTypes: true });
711
+ for (const entry of entries) {
712
+ const fullPath = join(directory, entry.name);
713
+ if (!entry.isFile() || !entry.name.endsWith(".js")) continue;
714
+ const event = await this.importFile(fullPath);
715
+ if (!event) continue;
716
+ if (this.items.has(event.name)) continue;
717
+ this.items.set(event.name, event);
718
+ }
719
+ return this;
720
+ }
763
721
  /**
764
722
  * Load all events.
765
723
  *
@@ -782,7 +740,7 @@ var EventRegistry = class extends BaseRegistry {
782
740
  this.items.set(event.name, event);
783
741
  }
784
742
  }
785
- this.items.set(interactionCreate_default.name, interactionCreate_default);
743
+ await this.loadPresetEvents();
786
744
  return this;
787
745
  }
788
746
  /**