trivious 1.6.18 → 2.0.1

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.
Files changed (128) hide show
  1. package/README.md +57 -68
  2. package/dist/{core/builders/util.builders.d.ts → features/builders/utility.builders.d.ts} +0 -9
  3. package/dist/{core/builders/util.builders.js → features/builders/utility.builders.js} +2 -2
  4. package/dist/features/builders/utility.builders.js.map +1 -0
  5. package/dist/features/client/client.types.d.ts +85 -0
  6. package/dist/features/client/client.types.js +3 -0
  7. package/dist/{shared/typings/client.js.map → features/client/client.types.js.map} +1 -1
  8. package/dist/features/client/deploy.client.d.ts +7 -0
  9. package/dist/features/client/deploy.client.js +43 -0
  10. package/dist/features/client/deploy.client.js.map +1 -0
  11. package/dist/features/client/trivious.client.d.ts +3 -0
  12. package/dist/features/client/trivious.client.js +61 -0
  13. package/dist/features/client/trivious.client.js.map +1 -0
  14. package/dist/features/commands/commands.types.d.ts +3 -0
  15. package/dist/features/commands/commands.types.js +3 -0
  16. package/dist/{shared/typings/commands.js.map → features/commands/commands.types.js.map} +1 -1
  17. package/dist/features/commands/methods.commands.d.ts +13 -0
  18. package/dist/features/commands/methods.commands.js +70 -0
  19. package/dist/features/commands/methods.commands.js.map +1 -0
  20. package/dist/features/commands/registry.commands.d.ts +7 -0
  21. package/dist/features/commands/registry.commands.js +90 -0
  22. package/dist/features/commands/registry.commands.js.map +1 -0
  23. package/dist/features/components/components.types.d.ts +3 -0
  24. package/dist/features/components/components.types.js +10 -0
  25. package/dist/features/components/components.types.js.map +1 -0
  26. package/dist/features/components/registry.components.d.ts +7 -0
  27. package/dist/features/components/registry.components.js +23 -0
  28. package/dist/features/components/registry.components.js.map +1 -0
  29. package/dist/features/customId/customid.types.d.ts +13 -0
  30. package/dist/features/customId/customid.types.js +3 -0
  31. package/dist/features/customId/customid.types.js.map +1 -0
  32. package/dist/features/customId/methods.customid.d.ts +20 -0
  33. package/dist/features/customId/methods.customid.js +24 -0
  34. package/dist/features/customId/methods.customid.js.map +1 -0
  35. package/dist/features/events/events.types.d.ts +3 -0
  36. package/dist/features/events/events.types.js +3 -0
  37. package/dist/{shared/typings/events.js.map → features/events/events.types.js.map} +1 -1
  38. package/dist/features/events/presets/clientReady.d.ts +11 -0
  39. package/dist/{core/events → features/events/presets}/clientReady.js +1 -1
  40. package/dist/features/events/presets/clientReady.js.map +1 -0
  41. package/dist/features/events/presets/interactionCreate.d.ts +10 -0
  42. package/dist/features/events/presets/interactionCreate.js +49 -0
  43. package/dist/features/events/presets/interactionCreate.js.map +1 -0
  44. package/dist/features/events/registry.events.d.ts +8 -0
  45. package/dist/features/events/registry.events.js +45 -0
  46. package/dist/features/events/registry.events.js.map +1 -0
  47. package/dist/features/modules/modules.types.d.ts +3 -0
  48. package/dist/features/modules/modules.types.js +3 -0
  49. package/dist/{shared/typings/module.js.map → features/modules/modules.types.js.map} +1 -1
  50. package/dist/features/modules/registry.modules.d.ts +8 -0
  51. package/dist/features/modules/registry.modules.js +30 -0
  52. package/dist/features/modules/registry.modules.js.map +1 -0
  53. package/dist/features/structure/index.structure.d.ts +10 -0
  54. package/dist/features/structure/index.structure.js +51 -0
  55. package/dist/features/structure/index.structure.js.map +1 -0
  56. package/dist/index.d.ts +6 -5
  57. package/dist/index.js +4 -10
  58. package/dist/modules.types-4hfuUiCb.d.ts +165 -0
  59. package/dist/shared/registries.d.ts +26 -0
  60. package/dist/shared/registries.js +25 -0
  61. package/dist/shared/registries.js.map +1 -0
  62. package/dist/shared/typings.d.ts +4 -0
  63. package/dist/shared/typings.js +9 -0
  64. package/dist/shared/typings.js.map +1 -0
  65. package/dist/utility/errors.d.ts +15 -0
  66. package/dist/utility/errors.js +24 -0
  67. package/dist/utility/errors.js.map +1 -0
  68. package/dist/utility/functions.d.ts +4 -0
  69. package/dist/utility/functions.js +32 -0
  70. package/dist/utility/functions.js.map +1 -0
  71. package/package.json +7 -3
  72. package/dist/core/builders/util.builders.js.map +0 -1
  73. package/dist/core/client/trivious.client.d.ts +0 -6
  74. package/dist/core/client/trivious.client.js +0 -115
  75. package/dist/core/client/trivious.client.js.map +0 -1
  76. package/dist/core/commands/methods.command.d.ts +0 -6
  77. package/dist/core/commands/methods.command.js +0 -90
  78. package/dist/core/commands/methods.command.js.map +0 -1
  79. package/dist/core/events/clientReady.d.ts +0 -14
  80. package/dist/core/events/clientReady.js.map +0 -1
  81. package/dist/core/events/interactionCreate.d.ts +0 -14
  82. package/dist/core/events/interactionCreate.js +0 -84
  83. package/dist/core/events/interactionCreate.js.map +0 -1
  84. package/dist/core/registry/command.registry.d.ts +0 -6
  85. package/dist/core/registry/command.registry.js +0 -54
  86. package/dist/core/registry/command.registry.js.map +0 -1
  87. package/dist/core/registry/component.registry.d.ts +0 -6
  88. package/dist/core/registry/component.registry.js +0 -41
  89. package/dist/core/registry/component.registry.js.map +0 -1
  90. package/dist/core/registry/event.registry.d.ts +0 -6
  91. package/dist/core/registry/event.registry.js +0 -71
  92. package/dist/core/registry/event.registry.js.map +0 -1
  93. package/dist/core/registry/index.d.ts +0 -22
  94. package/dist/core/registry/index.js +0 -39
  95. package/dist/core/registry/index.js.map +0 -1
  96. package/dist/core/registry/module.registry.d.ts +0 -6
  97. package/dist/core/registry/module.registry.js +0 -55
  98. package/dist/core/registry/module.registry.js.map +0 -1
  99. package/dist/index-DbWA_10I.d.ts +0 -439
  100. package/dist/shared/typings/client.d.ts +0 -74
  101. package/dist/shared/typings/client.js +0 -3
  102. package/dist/shared/typings/commands.d.ts +0 -6
  103. package/dist/shared/typings/commands.js +0 -3
  104. package/dist/shared/typings/components.d.ts +0 -6
  105. package/dist/shared/typings/components.js +0 -10
  106. package/dist/shared/typings/components.js.map +0 -1
  107. package/dist/shared/typings/events.d.ts +0 -6
  108. package/dist/shared/typings/events.js +0 -3
  109. package/dist/shared/typings/index.d.ts +0 -6
  110. package/dist/shared/typings/index.js +0 -9
  111. package/dist/shared/typings/index.js.map +0 -1
  112. package/dist/shared/typings/module.d.ts +0 -6
  113. package/dist/shared/typings/module.js +0 -3
  114. package/dist/shared/typings/permissions.d.ts +0 -16
  115. package/dist/shared/typings/permissions.js +0 -13
  116. package/dist/shared/typings/permissions.js.map +0 -1
  117. package/dist/shared/typings/registry.d.ts +0 -51
  118. package/dist/shared/typings/registry.js +0 -61
  119. package/dist/shared/typings/registry.js.map +0 -1
  120. package/dist/shared/utility/components.utility.d.ts +0 -6
  121. package/dist/shared/utility/components.utility.js +0 -17
  122. package/dist/shared/utility/components.utility.js.map +0 -1
  123. package/dist/shared/utility/functions.d.ts +0 -60
  124. package/dist/shared/utility/functions.js +0 -81
  125. package/dist/shared/utility/functions.js.map +0 -1
  126. package/dist/shared/utility/permissions.utility.d.ts +0 -6
  127. package/dist/shared/utility/permissions.utility.js +0 -12
  128. package/dist/shared/utility/permissions.utility.js.map +0 -1
package/README.md CHANGED
@@ -20,18 +20,17 @@ pnpm add trivious
20
20
 
21
21
  ```ts
22
22
  // src/index.ts
23
- import { TriviousClient, PermissionLevel } from "trivious";
23
+ import { TriviousClient } from "trivious";
24
24
  import { GatewayIntentBits } from "discord.js";
25
25
 
26
26
  const client = new TriviousClient({
27
- tokenReference: "BOT_TOKEN",
28
- clientIdReference: "CLIENT_ID",
29
- corePath: "core", // Folder containing commands/, events/, components/, modules/
30
- intents: [GatewayIntentBits.Guilds],
31
- rolePermissions: {
32
- // Altneratively can be set via client.rolePermissions
33
- "123456789012345678": PermissionLevel.GUILD_MODERATOR, // Role ID → PermissionLevel
27
+ credentials: {
28
+ tokenReference: "BOT_TOKEN",
29
+ clientIdReference: "CLIENT_ID",
34
30
  },
31
+ corePath: "core", // Folder containing your bot's processes
32
+ intents: [GatewayIntentBits.Guilds],
33
+ ownerUserIds: ["1234"],
35
34
  });
36
35
 
37
36
  (async () => {
@@ -40,9 +39,9 @@ const client = new TriviousClient({
40
39
  // Registers all commands, events, components, modules;
41
40
  // Deploys slash commands globally and then logs into the bot
42
41
 
43
- // To separately register commands, events, etc - use client.register()
44
42
  // To separately deploy commands - use client.deploy() followed by client.login()
45
- } catch (error) {
43
+ } catch (err: unknown) {
44
+ const error = err as Error;
46
45
  console.error("Failed to start bot:", error);
47
46
  }
48
47
  })();
@@ -53,100 +52,90 @@ const client = new TriviousClient({
53
52
  ### Included Default Events
54
53
 
55
54
  Trivious automatically includes and inserts `clientReady` and `interactionCreate` handlers, which can be overwritten.
56
- It is recommended to use the default interactionCreate handler, which requires zero input in your own code.
55
+ It is recommended to use the default interactionCreate handler, which requires zero setup in your own code.
57
56
 
58
- These default events can be found in `src/core/events` in the Trivious repository.
57
+ These default events can be found in `src/features/events/presets` in the Trivious repository.
59
58
 
60
59
  ---
61
60
 
62
61
  ### Creating a Slash Command
63
62
 
64
63
  ```ts
65
- // src/core/commands/debug/index.ts
66
- import { SlashCommandBuilder } from "discord.js";
67
- import { PermissionLevel, SlashCommand } from "trivious";
64
+ // commands/debug/index.ts
65
+ import { ApplicationCommandType, SlashCommandBuilder } from "discord.js";
66
+ import { SlashCommandData } from "trivious";
68
67
 
69
68
  export default {
70
69
  active: true,
71
70
  context: "SlashCommand",
72
- flags: ["OwnerOnly", "GuildOnly", "EphemeralReply", "DeferReply"],
73
- permission: PermissionLevel.BOT_OWNER,
71
+ commandType: ApplicationCommandType.ChatInput,
72
+ flags: ["Cached", "EphemeralReply", "DeferReply"],
74
73
  data: new SlashCommandBuilder().setName("debug").setDescription("Debug commands"),
75
- } satisfies SlashCommand; // recommended for type-safety
74
+ } satisfies SlashCommandData;
76
75
  ```
77
76
 
78
- > Subcommands go in the same directory as the command file and are auto-detected.
77
+ ### Creating a Subcommand Group
78
+
79
+ ```ts
80
+ // commands/debug/config/index.ts
81
+ import { Collection, SlashCommandSubcommandGroupBuilder } from "discord.js";
82
+ import { SlashSubcommandGroupData } from "trivious";
83
+
84
+ export default {
85
+ context: "SlashSubcommandGroup",
86
+ data: new SlashCommandSubcommandGroupBuilder()
87
+ .setName("config")
88
+ .setDescription("Config commands"),
89
+ subcommands: new Collection(),
90
+ } satisfies SlashSubcommandGroupData;
91
+ ```
92
+
93
+ > Subcommands go in the same directory as the subcommand group file and are auto-detected.
94
+
95
+ ---
79
96
 
80
97
  ### Creating a Subcommand
81
98
 
82
99
  ```ts
83
- // src/core/commands/debug/ping.ts
84
- import { SlashCommandSubcommandBuilder } from "discord.js";
85
- import { commandReply, SlashSubcommand } from "trivious";
100
+ // commands/debug/ping.ts
101
+ import { ApplicationCommandType, SlashCommandSubcommandBuilder } from "discord.js";
102
+ import { interactionReply, SlashSubcommandData } from "trivious";
86
103
 
87
104
  export default {
88
105
  active: true,
89
106
  context: "SlashSubcommand",
107
+ commandType: ApplicationCommandType.ChatInput,
90
108
  data: new SlashCommandSubcommandBuilder().setName("ping").setDescription("Ping pong!"),
91
109
 
92
110
  async execute(client, interaction) {
93
111
  const ping = (await interaction.fetchReply()).createdTimestamp - interaction.createdTimestamp;
94
112
 
95
- await commandReply(this, interaction, {
96
- content: `Pong!\nBot latency: ${ping}ms, API latency: ${client.ws.ping.toString()}ms`,
113
+ await interactionReply({
114
+ interaction,
115
+ replyPayload: {
116
+ content: `Pong!\nBot latency: ${ping}ms, API latency: ${client.ws.ping.toString()}ms`,
117
+ },
118
+ flags: ["EphemeralReply"],
97
119
  });
98
120
  },
99
- } satisfies SlashSubcommand; // recommended for type-safety
121
+ } satisfies SlashSubcommandData;
100
122
  ```
101
123
 
102
124
  ---
103
125
 
104
- ### Permission Levels
105
-
106
- ```ts
107
- enum PermissionLevel {
108
- USER = 0,
109
- GUILD_STAFF = 1,
110
- GUILD_MODERATOR = 2,
111
- GUILD_ADMINISTRATOR = 3,
112
- GUILD_OWNER = 4,
113
- BOT_OWNER = 5,
114
- }
115
- ```
116
-
117
- Set role permissions in client options
118
-
119
- ```ts
120
- rolePermissions: {
121
- "987654321098765432": PermissionLevel.GUILD_ADMINISTRATOR,
122
- moderatorRole.id: PermissionLevel.GUILD_MODERATOR,
123
- }
124
- ```
126
+ ### Project Structure
125
127
 
126
- Or dynamically at runtime:
128
+ Any project structure (e.g. type-based, feature-based) is acceptable as long as everything you expect to be registered is within the core directory.
127
129
 
128
- ```ts
129
- client.setRolePermissions({
130
- "123456": PermissionLevel.GUILD_STAFF,
131
- });
132
- ```
133
-
134
- ---
130
+ For example, if all of your commands, components, events and modules are anywhere inside src/features, assuming they export the correct data, they will be detected and registered to the client.
135
131
 
136
- ### Recommended Project Structure
132
+ The only required specific structure are for slash commands, as shown below.
137
133
 
138
134
  ```
139
- src/
140
- ├── core/
141
- ├── commands/
142
- │ │ └── debug/
143
- │ │ ├── index.ts
144
- │ │ └── ping.ts
145
- │ ├── events/
146
- │ │ └── ready.ts
147
- │ ├── components/
148
- │ │ └── ticket-create.ts
149
- │ └── modules/
150
- │ └── logging.ts
151
- └── index.ts
135
+ command/
136
+ ├── index.ts
137
+ ├── subcommand.ts
138
+ └── subcommand-group/
139
+ ├── index.ts
140
+ └──subcommand.ts
152
141
  ```
@@ -2,19 +2,10 @@ import { MessageActionRowComponentBuilder, ActionRowBuilder, EmbedData, APIEmbed
2
2
 
3
3
  /**
4
4
  * Utility action row builder
5
- *
6
- * @export
7
- * @template {MessageActionRowComponentBuilder} T
8
- * @param {...T[]} builders
9
- * @returns {*}
10
5
  */
11
6
  declare function createActionRow<T extends MessageActionRowComponentBuilder>(...builders: T[]): ActionRowBuilder<T>;
12
7
  /**
13
8
  * Utility embed builder
14
- *
15
- * @export
16
- * @param {?(EmbedData | APIEmbed)} [data]
17
- * @returns {*}
18
9
  */
19
10
  declare function createEmbed(data?: EmbedData | APIEmbed): EmbedBuilder;
20
11
 
@@ -8,5 +8,5 @@ function createEmbed(data) {
8
8
  }
9
9
 
10
10
  export { createActionRow, createEmbed };
11
- //# sourceMappingURL=util.builders.js.map
12
- //# sourceMappingURL=util.builders.js.map
11
+ //# sourceMappingURL=utility.builders.js.map
12
+ //# sourceMappingURL=utility.builders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/features/builders/utility.builders.ts"],"names":[],"mappings":";;AAWO,SAAS,mBAA+D,QAAA,EAAe;AAC7F,EAAA,OAAO,IAAI,gBAAA,EAAoB,CAAE,aAAA,CAAc,GAAG,QAAQ,CAAA;AAC3D;AAKO,SAAS,YAAY,IAAA,EAA6B;AACxD,EAAA,OAAO,IAAI,aAAa,IAAI,CAAA;AAC7B","file":"utility.builders.js","sourcesContent":["import {\n\tActionRowBuilder,\n\tAPIEmbed,\n\tEmbedBuilder,\n\tEmbedData,\n\tMessageActionRowComponentBuilder,\n} from \"discord.js\";\n\n/**\n * Utility action row builder\n */\nexport function createActionRow<T extends MessageActionRowComponentBuilder>(...builders: T[]) {\n\treturn new ActionRowBuilder<T>().setComponents(...builders);\n}\n\n/**\n * Utility embed builder\n */\nexport function createEmbed(data?: EmbedData | APIEmbed) {\n\treturn new EmbedBuilder(data);\n}\n"]}
@@ -0,0 +1,85 @@
1
+ import { ClientOptions } from 'discord.js';
2
+
3
+ /**
4
+ * Login credentials for the Discord application
5
+ *
6
+ * @param token Environment variable name for bot token
7
+ * @param clientId Environment variable name for bot client ID
8
+ */
9
+ interface TriviousClientCredentials {
10
+ tokenReference: string;
11
+ clientIdReference: string;
12
+ }
13
+ /**
14
+ * Base interface for project structure
15
+ *
16
+ * @param useTypeBasedStructure Whether to use type-based structure or not
17
+ */
18
+ interface TriviousStructure {
19
+ useTypeBasedStructure: boolean;
20
+ }
21
+ /**
22
+ * Type-based project structure configuration
23
+ *
24
+ * Everything is inside `src/core`; `src/core/commands`, `src/core/event`...
25
+ *
26
+ * Directory names of course can be different, but the default expected names are used unless configured otherwise by the user
27
+ *
28
+ * @param useTypeBasedStructure Identify as type-based structure
29
+ * @param corePath The path to the **core** directory
30
+ * @param commandsPath The path to the **commands** directory
31
+ * @param componentsPath The path to the **components** directory
32
+ * @param eventsPath The path to the **components** directory
33
+ * @param modulesPath The path to the **module** directory
34
+ */
35
+ interface TypeBasedStructure extends TriviousStructure {
36
+ useTypeBasedStructure: true;
37
+ corePath: string;
38
+ commandsPath?: string;
39
+ componentPath?: string;
40
+ eventsPath?: string;
41
+ modulesPath?: string;
42
+ }
43
+ /**
44
+ * Feature-based structure configuration
45
+ *
46
+ * Everything is inside `src/features`; `src/features/moderation` and further; `src/features/moderation/commands/ban/index.ts`
47
+ *
48
+ * Feature directories are expected to contain command, component, event, and module directories.
49
+ * Though event and module directories remain optionally supported in the core path.
50
+ *
51
+ * @param useTypeBasedStructure Identify as feature-based structure
52
+ * @param featuresPath The path to the **features** directory
53
+ * @param corePath The path to the **core** directory - Commands and Components are NOT supported in this structure
54
+ */
55
+ interface FeatureBasedStructure extends TriviousStructure {
56
+ useTypeBasedStructure: false;
57
+ featuresPath: string;
58
+ corePath?: string;
59
+ }
60
+ /**
61
+ * Command hash configuration for automatic command deployment
62
+ *
63
+ * @param enabled Whether this feature is enabled
64
+ * @param persistentDataPath The path to store the command hash, this should be persistent so the feature works as intended
65
+ */
66
+ interface CommandHashConfiguration {
67
+ enabled: boolean;
68
+ persistentDataPath: string;
69
+ }
70
+ /**
71
+ * Trivious client options
72
+ *
73
+ * @param credentials Bot login credentials
74
+ * @param structurePaths Chosen project structure and relevant paths
75
+ * @param ownerUserIds Discord user IDs of bot owner(s)
76
+ * @param commandHashConfig Command auto-deployment configuration
77
+ */
78
+ interface TriviousClientOptions extends ClientOptions {
79
+ credentials: TriviousClientCredentials;
80
+ corePath: string;
81
+ ownerUserIds?: string[];
82
+ commandHashConfig?: CommandHashConfiguration;
83
+ }
84
+
85
+ export type { CommandHashConfiguration, FeatureBasedStructure, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure };
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=client.types.js.map
3
+ //# sourceMappingURL=client.types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"client.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"client.types.js"}
@@ -0,0 +1,7 @@
1
+ import { T as TriviousClient } from '../../modules.types-4hfuUiCb.js';
2
+ import 'discord.js';
3
+ import './client.types.js';
4
+
5
+ declare function commandDeploy(client: TriviousClient): Promise<void>;
6
+
7
+ export { commandDeploy as default };
@@ -0,0 +1,43 @@
1
+ import { createHash } from 'crypto';
2
+ import { REST, Routes } from 'discord.js';
3
+ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs';
4
+ import { join, dirname } from 'path';
5
+ import { TriviousError } from '../../utility/errors.js';
6
+
7
+ async function commandDeploy(client) {
8
+ const { commandHashConfig } = client.trivious;
9
+ const clientId = process.env[client.trivious.credentials.clientIdReference];
10
+ const token = process.env[client.trivious.credentials.tokenReference];
11
+ if (!clientId || !token)
12
+ throw new TriviousError("Invalid clientId or token environment variable");
13
+ const commands = client.stores.commands;
14
+ const body = [
15
+ ...commands.chatInput.map((command) => command.data.toJSON()),
16
+ ...commands.context.map(
17
+ (command) => command.data.toJSON()
18
+ )
19
+ ];
20
+ if (commandHashConfig && commandHashConfig.enabled) {
21
+ const hashFile = join(commandHashConfig.persistentDataPath || "data", "commands.hash");
22
+ const newHash = createHash("sha256").update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString()).digest("hex");
23
+ let oldHash = "";
24
+ if (existsSync(hashFile)) oldHash = readFileSync(hashFile, "utf-8");
25
+ if (newHash === oldHash) {
26
+ console.debug(`[Trivious] No changes in commands found, skipping deployment.`);
27
+ return;
28
+ }
29
+ const hashDirectory = dirname(hashFile);
30
+ if (!existsSync(hashDirectory)) {
31
+ mkdirSync(hashDirectory, { recursive: true });
32
+ }
33
+ writeFileSync(hashFile, newHash, { encoding: "utf-8" });
34
+ console.debug(`[Trivious] Created new command hash: ${hashFile}`);
35
+ }
36
+ const rest = new REST({ version: "10" }).setToken(token);
37
+ await rest.put(Routes.applicationCommands(clientId), { body });
38
+ console.debug(`[Trivious] Deployed ${body.length} commands`);
39
+ }
40
+
41
+ export { commandDeploy as default };
42
+ //# sourceMappingURL=deploy.client.js.map
43
+ //# sourceMappingURL=deploy.client.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W,QAAQ,CAAA,EAAG,OAAA,GAAU,YAAA,CAAa,UAAU,OAAO,CAAA;AAElE,IAAA,IAAI,YAAY,OAAA,EAAS;AACxB,MAAA,OAAA,CAAQ,MAAM,CAAA,6DAAA,CAA+D,CAAA;AAC7E,MAAA;AAAA,IACD;AAEA,IAAA,MAAM,aAAA,GAAgB,QAAQ,QAAQ,CAAA;AACtC,IAAA,IAAI,CAAC,UAAA,CAAW,aAAa,CAAA,EAAG;AAC/B,MAAA,SAAA,CAAU,aAAA,EAAe,EAAE,SAAA,EAAW,IAAA,EAAM,CAAA;AAAA,IAC7C;AAEA,IAAA,aAAA,CAAc,QAAA,EAAU,OAAA,EAAS,EAAE,QAAA,EAAU,SAAS,CAAA;AACtD,IAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,qCAAA,EAAwC,QAAQ,CAAA,CAAE,CAAA;AAAA,EACjE;AAEA,EAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK,EAAE,SAAS,IAAA,EAAM,CAAA,CAAE,QAAA,CAAS,KAAK,CAAA;AACvD,EAAA,MAAM,IAAA,CAAK,IAAI,MAAA,CAAO,mBAAA,CAAoB,QAAQ,CAAA,EAAG,EAAE,MAAM,CAAA;AAC7D,EAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,oBAAA,EAAuB,IAAA,CAAK,MAAM,CAAA,SAAA,CAAW,CAAA;AAC5D","file":"deploy.client.js","sourcesContent":["import { createHash } from \"crypto\";\nimport { REST, Routes } from \"discord.js\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { TriviousError } from \"src/utility/errors.js\";\nimport { MessageCommandData, UserCommandData } from \"../commands/commands.types.js\";\nimport TriviousClient from \"./trivious.client.js\";\n\nexport default async function commandDeploy(client: TriviousClient) {\n\tconst { commandHashConfig } = client.trivious;\n\n\tconst clientId = process.env[client.trivious.credentials.clientIdReference];\n\tconst token = process.env[client.trivious.credentials.tokenReference];\n\tif (!clientId || !token)\n\t\tthrow new TriviousError(\"Invalid clientId or token environment variable\");\n\n\tconst commands = client.stores.commands;\n\tconst body = [\n\t\t...commands.chatInput.map((command) => command.data.toJSON()),\n\t\t...commands.context.map((command) =>\n\t\t\t(command as UserCommandData | MessageCommandData).data.toJSON()\n\t\t),\n\t];\n\n\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\tconst hashFile = join(commandHashConfig.persistentDataPath || \"data\", \"commands.hash\");\n\t\tconst newHash = createHash(\"sha256\")\n\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t.digest(\"hex\");\n\n\t\tlet oldHash = \"\";\n\t\tif (existsSync(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\n\t\tif (newHash === oldHash) {\n\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment.`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst hashDirectory = dirname(hashFile);\n\t\tif (!existsSync(hashDirectory)) {\n\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t}\n\n\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t}\n\n\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\tconsole.debug(`[Trivious] Deployed ${body.length} commands`);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import 'discord.js';
2
+ import './client.types.js';
3
+ export { T as default } from '../../modules.types-4hfuUiCb.js';
@@ -0,0 +1,61 @@
1
+ import { Client, Collection } from 'discord.js';
2
+ import registries from '../../shared/registries.js';
3
+ import structure from '../structure/index.structure.js';
4
+ import { TriviousError } from '../../utility/errors.js';
5
+ import commandDeploy from './deploy.client.js';
6
+
7
+ class TriviousClient extends Client {
8
+ trivious;
9
+ stores;
10
+ constructor(options) {
11
+ super(options);
12
+ this.trivious = options;
13
+ this.stores = {
14
+ commands: {
15
+ chatInput: new Collection(),
16
+ context: new Collection()
17
+ },
18
+ components: new Collection(),
19
+ events: new Collection(),
20
+ modules: new Collection()
21
+ };
22
+ }
23
+ /**
24
+ * Register, deploy and log into the bot.
25
+ *
26
+ * @throws {TriviousError} If invalid bot token
27
+ */
28
+ async start() {
29
+ const token = process.env[this.trivious.credentials.tokenReference];
30
+ if (!token) {
31
+ throw new TriviousError(
32
+ `Bot token environment variable '${this.trivious.credentials.tokenReference}' does not exist!`,
33
+ "Null environment variable"
34
+ );
35
+ }
36
+ await this.register();
37
+ await this.deploy();
38
+ try {
39
+ await registries.events.bind(this);
40
+ await registries.modules.bind(this);
41
+ } catch (err) {
42
+ const error = new TriviousError(err.message, "Error during events and modules binds");
43
+ console.error(error);
44
+ }
45
+ await this.login(token);
46
+ }
47
+ async register() {
48
+ const dir = structure.resolveRelativePath(this.trivious.corePath);
49
+ await registries.events.register(this, dir);
50
+ await registries.modules.register(this, dir);
51
+ await registries.commands.register(this, dir);
52
+ await registries.components.register(this, dir);
53
+ }
54
+ async deploy() {
55
+ await commandDeploy(this);
56
+ }
57
+ }
58
+
59
+ export { TriviousClient as default };
60
+ //# sourceMappingURL=trivious.client.js.map
61
+ //# sourceMappingURL=trivious.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/features/client/trivious.client.ts"],"names":[],"mappings":";;;;;;AAeA,MAAO,uBAAqC,MAAA,CAAO;AAAA,EAClD,QAAA;AAAA,EACS,MAAA;AAAA,EAUT,YAAY,OAAA,EAAgC;AAC3C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAEhB,IAAA,IAAA,CAAK,MAAA,GAAS;AAAA,MACb,QAAA,EAAU;AAAA,QACT,SAAA,EAAW,IAAI,UAAA,EAAW;AAAA,QAC1B,OAAA,EAAS,IAAI,UAAA;AAAW,OACzB;AAAA,MACA,UAAA,EAAY,IAAI,UAAA,EAAW;AAAA,MAC3B,MAAA,EAA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;AAC5C,IAAA,MAAM,UAAA,CAAW,UAAA,CAAW,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAAA,EAC/C;AAAA,EAEA,MAAM,MAAA,GAAS;AACd,IAAA,MAAM,cAAc,IAAI,CAAA;AAAA,EACzB;AACD","file":"trivious.client.js","sourcesContent":["import { Client, Collection } from \"discord.js\";\nimport registries from \"src/shared/registries.js\";\nimport structure from \"../structure/index.structure.js\";\n\nimport type {\n\tBaseContextCommandData,\n\tComponent,\n\tEvent,\n\tModule,\n\tSlashCommandData,\n\tTriviousClientOptions,\n} from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport commandDeploy from \"./deploy.client.js\";\n\nexport default class TriviousClient extends Client {\n\ttrivious: TriviousClientOptions;\n\treadonly stores: {\n\t\tcommands: {\n\t\t\tchatInput: Collection<string, SlashCommandData>;\n\t\t\tcontext: Collection<string, BaseContextCommandData>;\n\t\t};\n\t\tcomponents: Collection<string, Component>;\n\t\tevents: Collection<string, Event>;\n\t\tmodules: Collection<string, Module>;\n\t};\n\n\tconstructor(options: TriviousClientOptions) {\n\t\tsuper(options);\n\t\tthis.trivious = options;\n\n\t\tthis.stores = {\n\t\t\tcommands: {\n\t\t\t\tchatInput: new Collection(),\n\t\t\t\tcontext: new Collection(),\n\t\t\t},\n\t\t\tcomponents: new Collection(),\n\t\t\tevents: new Collection(),\n\t\t\tmodules: new Collection(),\n\t\t};\n\t}\n\n\t/**\n\t * Register, deploy and log into the bot.\n\t *\n\t * @throws {TriviousError} If invalid bot token\n\t */\n\tasync start() {\n\t\tconst token = process.env[this.trivious.credentials.tokenReference];\n\t\tif (!token) {\n\t\t\tthrow new TriviousError(\n\t\t\t\t`Bot token environment variable '${this.trivious.credentials.tokenReference}' does not exist!`,\n\t\t\t\t\"Null environment variable\"\n\t\t\t);\n\t\t}\n\n\t\tawait this.register();\n\t\tawait this.deploy();\n\n\t\ttry {\n\t\t\tawait registries.events.bind(this);\n\t\t\tawait registries.modules.bind(this);\n\t\t} catch (err: any) {\n\t\t\tconst error = new TriviousError(err.message, \"Error during events and modules binds\");\n\t\t\tconsole.error(error);\n\t\t}\n\n\t\tawait this.login(token);\n\t}\n\n\tasync register() {\n\t\tconst dir = structure.resolveRelativePath(this.trivious.corePath);\n\n\t\tawait registries.events.register(this, dir);\n\t\tawait registries.modules.register(this, dir);\n\t\tawait registries.commands.register(this, dir);\n\t\tawait registries.components.register(this, dir);\n\t}\n\n\tasync deploy() {\n\t\tawait commandDeploy(this);\n\t}\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import 'discord.js';
2
+ export { B as BaseChatInputCommandData, a as BaseCommandData, b as BaseContextCommandData, C as ChatInputCommandContext, c as ChatInputCommandFunction, d as CommandFlags, i as ContextCommandData, j as ContextMenuCommandFunction, M as MessageCommandData, S as SlashCommandData, l as SlashSubcommandData, m as SlashSubcommandGroupData, U as UserCommandData } from '../../modules.types-4hfuUiCb.js';
3
+ import '../client/client.types.js';
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=commands.types.js.map
3
+ //# sourceMappingURL=commands.types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"commands.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"commands.types.js"}
@@ -0,0 +1,13 @@
1
+ import * as discord_js from 'discord.js';
2
+ import { ChatInputCommandInteraction, Interaction, CacheType, InteractionReplyOptions, InteractionEditReplyOptions, MessagePayload } from 'discord.js';
3
+ import { T as TriviousClient, S as SlashCommandData, d as CommandFlags } from '../../modules.types-4hfuUiCb.js';
4
+ import '../client/client.types.js';
5
+
6
+ declare function interactionReply(options: {
7
+ interaction: Interaction<CacheType>;
8
+ replyPayload: InteractionReplyOptions | InteractionEditReplyOptions | MessagePayload;
9
+ flags?: (CommandFlags | "FollowUp")[];
10
+ }): Promise<discord_js.Message<boolean> | discord_js.InteractionResponse<boolean> | undefined>;
11
+ declare function handleSlashCommand(client: TriviousClient, command: SlashCommandData, interaction: ChatInputCommandInteraction): Promise<void>;
12
+
13
+ export { handleSlashCommand, interactionReply };
@@ -0,0 +1,70 @@
1
+ async function interactionReply(options) {
2
+ const { interaction, replyPayload, flags } = options;
3
+ if (!("reply" in interaction)) return;
4
+ const payload = replyPayload;
5
+ if (flags?.includes("EphemeralReply")) payload.flags = ["Ephemeral"];
6
+ if (interaction.deferred || interaction.replied) {
7
+ if (flags?.includes("FollowUp")) return await interaction.followUp(payload);
8
+ return await interaction.editReply(payload);
9
+ }
10
+ return await interaction.reply(payload);
11
+ }
12
+ async function handleSlashCommand(client, command, interaction) {
13
+ const { options } = interaction;
14
+ if (command.flags?.includes("Cached") && !interaction.inCachedGuild()) return;
15
+ if (command.flags?.includes("ExpectModal")) return;
16
+ if (command.flags?.includes("DeferReply")) {
17
+ await interactionReply({
18
+ interaction,
19
+ flags: command.flags,
20
+ replyPayload: { content: "Processing command..." }
21
+ });
22
+ }
23
+ if ("run" in command && command.run) {
24
+ try {
25
+ await command.run(client, interaction);
26
+ } catch (err) {
27
+ console.error(err);
28
+ }
29
+ }
30
+ const subcommandGroup = options.getSubcommandGroup(false);
31
+ const subcommand = options.getSubcommand(false);
32
+ if (subcommandGroup && command.subcommandGroups && subcommand) {
33
+ const foundGroup = command.subcommandGroups.get(subcommandGroup);
34
+ if (!foundGroup) {
35
+ await interactionReply({
36
+ interaction,
37
+ flags: ["EphemeralReply"],
38
+ replyPayload: {
39
+ content: "Subcommand group is outdated, inactive, or does not have a handler!"
40
+ }
41
+ });
42
+ return;
43
+ }
44
+ const foundSubcommand = foundGroup.subcommands.get(subcommand);
45
+ if (!foundSubcommand) {
46
+ await interactionReply({
47
+ interaction,
48
+ flags: ["EphemeralReply"],
49
+ replyPayload: { content: "Subcommand is outdated, inactive, or does not have a handler!" }
50
+ });
51
+ return;
52
+ }
53
+ return await foundSubcommand.execute(client, interaction);
54
+ } else if (subcommand && command.subcommands) {
55
+ const foundSubcommand = command.subcommands.get(subcommand);
56
+ if (!foundSubcommand) {
57
+ await interactionReply({
58
+ interaction,
59
+ flags: ["EphemeralReply"],
60
+ replyPayload: { content: "Subcommand is outdated, inactive, or does not have a handler!" }
61
+ });
62
+ return;
63
+ }
64
+ return await foundSubcommand.execute(client, interaction);
65
+ }
66
+ }
67
+
68
+ export { handleSlashCommand, interactionReply };
69
+ //# sourceMappingURL=methods.commands.js.map
70
+ //# sourceMappingURL=methods.commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/features/commands/methods.commands.ts"],"names":[],"mappings":"AAUA,eAAsB,iBAAiB,OAAA,EAIpC;AACF,EAAA,MAAM,EAAE,WAAA,EAAa,YAAA,EAAc,KAAA,EAAM,GAAI,OAAA;AAC7C,EAAA,IAAI,EAAE,WAAW,WAAA,CAAA,EAAc;AAE/B,EAAA,MAAM,OAAA,GAAU,YAAA;AAChB,EAAA,IAAI,OAAO,QAAA,CAAS,gBAAgB,GAAG,OAAA,CAAQ,KAAA,GAAQ,CAAC,WAAW,CAAA;AAEnE,EAAA,IAAI,WAAA,CAAY,QAAA,IAAY,WAAA,CAAY,OAAA,EAAS;AAChD,IAAA,IAAI,KAAA,EAAO,SAAS,UAAU,CAAA,SAAU,MAAM,WAAA,CAAY,SAAS,OAAO,CAAA;AAC1E,IAAA,OAAO,MAAM,WAAA,CAAY,SAAA,CAAU,OAAsC,CAAA;AAAA,EAC1E;AAEA,EAAA,OAAO,MAAM,WAAA,CAAY,KAAA,CAAM,OAAO,CAAA;AACvC;AAEA,eAAsB,kBAAA,CACrB,MAAA,EACA,OAAA,EACA,WAAA,EACC;AACD,EAAA,MAAM,EAAE,SAAQ,GAAI,WAAA;AAEpB,EAAA,IAAI,OAAA,CAAQ,OAAO,QAAA,CAAS,QAAQ,KAAK,CAAC,WAAA,CAAY,eAAc,EAAG;AACvE,EAAA,IAAI,OAAA,CAAQ,KAAA,EAAO,QAAA,CAAS,aAAa,CAAA,EAAG;AAC5C,EAAA,IAAI,OAAA,CAAQ,KAAA,EAAO,QAA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AAA;AACD,MAAA;AAAA,IACD;AAEA,IAAA,OAAO,MAAM,eAAA,CAAgB,OAAA,CAAQ,MAAA,EAAQ,WAAW,CAAA;AAAA,EACzD,CAAA,MAAA,IAAW,UAAA,IAAc,OAAA,CAAQ,WAAA,EAAa;AAC7C,IAAA,MAAM,eAAA,GAAkB,OAAA,CAAQ,WAAA,CAAY,GAAA,CAAI,UAAU,CAAA;AAC1D,IAAA,IAAI,CAAC,eAAA,EAAiB;AACrB,MAAA,MAAM,gBAAA,CAAiB;AAAA,QACtB,WAAA;AAAA,QACA,KAAA,EAAO,CAAC,gBAAgB,CAAA;AAAA,QACxB,YAAA,EAAc,EAAE,OAAA,EAAS,+DAAA;AAAgE,OACzF,CAAA;AACD,MAAA;AAAA,IACD;AAEA,IAAA,OAAO,MAAM,eAAA,CAAgB,OAAA,CAAQ,MAAA,EAAQ,WAAW,CAAA;AAAA,EACzD;AACD","file":"methods.commands.js","sourcesContent":["import type {\n\tCacheType,\n\tChatInputCommandInteraction,\n\tInteraction,\n\tInteractionEditReplyOptions,\n\tInteractionReplyOptions,\n\tMessagePayload,\n} from \"discord.js\";\nimport type { CommandFlags, SlashCommandData, TriviousClient } from \"#typings\";\n\nexport async function interactionReply(options: {\n\tinteraction: Interaction<CacheType>;\n\treplyPayload: InteractionReplyOptions | InteractionEditReplyOptions | MessagePayload;\n\tflags?: (CommandFlags | \"FollowUp\")[];\n}) {\n\tconst { interaction, replyPayload, flags } = options;\n\tif (!(\"reply\" in interaction)) return;\n\n\tconst payload = replyPayload as InteractionReplyOptions;\n\tif (flags?.includes(\"EphemeralReply\")) payload.flags = [\"Ephemeral\"];\n\n\tif (interaction.deferred || interaction.replied) {\n\t\tif (flags?.includes(\"FollowUp\")) return await interaction.followUp(payload);\n\t\treturn await interaction.editReply(payload as InteractionEditReplyOptions);\n\t}\n\n\treturn await interaction.reply(payload);\n}\n\nexport async function handleSlashCommand(\n\tclient: TriviousClient,\n\tcommand: SlashCommandData,\n\tinteraction: ChatInputCommandInteraction\n) {\n\tconst { options } = interaction;\n\n\tif (command.flags?.includes(\"Cached\") && !interaction.inCachedGuild()) return;\n\tif (command.flags?.includes(\"ExpectModal\")) return;\n\tif (command.flags?.includes(\"DeferReply\")) {\n\t\tawait interactionReply({\n\t\t\tinteraction,\n\t\t\tflags: command.flags,\n\t\t\treplyPayload: { content: \"Processing command...\" },\n\t\t});\n\t}\n\n\tif (\"run\" in command && command.run) {\n\t\ttry {\n\t\t\tawait command.run(client, interaction);\n\t\t} catch (err: any) {\n\t\t\tconsole.error(err);\n\t\t}\n\t}\n\n\tconst subcommandGroup = options.getSubcommandGroup(false);\n\tconst subcommand = options.getSubcommand(false);\n\n\tif (subcommandGroup && command.subcommandGroups && subcommand) {\n\t\tconst foundGroup = command.subcommandGroups.get(subcommandGroup);\n\t\tif (!foundGroup) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: {\n\t\t\t\t\tcontent: \"Subcommand group is outdated, inactive, or does not have a handler!\",\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst foundSubcommand = foundGroup.subcommands.get(subcommand);\n\t\tif (!foundSubcommand) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: { content: \"Subcommand is outdated, inactive, or does not have a handler!\" },\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\treturn await foundSubcommand.execute(client, interaction);\n\t} else if (subcommand && command.subcommands) {\n\t\tconst foundSubcommand = command.subcommands.get(subcommand);\n\t\tif (!foundSubcommand) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: { content: \"Subcommand is outdated, inactive, or does not have a handler!\" },\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\treturn await foundSubcommand.execute(client, interaction);\n\t}\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import { T as TriviousClient } from '../../modules.types-4hfuUiCb.js';
2
+ import 'discord.js';
3
+ import '../client/client.types.js';
4
+
5
+ declare function registerCommands(client: TriviousClient, directory: string): Promise<void>;
6
+
7
+ export { registerCommands as default };