trivious 1.3.21 → 1.3.23

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 (129) hide show
  1. package/dist/index.cjs +1443 -67
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +979 -3
  4. package/dist/index.d.ts +979 -3
  5. package/dist/index.js +1432 -10
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/dist/core/client/trivious.client.cjs +0 -90
  9. package/dist/core/client/trivious.client.cjs.map +0 -1
  10. package/dist/core/client/trivious.client.d.cts +0 -3
  11. package/dist/core/client/trivious.client.d.ts +0 -3
  12. package/dist/core/client/trivious.client.js +0 -88
  13. package/dist/core/client/trivious.client.js.map +0 -1
  14. package/dist/core/commands/command.base.cjs +0 -224
  15. package/dist/core/commands/command.base.cjs.map +0 -1
  16. package/dist/core/commands/command.base.d.cts +0 -3
  17. package/dist/core/commands/command.base.d.ts +0 -3
  18. package/dist/core/commands/command.base.js +0 -214
  19. package/dist/core/commands/command.base.js.map +0 -1
  20. package/dist/core/commands/contextcommand.base.cjs +0 -98
  21. package/dist/core/commands/contextcommand.base.cjs.map +0 -1
  22. package/dist/core/commands/contextcommand.base.d.cts +0 -3
  23. package/dist/core/commands/contextcommand.base.d.ts +0 -3
  24. package/dist/core/commands/contextcommand.base.js +0 -93
  25. package/dist/core/commands/contextcommand.base.js.map +0 -1
  26. package/dist/core/commands/subcommand.base.cjs +0 -96
  27. package/dist/core/commands/subcommand.base.cjs.map +0 -1
  28. package/dist/core/commands/subcommand.base.d.cts +0 -3
  29. package/dist/core/commands/subcommand.base.d.ts +0 -3
  30. package/dist/core/commands/subcommand.base.js +0 -91
  31. package/dist/core/commands/subcommand.base.js.map +0 -1
  32. package/dist/core/components/component.base.cjs +0 -111
  33. package/dist/core/components/component.base.cjs.map +0 -1
  34. package/dist/core/components/component.base.d.cts +0 -3
  35. package/dist/core/components/component.base.d.ts +0 -3
  36. package/dist/core/components/component.base.js +0 -106
  37. package/dist/core/components/component.base.js.map +0 -1
  38. package/dist/core/events/interactionCreate.cjs +0 -68
  39. package/dist/core/events/interactionCreate.cjs.map +0 -1
  40. package/dist/core/events/interactionCreate.d.cts +0 -10
  41. package/dist/core/events/interactionCreate.d.ts +0 -10
  42. package/dist/core/events/interactionCreate.js +0 -66
  43. package/dist/core/events/interactionCreate.js.map +0 -1
  44. package/dist/core/registry/command.registry.cjs +0 -56
  45. package/dist/core/registry/command.registry.cjs.map +0 -1
  46. package/dist/core/registry/command.registry.d.cts +0 -3
  47. package/dist/core/registry/command.registry.d.ts +0 -3
  48. package/dist/core/registry/command.registry.js +0 -54
  49. package/dist/core/registry/command.registry.js.map +0 -1
  50. package/dist/core/registry/component.registry.cjs +0 -42
  51. package/dist/core/registry/component.registry.cjs.map +0 -1
  52. package/dist/core/registry/component.registry.d.cts +0 -3
  53. package/dist/core/registry/component.registry.d.ts +0 -3
  54. package/dist/core/registry/component.registry.js +0 -40
  55. package/dist/core/registry/component.registry.js.map +0 -1
  56. package/dist/core/registry/event.registry.cjs +0 -57
  57. package/dist/core/registry/event.registry.cjs.map +0 -1
  58. package/dist/core/registry/event.registry.d.cts +0 -3
  59. package/dist/core/registry/event.registry.d.ts +0 -3
  60. package/dist/core/registry/event.registry.js +0 -51
  61. package/dist/core/registry/event.registry.js.map +0 -1
  62. package/dist/core/registry/index.cjs +0 -49
  63. package/dist/core/registry/index.cjs.map +0 -1
  64. package/dist/core/registry/index.d.cts +0 -19
  65. package/dist/core/registry/index.d.ts +0 -19
  66. package/dist/core/registry/index.js +0 -39
  67. package/dist/core/registry/index.js.map +0 -1
  68. package/dist/core/registry/module.registry.cjs +0 -57
  69. package/dist/core/registry/module.registry.cjs.map +0 -1
  70. package/dist/core/registry/module.registry.d.cts +0 -3
  71. package/dist/core/registry/module.registry.d.ts +0 -3
  72. package/dist/core/registry/module.registry.js +0 -55
  73. package/dist/core/registry/module.registry.js.map +0 -1
  74. package/dist/index-BPaYmWRO.d.ts +0 -927
  75. package/dist/index-CU2Xl9Xo.d.cts +0 -927
  76. package/dist/shared/typings/client.cjs +0 -4
  77. package/dist/shared/typings/client.cjs.map +0 -1
  78. package/dist/shared/typings/client.d.cts +0 -3
  79. package/dist/shared/typings/client.d.ts +0 -3
  80. package/dist/shared/typings/client.js +0 -3
  81. package/dist/shared/typings/client.js.map +0 -1
  82. package/dist/shared/typings/commands.cjs +0 -4
  83. package/dist/shared/typings/commands.cjs.map +0 -1
  84. package/dist/shared/typings/commands.d.cts +0 -3
  85. package/dist/shared/typings/commands.d.ts +0 -3
  86. package/dist/shared/typings/commands.js +0 -3
  87. package/dist/shared/typings/commands.js.map +0 -1
  88. package/dist/shared/typings/components.cjs +0 -22
  89. package/dist/shared/typings/components.cjs.map +0 -1
  90. package/dist/shared/typings/components.d.cts +0 -3
  91. package/dist/shared/typings/components.d.ts +0 -3
  92. package/dist/shared/typings/components.js +0 -19
  93. package/dist/shared/typings/components.js.map +0 -1
  94. package/dist/shared/typings/events.cjs +0 -4
  95. package/dist/shared/typings/events.cjs.map +0 -1
  96. package/dist/shared/typings/events.d.cts +0 -3
  97. package/dist/shared/typings/events.d.ts +0 -3
  98. package/dist/shared/typings/events.js +0 -3
  99. package/dist/shared/typings/events.js.map +0 -1
  100. package/dist/shared/typings/index.cjs +0 -56
  101. package/dist/shared/typings/index.cjs.map +0 -1
  102. package/dist/shared/typings/index.d.cts +0 -3
  103. package/dist/shared/typings/index.d.ts +0 -3
  104. package/dist/shared/typings/index.js +0 -9
  105. package/dist/shared/typings/index.js.map +0 -1
  106. package/dist/shared/typings/module.cjs +0 -4
  107. package/dist/shared/typings/module.cjs.map +0 -1
  108. package/dist/shared/typings/module.d.cts +0 -3
  109. package/dist/shared/typings/module.d.ts +0 -3
  110. package/dist/shared/typings/module.js +0 -3
  111. package/dist/shared/typings/module.js.map +0 -1
  112. package/dist/shared/typings/permissions.cjs +0 -22
  113. package/dist/shared/typings/permissions.cjs.map +0 -1
  114. package/dist/shared/typings/permissions.d.cts +0 -3
  115. package/dist/shared/typings/permissions.d.ts +0 -3
  116. package/dist/shared/typings/permissions.js +0 -19
  117. package/dist/shared/typings/permissions.js.map +0 -1
  118. package/dist/shared/typings/registry.cjs +0 -63
  119. package/dist/shared/typings/registry.cjs.map +0 -1
  120. package/dist/shared/typings/registry.d.cts +0 -51
  121. package/dist/shared/typings/registry.d.ts +0 -51
  122. package/dist/shared/typings/registry.js +0 -61
  123. package/dist/shared/typings/registry.js.map +0 -1
  124. package/dist/shared/utility/functions.cjs +0 -81
  125. package/dist/shared/utility/functions.cjs.map +0 -1
  126. package/dist/shared/utility/functions.d.cts +0 -56
  127. package/dist/shared/utility/functions.d.ts +0 -56
  128. package/dist/shared/utility/functions.js +0 -74
  129. package/dist/shared/utility/functions.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,12 +1,1434 @@
1
- import 'dotenv/config';
2
- import 'node:util';
3
- export { default as TriviousClient } from './core/client/trivious.client.js';
4
- export { default as Command, CommandBuilder, SlashCommand } from './core/commands/command.base.js';
5
- export { default as Subcommand, SubcommandBuilder } from './core/commands/subcommand.base.js';
6
- export { ContextMenuBuilder, default as ContextMenuCommand } from './core/commands/contextcommand.base.js';
7
- export { default as CommandRegistry } from './core/registry/command.registry.js';
8
- export { default as Component, ComponentBuilder } from './core/components/component.base.js';
9
- export { default as ComponentRegistry } from './core/registry/component.registry.js';
10
- export * from './shared/typings/index.js';
1
+ import 'util';
2
+ import { Collection, SlashCommandSubcommandBuilder, Client, REST, Routes, SlashCommandBuilder, ContextMenuCommandBuilder, InteractionContextType, ButtonInteraction, ModalSubmitInteraction } from 'discord.js';
3
+ import { existsSync, promises } from 'fs';
4
+ import path, { dirname, join, resolve } from 'path';
5
+ import { fileURLToPath, pathToFileURL } from 'url';
6
+
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+
18
+ // node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/package.json
19
+ var require_package = __commonJS({
20
+ "node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/package.json"(exports$1, module) {
21
+ module.exports = {
22
+ name: "dotenv",
23
+ version: "17.2.3",
24
+ description: "Loads environment variables from .env file",
25
+ main: "lib/main.js",
26
+ types: "lib/main.d.ts",
27
+ exports: {
28
+ ".": {
29
+ types: "./lib/main.d.ts",
30
+ require: "./lib/main.js",
31
+ default: "./lib/main.js"
32
+ },
33
+ "./config": "./config.js",
34
+ "./config.js": "./config.js",
35
+ "./lib/env-options": "./lib/env-options.js",
36
+ "./lib/env-options.js": "./lib/env-options.js",
37
+ "./lib/cli-options": "./lib/cli-options.js",
38
+ "./lib/cli-options.js": "./lib/cli-options.js",
39
+ "./package.json": "./package.json"
40
+ },
41
+ scripts: {
42
+ "dts-check": "tsc --project tests/types/tsconfig.json",
43
+ lint: "standard",
44
+ pretest: "npm run lint && npm run dts-check",
45
+ test: "tap run tests/**/*.js --allow-empty-coverage --disable-coverage --timeout=60000",
46
+ "test:coverage": "tap run tests/**/*.js --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
47
+ prerelease: "npm test",
48
+ release: "standard-version"
49
+ },
50
+ repository: {
51
+ type: "git",
52
+ url: "git://github.com/motdotla/dotenv.git"
53
+ },
54
+ homepage: "https://github.com/motdotla/dotenv#readme",
55
+ funding: "https://dotenvx.com",
56
+ keywords: [
57
+ "dotenv",
58
+ "env",
59
+ ".env",
60
+ "environment",
61
+ "variables",
62
+ "config",
63
+ "settings"
64
+ ],
65
+ readmeFilename: "README.md",
66
+ license: "BSD-2-Clause",
67
+ devDependencies: {
68
+ "@types/node": "^18.11.3",
69
+ decache: "^4.6.2",
70
+ sinon: "^14.0.1",
71
+ standard: "^17.0.0",
72
+ "standard-version": "^9.5.0",
73
+ tap: "^19.2.0",
74
+ typescript: "^4.8.4"
75
+ },
76
+ engines: {
77
+ node: ">=12"
78
+ },
79
+ browser: {
80
+ fs: false
81
+ }
82
+ };
83
+ }
84
+ });
85
+
86
+ // node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/lib/main.js
87
+ var require_main = __commonJS({
88
+ "node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/lib/main.js"(exports$1, module) {
89
+ var fs6 = __require("fs");
90
+ var path2 = __require("path");
91
+ var os = __require("os");
92
+ var crypto = __require("crypto");
93
+ var packageJson = require_package();
94
+ var version = packageJson.version;
95
+ var TIPS = [
96
+ "\u{1F510} encrypt with Dotenvx: https://dotenvx.com",
97
+ "\u{1F510} prevent committing .env to code: https://dotenvx.com/precommit",
98
+ "\u{1F510} prevent building .env in docker: https://dotenvx.com/prebuild",
99
+ "\u{1F4E1} add observability to secrets: https://dotenvx.com/ops",
100
+ "\u{1F465} sync secrets across teammates & machines: https://dotenvx.com/ops",
101
+ "\u{1F5C2}\uFE0F backup and recover secrets: https://dotenvx.com/ops",
102
+ "\u2705 audit secrets and track compliance: https://dotenvx.com/ops",
103
+ "\u{1F504} add secrets lifecycle management: https://dotenvx.com/ops",
104
+ "\u{1F511} add access controls to secrets: https://dotenvx.com/ops",
105
+ "\u{1F6E0}\uFE0F run anywhere with `dotenvx run -- yourcommand`",
106
+ "\u2699\uFE0F specify custom .env file path with { path: '/custom/path/.env' }",
107
+ "\u2699\uFE0F enable debug logging with { debug: true }",
108
+ "\u2699\uFE0F override existing env vars with { override: true }",
109
+ "\u2699\uFE0F suppress all logs with { quiet: true }",
110
+ "\u2699\uFE0F write to custom object with { processEnv: myObject }",
111
+ "\u2699\uFE0F load multiple .env files with { path: ['.env.local', '.env'] }"
112
+ ];
113
+ function _getRandomTip() {
114
+ return TIPS[Math.floor(Math.random() * TIPS.length)];
115
+ }
116
+ function parseBoolean(value) {
117
+ if (typeof value === "string") {
118
+ return !["false", "0", "no", "off", ""].includes(value.toLowerCase());
119
+ }
120
+ return Boolean(value);
121
+ }
122
+ function supportsAnsi() {
123
+ return process.stdout.isTTY;
124
+ }
125
+ function dim(text) {
126
+ return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
127
+ }
128
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
129
+ function parse(src) {
130
+ const obj = {};
131
+ let lines = src.toString();
132
+ lines = lines.replace(/\r\n?/mg, "\n");
133
+ let match;
134
+ while ((match = LINE.exec(lines)) != null) {
135
+ const key = match[1];
136
+ let value = match[2] || "";
137
+ value = value.trim();
138
+ const maybeQuote = value[0];
139
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
140
+ if (maybeQuote === '"') {
141
+ value = value.replace(/\\n/g, "\n");
142
+ value = value.replace(/\\r/g, "\r");
143
+ }
144
+ obj[key] = value;
145
+ }
146
+ return obj;
147
+ }
148
+ function _parseVault(options) {
149
+ options = options || {};
150
+ const vaultPath = _vaultPath(options);
151
+ options.path = vaultPath;
152
+ const result = DotenvModule.configDotenv(options);
153
+ if (!result.parsed) {
154
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
155
+ err.code = "MISSING_DATA";
156
+ throw err;
157
+ }
158
+ const keys = _dotenvKey(options).split(",");
159
+ const length = keys.length;
160
+ let decrypted;
161
+ for (let i = 0; i < length; i++) {
162
+ try {
163
+ const key = keys[i].trim();
164
+ const attrs = _instructions(result, key);
165
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
166
+ break;
167
+ } catch (error) {
168
+ if (i + 1 >= length) {
169
+ throw error;
170
+ }
171
+ }
172
+ }
173
+ return DotenvModule.parse(decrypted);
174
+ }
175
+ function _warn(message) {
176
+ console.error(`[dotenv@${version}][WARN] ${message}`);
177
+ }
178
+ function _debug(message) {
179
+ console.log(`[dotenv@${version}][DEBUG] ${message}`);
180
+ }
181
+ function _log(message) {
182
+ console.log(`[dotenv@${version}] ${message}`);
183
+ }
184
+ function _dotenvKey(options) {
185
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
186
+ return options.DOTENV_KEY;
187
+ }
188
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
189
+ return process.env.DOTENV_KEY;
190
+ }
191
+ return "";
192
+ }
193
+ function _instructions(result, dotenvKey) {
194
+ let uri;
195
+ try {
196
+ uri = new URL(dotenvKey);
197
+ } catch (error) {
198
+ if (error.code === "ERR_INVALID_URL") {
199
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
200
+ err.code = "INVALID_DOTENV_KEY";
201
+ throw err;
202
+ }
203
+ throw error;
204
+ }
205
+ const key = uri.password;
206
+ if (!key) {
207
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
208
+ err.code = "INVALID_DOTENV_KEY";
209
+ throw err;
210
+ }
211
+ const environment = uri.searchParams.get("environment");
212
+ if (!environment) {
213
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
214
+ err.code = "INVALID_DOTENV_KEY";
215
+ throw err;
216
+ }
217
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
218
+ const ciphertext = result.parsed[environmentKey];
219
+ if (!ciphertext) {
220
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
221
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
222
+ throw err;
223
+ }
224
+ return { ciphertext, key };
225
+ }
226
+ function _vaultPath(options) {
227
+ let possibleVaultPath = null;
228
+ if (options && options.path && options.path.length > 0) {
229
+ if (Array.isArray(options.path)) {
230
+ for (const filepath of options.path) {
231
+ if (fs6.existsSync(filepath)) {
232
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
233
+ }
234
+ }
235
+ } else {
236
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
237
+ }
238
+ } else {
239
+ possibleVaultPath = path2.resolve(process.cwd(), ".env.vault");
240
+ }
241
+ if (fs6.existsSync(possibleVaultPath)) {
242
+ return possibleVaultPath;
243
+ }
244
+ return null;
245
+ }
246
+ function _resolveHome(envPath) {
247
+ return envPath[0] === "~" ? path2.join(os.homedir(), envPath.slice(1)) : envPath;
248
+ }
249
+ function _configVault(options) {
250
+ const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
251
+ const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
252
+ if (debug || !quiet) {
253
+ _log("Loading env from encrypted .env.vault");
254
+ }
255
+ const parsed = DotenvModule._parseVault(options);
256
+ let processEnv = process.env;
257
+ if (options && options.processEnv != null) {
258
+ processEnv = options.processEnv;
259
+ }
260
+ DotenvModule.populate(processEnv, parsed, options);
261
+ return { parsed };
262
+ }
263
+ function configDotenv(options) {
264
+ const dotenvPath = path2.resolve(process.cwd(), ".env");
265
+ let encoding = "utf8";
266
+ let processEnv = process.env;
267
+ if (options && options.processEnv != null) {
268
+ processEnv = options.processEnv;
269
+ }
270
+ let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
271
+ let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
272
+ if (options && options.encoding) {
273
+ encoding = options.encoding;
274
+ } else {
275
+ if (debug) {
276
+ _debug("No encoding is specified. UTF-8 is used by default");
277
+ }
278
+ }
279
+ let optionPaths = [dotenvPath];
280
+ if (options && options.path) {
281
+ if (!Array.isArray(options.path)) {
282
+ optionPaths = [_resolveHome(options.path)];
283
+ } else {
284
+ optionPaths = [];
285
+ for (const filepath of options.path) {
286
+ optionPaths.push(_resolveHome(filepath));
287
+ }
288
+ }
289
+ }
290
+ let lastError;
291
+ const parsedAll = {};
292
+ for (const path3 of optionPaths) {
293
+ try {
294
+ const parsed = DotenvModule.parse(fs6.readFileSync(path3, { encoding }));
295
+ DotenvModule.populate(parsedAll, parsed, options);
296
+ } catch (e) {
297
+ if (debug) {
298
+ _debug(`Failed to load ${path3} ${e.message}`);
299
+ }
300
+ lastError = e;
301
+ }
302
+ }
303
+ const populated = DotenvModule.populate(processEnv, parsedAll, options);
304
+ debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
305
+ quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
306
+ if (debug || !quiet) {
307
+ const keysCount = Object.keys(populated).length;
308
+ const shortPaths = [];
309
+ for (const filePath of optionPaths) {
310
+ try {
311
+ const relative = path2.relative(process.cwd(), filePath);
312
+ shortPaths.push(relative);
313
+ } catch (e) {
314
+ if (debug) {
315
+ _debug(`Failed to load ${filePath} ${e.message}`);
316
+ }
317
+ lastError = e;
318
+ }
319
+ }
320
+ _log(`injecting env (${keysCount}) from ${shortPaths.join(",")} ${dim(`-- tip: ${_getRandomTip()}`)}`);
321
+ }
322
+ if (lastError) {
323
+ return { parsed: parsedAll, error: lastError };
324
+ } else {
325
+ return { parsed: parsedAll };
326
+ }
327
+ }
328
+ function config(options) {
329
+ if (_dotenvKey(options).length === 0) {
330
+ return DotenvModule.configDotenv(options);
331
+ }
332
+ const vaultPath = _vaultPath(options);
333
+ if (!vaultPath) {
334
+ _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
335
+ return DotenvModule.configDotenv(options);
336
+ }
337
+ return DotenvModule._configVault(options);
338
+ }
339
+ function decrypt(encrypted, keyStr) {
340
+ const key = Buffer.from(keyStr.slice(-64), "hex");
341
+ let ciphertext = Buffer.from(encrypted, "base64");
342
+ const nonce = ciphertext.subarray(0, 12);
343
+ const authTag = ciphertext.subarray(-16);
344
+ ciphertext = ciphertext.subarray(12, -16);
345
+ try {
346
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
347
+ aesgcm.setAuthTag(authTag);
348
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
349
+ } catch (error) {
350
+ const isRange = error instanceof RangeError;
351
+ const invalidKeyLength = error.message === "Invalid key length";
352
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
353
+ if (isRange || invalidKeyLength) {
354
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
355
+ err.code = "INVALID_DOTENV_KEY";
356
+ throw err;
357
+ } else if (decryptionFailed) {
358
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
359
+ err.code = "DECRYPTION_FAILED";
360
+ throw err;
361
+ } else {
362
+ throw error;
363
+ }
364
+ }
365
+ }
366
+ function populate(processEnv, parsed, options = {}) {
367
+ const debug = Boolean(options && options.debug);
368
+ const override = Boolean(options && options.override);
369
+ const populated = {};
370
+ if (typeof parsed !== "object") {
371
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
372
+ err.code = "OBJECT_REQUIRED";
373
+ throw err;
374
+ }
375
+ for (const key of Object.keys(parsed)) {
376
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
377
+ if (override === true) {
378
+ processEnv[key] = parsed[key];
379
+ populated[key] = parsed[key];
380
+ }
381
+ if (debug) {
382
+ if (override === true) {
383
+ _debug(`"${key}" is already defined and WAS overwritten`);
384
+ } else {
385
+ _debug(`"${key}" is already defined and was NOT overwritten`);
386
+ }
387
+ }
388
+ } else {
389
+ processEnv[key] = parsed[key];
390
+ populated[key] = parsed[key];
391
+ }
392
+ }
393
+ return populated;
394
+ }
395
+ var DotenvModule = {
396
+ configDotenv,
397
+ _configVault,
398
+ _parseVault,
399
+ config,
400
+ decrypt,
401
+ parse,
402
+ populate
403
+ };
404
+ module.exports.configDotenv = DotenvModule.configDotenv;
405
+ module.exports._configVault = DotenvModule._configVault;
406
+ module.exports._parseVault = DotenvModule._parseVault;
407
+ module.exports.config = DotenvModule.config;
408
+ module.exports.decrypt = DotenvModule.decrypt;
409
+ module.exports.parse = DotenvModule.parse;
410
+ module.exports.populate = DotenvModule.populate;
411
+ module.exports = DotenvModule;
412
+ }
413
+ });
414
+
415
+ // node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/lib/env-options.js
416
+ var require_env_options = __commonJS({
417
+ "node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/lib/env-options.js"(exports$1, module) {
418
+ var options = {};
419
+ if (process.env.DOTENV_CONFIG_ENCODING != null) {
420
+ options.encoding = process.env.DOTENV_CONFIG_ENCODING;
421
+ }
422
+ if (process.env.DOTENV_CONFIG_PATH != null) {
423
+ options.path = process.env.DOTENV_CONFIG_PATH;
424
+ }
425
+ if (process.env.DOTENV_CONFIG_QUIET != null) {
426
+ options.quiet = process.env.DOTENV_CONFIG_QUIET;
427
+ }
428
+ if (process.env.DOTENV_CONFIG_DEBUG != null) {
429
+ options.debug = process.env.DOTENV_CONFIG_DEBUG;
430
+ }
431
+ if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
432
+ options.override = process.env.DOTENV_CONFIG_OVERRIDE;
433
+ }
434
+ if (process.env.DOTENV_CONFIG_DOTENV_KEY != null) {
435
+ options.DOTENV_KEY = process.env.DOTENV_CONFIG_DOTENV_KEY;
436
+ }
437
+ module.exports = options;
438
+ }
439
+ });
440
+
441
+ // node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/lib/cli-options.js
442
+ var require_cli_options = __commonJS({
443
+ "node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/lib/cli-options.js"(exports$1, module) {
444
+ var re = /^dotenv_config_(encoding|path|quiet|debug|override|DOTENV_KEY)=(.+)$/;
445
+ module.exports = function optionMatcher(args) {
446
+ const options = args.reduce(function(acc, cur) {
447
+ const matches = cur.match(re);
448
+ if (matches) {
449
+ acc[matches[1]] = matches[2];
450
+ }
451
+ return acc;
452
+ }, {});
453
+ if (!("quiet" in options)) {
454
+ options.quiet = "true";
455
+ }
456
+ return options;
457
+ };
458
+ }
459
+ });
460
+
461
+ // node_modules/.pnpm/dotenv@17.2.3/node_modules/dotenv/config.js
462
+ (function() {
463
+ require_main().config(
464
+ Object.assign(
465
+ {},
466
+ require_env_options(),
467
+ require_cli_options()(process.argv)
468
+ )
469
+ );
470
+ })();
471
+
472
+ // src/shared/typings/permissions.ts
473
+ var PermissionLevel = /* @__PURE__ */ ((PermissionLevel2) => {
474
+ PermissionLevel2[PermissionLevel2["USER"] = 0] = "USER";
475
+ PermissionLevel2[PermissionLevel2["GUILD_STAFF"] = 1] = "GUILD_STAFF";
476
+ PermissionLevel2[PermissionLevel2["GUILD_MODERATOR"] = 2] = "GUILD_MODERATOR";
477
+ PermissionLevel2[PermissionLevel2["GUILD_ADMINISTRATOR"] = 3] = "GUILD_ADMINISTRATOR";
478
+ PermissionLevel2[PermissionLevel2["GUILD_OWNER"] = 4] = "GUILD_OWNER";
479
+ PermissionLevel2[PermissionLevel2["BOT_OWNER"] = 5] = "BOT_OWNER";
480
+ return PermissionLevel2;
481
+ })(PermissionLevel || {});
482
+ var getPermissionLevel = (client, member) => {
483
+ const highestRole = member.roles.highest;
484
+ if (member.user.id === member.guild.ownerId) return 4 /* GUILD_OWNER */;
485
+ const rolePermissions = client.rolePermissions;
486
+ return rolePermissions[highestRole.name] ?? 0 /* USER */;
487
+ };
488
+
489
+ // src/shared/utility/functions.ts
490
+ var __filename$1 = fileURLToPath(import.meta.url);
491
+ var __dirname$1 = dirname(__filename$1);
492
+ var getPackageRoot = () => {
493
+ let dir = __dirname$1;
494
+ while (dir !== dirname(dir)) {
495
+ if (existsSync(join(dir, "package.json")) || existsSync(join(dir, "node_modules"))) {
496
+ return dir;
497
+ }
498
+ dir = dirname(dir);
499
+ }
500
+ return __dirname$1;
501
+ };
502
+ var FRAMEWORK_PACKAGE_ROOT = getPackageRoot();
503
+ function getCorePath(options) {
504
+ const { userPath, coreDirectory } = options;
505
+ if (userPath) {
506
+ return resolveUserPath(userPath);
507
+ }
508
+ const builtInCandidates = [
509
+ join(FRAMEWORK_PACKAGE_ROOT, "lib", coreDirectory),
510
+ join(FRAMEWORK_PACKAGE_ROOT, "dist", coreDirectory)
511
+ ];
512
+ for (const candidate of builtInCandidates) {
513
+ if (existsSync(candidate)) {
514
+ return candidate;
515
+ }
516
+ }
517
+ return join(FRAMEWORK_PACKAGE_ROOT, "lib", coreDirectory);
518
+ }
519
+ function resolveUserPath(relativePath) {
520
+ const candidates = [
521
+ join(process.cwd(), relativePath),
522
+ join(process.cwd(), "lib", relativePath),
523
+ join(process.cwd(), "dist", relativePath),
524
+ join(FRAMEWORK_PACKAGE_ROOT, relativePath),
525
+ join(FRAMEWORK_PACKAGE_ROOT, "lib", relativePath),
526
+ join(FRAMEWORK_PACKAGE_ROOT, "dist", relativePath)
527
+ ];
528
+ for (const candidate of candidates) {
529
+ const full = resolve(candidate);
530
+ if (existsSync(full)) return full;
531
+ }
532
+ return join(process.cwd(), relativePath);
533
+ }
534
+ async function exists(path2) {
535
+ try {
536
+ await promises.access(path2);
537
+ return true;
538
+ } catch {
539
+ return false;
540
+ }
541
+ }
542
+ function hasPermission(client, options) {
543
+ const { permission, user, member } = options;
544
+ if (permission === 5 /* BOT_OWNER */ && client._options.botOwnerIds) return user ? client._options.botOwnerIds.includes(user.id) : member ? client._options.botOwnerIds.includes(member.id) : false;
545
+ if (user) return true;
546
+ if (member) {
547
+ const memberPermission = getPermissionLevel(client, member);
548
+ return memberPermission >= permission;
549
+ }
550
+ return false;
551
+ }
552
+ var BaseRegistry = class {
553
+ /**
554
+ * Get all of loaded T
555
+ *
556
+ * @returns {Collection<string, T>}
557
+ */
558
+ get() {
559
+ return this.items;
560
+ }
561
+ /**
562
+ * Import a file from a path to be loaded.
563
+ *
564
+ * @protected
565
+ * @async
566
+ * @template T
567
+ * @param {string} filePath
568
+ * @returns {Promise<T | null>}
569
+ */
570
+ async importFile(filePath) {
571
+ try {
572
+ const { default: file } = await import(pathToFileURL(filePath).href);
573
+ const imports = file.default ?? file;
574
+ if (!imports) return null;
575
+ if (typeof imports === "function" && imports.prototype) {
576
+ return new imports();
577
+ }
578
+ if (typeof imports === "object") {
579
+ if (Object.keys(imports).length === 0) return null;
580
+ return imports;
581
+ }
582
+ console.error(`Invalid export in ${filePath}: expected class or object`);
583
+ return null;
584
+ } catch (error) {
585
+ console.error("Failed to import:", filePath, error);
586
+ return null;
587
+ }
588
+ }
589
+ /**
590
+ * Clear file path cache.
591
+ * Does not run in production environment.
592
+ *
593
+ * @protected
594
+ * @async
595
+ * @param {string} filePath
596
+ * @returns {*}
597
+ */
598
+ async clearCache(filePath) {
599
+ if (process.env.NODE_ENV === "production") return;
600
+ try {
601
+ const resvoled = __require.resolve(filePath);
602
+ delete __require.cache[resvoled];
603
+ } catch {
604
+ }
605
+ }
606
+ };
607
+
608
+ // src/shared/typings/components.ts
609
+ var ComponentType = /* @__PURE__ */ ((ComponentType2) => {
610
+ ComponentType2["Button"] = "button";
611
+ ComponentType2["SelectMenu"] = "select";
612
+ ComponentType2["Modal"] = "modal";
613
+ return ComponentType2;
614
+ })(ComponentType || {});
615
+ var deconstructCustomId = (customId) => {
616
+ const [componentType, dataTags] = customId.split(":");
617
+ const [data, ...tags] = dataTags.split(".");
618
+ return {
619
+ componentType,
620
+ data,
621
+ tags
622
+ };
623
+ };
624
+ var CommandRegistry = class extends BaseRegistry {
625
+ items = new Collection();
626
+ /**
627
+ * Load all commands and their subcommands
628
+ *
629
+ * @async
630
+ * @param {string} [directory=getCorePath({ coreDirectory: "commands" })]
631
+ * @returns {unknown}
632
+ */
633
+ async load(directory = getCorePath({ coreDirectory: "commands" })) {
634
+ if (!await exists(directory)) {
635
+ return this;
636
+ }
637
+ const entries = await promises.readdir(directory, { withFileTypes: true });
638
+ for (const entry of entries) {
639
+ const fullPath = join(directory, entry.name);
640
+ if (!entry.isDirectory()) continue;
641
+ const indexFile = join(fullPath, "index.ts");
642
+ const indexJs = join(fullPath, "index.js");
643
+ let commandFile = "";
644
+ if (await exists(indexFile)) commandFile = indexFile;
645
+ else if (await exists(indexJs)) commandFile = indexJs;
646
+ else continue;
647
+ const command = await this.importFile(commandFile);
648
+ if (!command) continue;
649
+ if (!command.metadata.active) continue;
650
+ if (command.isSlashCommand()) {
651
+ const subcommandFiles = (await promises.readdir(fullPath)).filter(
652
+ (file) => (file.endsWith(".ts") || file.endsWith(".js")) && !file.startsWith("index.") && !file.endsWith(".d.ts")
653
+ );
654
+ for (const file of subcommandFiles) {
655
+ const subcommand = await this.importFile(join(fullPath, file));
656
+ if (!subcommand) continue;
657
+ if (!subcommand.data.name || !(subcommand.data instanceof SlashCommandSubcommandBuilder))
658
+ continue;
659
+ command.data.addSubcommand(subcommand.data);
660
+ command.metadata.subcommands.set(subcommand.data.name, subcommand);
661
+ }
662
+ }
663
+ this.items.set(command.data.name, command);
664
+ }
665
+ return this;
666
+ }
667
+ };
668
+ var ComponentRegistry = class extends BaseRegistry {
669
+ items = new Collection();
670
+ /**
671
+ * Load all components.
672
+ *
673
+ * @async
674
+ * @param {string} [directory=getCorePath({ coreDirectory: "components" })]
675
+ * @returns {Promise<this>}
676
+ */
677
+ async load(directory = getCorePath({ coreDirectory: "components" })) {
678
+ if (!await exists(directory)) {
679
+ return this;
680
+ }
681
+ const entries = await promises.readdir(directory, { withFileTypes: true });
682
+ for (const entry of entries) {
683
+ const fullPath = join(directory, entry.name);
684
+ if (!entry.isDirectory()) continue;
685
+ const componentFiles = (await promises.readdir(fullPath)).filter(
686
+ (file) => (file.endsWith(".ts") || file.endsWith(".js")) && !file.startsWith("index.") && !file.endsWith(".d.ts")
687
+ );
688
+ for (const file of componentFiles) {
689
+ const component = await this.importFile(join(fullPath, file));
690
+ if (!component) continue;
691
+ const { data } = deconstructCustomId(component.metadata.customId);
692
+ this.items.set(data, component);
693
+ }
694
+ }
695
+ return this;
696
+ }
697
+ };
698
+ var interactionCreate_default = {
699
+ name: "interactionCreate",
700
+ execute: async (client, interaction) => {
701
+ if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
702
+ const { commandName } = interaction;
703
+ const registeredCommands = client.registries.commands.get();
704
+ const command = registeredCommands.get(commandName);
705
+ if (!command) {
706
+ await interaction.reply({
707
+ content: `Command is outdated, inactive or does not have a handler!`,
708
+ flags: ["Ephemeral"]
709
+ });
710
+ return;
711
+ }
712
+ const requiredPermission = command.metadata.permission;
713
+ const hasPermission2 = await command.validateGuildPermission(
714
+ client,
715
+ interaction,
716
+ requiredPermission
717
+ );
718
+ if (!hasPermission2) return;
719
+ if (!("execute" in command)) {
720
+ await command.reply(interaction, { content: "Command does not have a way to execute! Ensure the command is a SlashCommand or ContextMenuCommand!" });
721
+ return;
722
+ }
723
+ await command.reply(interaction, { content: "Processing command..." });
724
+ if (interaction.isChatInputCommand() && command.isSlashCommand()) {
725
+ await command.execute(client, interaction);
726
+ } else if (interaction.isContextMenuCommand() && command.isContextMenuCommand()) {
727
+ await command.execute(client, interaction);
728
+ }
729
+ } else if (interaction.isMessageComponent() || interaction.isModalSubmit()) {
730
+ const { componentType, tags, data } = deconstructCustomId(interaction.customId);
731
+ if (componentType === "button" /* Button */ && !(interaction instanceof ButtonInteraction))
732
+ return;
733
+ if (componentType === "modal" /* Modal */ && !(interaction instanceof ModalSubmitInteraction))
734
+ return;
735
+ if (tags.includes("awaited")) return;
736
+ const registeredComponents = client.registries.components.get();
737
+ const component = registeredComponents.get(data);
738
+ if (!component) {
739
+ await interaction.reply({
740
+ content: `Command is outdated, inactive or does not have a handler!`,
741
+ flags: ["Ephemeral"]
742
+ });
743
+ return;
744
+ }
745
+ const requiredPermission = component.metadata.permission;
746
+ const hasPermission2 = await component.validateGuildPermission(
747
+ client,
748
+ interaction,
749
+ requiredPermission
750
+ );
751
+ if (!hasPermission2) return;
752
+ if (!interaction.isModalSubmit()) await interaction.deferUpdate();
753
+ await component.execute(client, interaction);
754
+ }
755
+ }
756
+ };
757
+
758
+ // src/core/registry/event.registry.ts
759
+ var EventRegistry = class extends BaseRegistry {
760
+ items = new Collection();
761
+ /**
762
+ * Load all events.
763
+ *
764
+ * @async
765
+ * @param {string} [directory=getCorePath({ coreDirectory: "events" })]
766
+ * @returns {Promise<this>}
767
+ */
768
+ async load(directory = getCorePath({ coreDirectory: "events" })) {
769
+ if (!await exists(directory)) return this;
770
+ const entries = await promises.readdir(directory, { withFileTypes: true });
771
+ for (const entry of entries) {
772
+ const fullPath = join(directory, entry.name);
773
+ if (entry.isDirectory()) {
774
+ await this.load(fullPath);
775
+ continue;
776
+ }
777
+ if (entry.isFile() && entry.name.endsWith(".js")) {
778
+ const event = await this.importFile(fullPath);
779
+ if (!event) continue;
780
+ this.items.set(event.name, event);
781
+ }
782
+ }
783
+ this.items.set(interactionCreate_default.name, interactionCreate_default);
784
+ return this;
785
+ }
786
+ /**
787
+ * Bind loaded events to their client events respectively.
788
+ *
789
+ * @param {TriviousClient} client
790
+ */
791
+ bind(client) {
792
+ for (const event of this.items.values()) {
793
+ const handler = (...args) => void event.execute(client, ...args);
794
+ if (event.once) client.once(event.name, handler);
795
+ else client.on(event.name, handler);
796
+ }
797
+ }
798
+ };
799
+ var ModuleRegistry = class extends BaseRegistry {
800
+ items = new Collection();
801
+ /**
802
+ * Load all modules.
803
+ *
804
+ * @async
805
+ * @param {string} [directory=getCorePath({ coreDirectory: "module" })]
806
+ * @returns {Promise<this>}
807
+ */
808
+ async load(directory = getCorePath({ coreDirectory: "module" })) {
809
+ if (!await exists(directory)) {
810
+ return this;
811
+ }
812
+ const entries = await promises.readdir(directory, { withFileTypes: true });
813
+ for (const entry of entries) {
814
+ const fullPath = join(directory, entry.name);
815
+ if (!entry.isDirectory()) continue;
816
+ const moduleFiles = (await promises.readdir(fullPath)).filter(
817
+ (file) => (file.endsWith(".ts") || file.endsWith(".js")) && !file.startsWith("index.") && !file.endsWith(".d.ts")
818
+ );
819
+ for (const file of moduleFiles) {
820
+ const moduleEvent = await this.importFile(join(fullPath, file));
821
+ if (!moduleEvent || !moduleEvent.events) continue;
822
+ this.items.set(moduleEvent.name, moduleEvent);
823
+ }
824
+ }
825
+ return this;
826
+ }
827
+ /**
828
+ * Bind all loaded modules to their client event respectively.
829
+ *
830
+ * @param {TriviousClient} client
831
+ */
832
+ bind(client) {
833
+ for (const mod of this.items.values()) {
834
+ for (const [eventName, handler] of Object.entries(mod.events)) {
835
+ if (typeof handler !== "function") continue;
836
+ const listener = (...args) => {
837
+ void handler(client, ...args);
838
+ };
839
+ client.on(eventName, listener);
840
+ }
841
+ }
842
+ }
843
+ };
844
+ var registries = () => ({
845
+ commands: new CommandRegistry(),
846
+ components: new ComponentRegistry(),
847
+ events: new EventRegistry(),
848
+ modules: new ModuleRegistry(),
849
+ async loadAll(options) {
850
+ const corePaths = options.corePaths;
851
+ const corePath = options.corePath;
852
+ await Promise.all([
853
+ this.commands.load(
854
+ corePath ? resolveUserPath(path.join(corePath, "commands")) : corePaths?.commandsPath ? resolveUserPath(corePaths.commandsPath) : void 0
855
+ ),
856
+ this.components.load(
857
+ corePath ? resolveUserPath(path.join(corePath, "components")) : corePaths?.componentsPath ? resolveUserPath(corePaths.componentsPath) : void 0
858
+ ),
859
+ this.events.load(
860
+ corePath ? resolveUserPath(path.join(corePath, "events")) : corePaths?.eventsPath ? resolveUserPath(corePaths.eventsPath) : void 0
861
+ ),
862
+ this.modules.load(
863
+ corePath ? resolveUserPath(path.join(corePath, "modules")) : corePaths?.modulesPath ? resolveUserPath(corePaths.modulesPath) : void 0
864
+ )
865
+ ]);
866
+ },
867
+ bind(client) {
868
+ this.events.bind(client);
869
+ this.modules.bind(client);
870
+ }
871
+ });
872
+
873
+ // src/core/client/trivious.client.ts
874
+ var TriviousClient = class extends Client {
875
+ /**
876
+ * Client registries.
877
+ *
878
+ * @public
879
+ * @readonly
880
+ * @type {*}
881
+ */
882
+ registries = registries();
883
+ /**
884
+ * Client copy of the constructor options.
885
+ *
886
+ * @private
887
+ * @type {TriviousClientOptions}
888
+ */
889
+ _options;
890
+ /**
891
+ * Creates an instance of TriviousClient.
892
+ *
893
+ * @constructor
894
+ * @param {TriviousClientOptions} options
895
+ */
896
+ constructor(options) {
897
+ super(options);
898
+ this._options = options;
899
+ }
900
+ /**
901
+ * Load all registries.
902
+ *
903
+ * @async
904
+ * @returns {*}
905
+ */
906
+ async register() {
907
+ const { registries: registries2 } = this;
908
+ await registries2.loadAll(this._options);
909
+ console.log(
910
+ `[Trivious] Loaded all registries (${registries2.commands.get().size} commands, ${registries2.events.get().size} events, ${registries2.components.get().size} components, ${registries2.modules.get().size} modules)`
911
+ );
912
+ }
913
+ /**
914
+ * Login and start the bot.
915
+ *
916
+ * @async
917
+ * @returns {*}
918
+ */
919
+ async start() {
920
+ if (!process.env[this._options.tokenReference]) {
921
+ if (process.env.NODE_ENV !== "production") return;
922
+ else throw new Error("[Trivious] Invalid token reference");
923
+ }
924
+ this.registries.bind(this);
925
+ await this.login(process.env[this._options.tokenReference]);
926
+ }
927
+ /**
928
+ * Deploy all commands.
929
+ *
930
+ * @async
931
+ * @returns {*}
932
+ */
933
+ async deploy() {
934
+ const clientId = process.env[this._options.clientIdReference];
935
+ const token = process.env[this._options.tokenReference];
936
+ if (!clientId || !token) throw new Error("[Trivious] Invalid clientId or token reference");
937
+ const slashCommands = Array.from(this.registries.commands.get().values());
938
+ const body = [...slashCommands.map((command) => command.toJSON())];
939
+ const rest = new REST({ version: "10" }).setToken(token);
940
+ await rest.put(Routes.applicationCommands(clientId), { body });
941
+ console.log(`[Trivious] Deployed ${body.length} commands`);
942
+ }
943
+ /**
944
+ * Set the roles tied to a permission level.
945
+ *
946
+ * @param {Record<string, PermissionLevel>} roles
947
+ */
948
+ setRolePermissions(roles) {
949
+ this._options.rolePermissions = roles;
950
+ }
951
+ get rolePermissions() {
952
+ return this._options.rolePermissions ?? {};
953
+ }
954
+ };
955
+ var Command = class {
956
+ /**
957
+ * Returns whether the command is a SlashCommand.
958
+ *
959
+ * @public
960
+ * @param {Command} this
961
+ * @returns {this is SlashCommand}
962
+ */
963
+ isSlashCommand() {
964
+ return this.data instanceof SlashCommandBuilder && this instanceof SlashCommand;
965
+ }
966
+ /**
967
+ * Returns whether the command is a ContextMenuCommand.
968
+ *
969
+ * @public
970
+ * @param {Command} this
971
+ * @returns {this is ContextMenuCommand}
972
+ */
973
+ isContextMenuCommand() {
974
+ return this.data instanceof ContextMenuCommandBuilder && this instanceof ContextMenuCommand;
975
+ }
976
+ /**
977
+ * Returns JSON of the command builder.
978
+ *
979
+ * @public
980
+ * @returns {*}
981
+ */
982
+ toJSON() {
983
+ return this.data.toJSON();
984
+ }
985
+ /**
986
+ * Reply to the interaction respecting command metadata and if the interaction has already been replied to.
987
+ *
988
+ * @public
989
+ * @async
990
+ * @param {CommandInteraction} interaction
991
+ * @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options
992
+ * @returns {*}
993
+ */
994
+ async reply(interaction, options) {
995
+ if (interaction.replied) {
996
+ await interaction.editReply(options);
997
+ return;
998
+ }
999
+ const newOptions = { ...options };
1000
+ if (this.metadata.ephemeralReply) newOptions.flags = ["Ephemeral"];
1001
+ await interaction.reply(newOptions);
1002
+ }
1003
+ /**
1004
+ * Validate permissions for a user/member in a guild.
1005
+ *
1006
+ * @async
1007
+ * @param {CommandInteraction} interaction
1008
+ * @param {PermissionLevel} permission
1009
+ * @param {boolean} [doReply=true]
1010
+ * @returns {unknown}
1011
+ */
1012
+ async validateGuildPermission(client, interaction, permission, doReply = true) {
1013
+ const isContextMenu = interaction.isContextMenuCommand();
1014
+ const isChatInput = interaction.isChatInputCommand();
1015
+ const requiresGuildCheck = isContextMenu || isChatInput && (this.isSlashCommand() ? this.metadata.guildOnly : false);
1016
+ if (!requiresGuildCheck) return true;
1017
+ const member = interaction.member;
1018
+ const memberHasPermission = hasPermission(client, { permission, member });
1019
+ if (!memberHasPermission && doReply) {
1020
+ await this.reply(interaction, {
1021
+ content: `You do not have permission to run this command, required permission: \`${PermissionLevel[permission]}\``
1022
+ });
1023
+ }
1024
+ return memberHasPermission;
1025
+ }
1026
+ };
1027
+ var SlashCommand = class extends Command {
1028
+ /**
1029
+ * Optional function to run if the SlashCommand has no subcommands or for extra fuctionality.
1030
+ *
1031
+ * @abstract
1032
+ * @type {?(
1033
+ * client: TriviousClient,
1034
+ * interaction: ChatInputCommandInteraction
1035
+ * ) => Promise<void>}
1036
+ */
1037
+ run;
1038
+ /**
1039
+ * General handler for the command and its subcommand, if applicable.
1040
+ *
1041
+ * @public
1042
+ * @async
1043
+ * @param {TriviousClient} client
1044
+ * @param {ChatInputCommandInteraction} interaction
1045
+ * @returns {*}
1046
+ */
1047
+ async execute(client, interaction) {
1048
+ const { run, reply, metadata } = this;
1049
+ const { options } = interaction;
1050
+ if (run) {
1051
+ const memberHasPermission2 = await this.validateGuildPermission(
1052
+ client,
1053
+ interaction,
1054
+ metadata.permission,
1055
+ false
1056
+ );
1057
+ if (memberHasPermission2) await run(client, interaction);
1058
+ }
1059
+ const subcommands = metadata.subcommands;
1060
+ if (subcommands.size <= 0) return;
1061
+ const subcommand = metadata.subcommands.find(
1062
+ (subcmd) => subcmd.data.name === options.getSubcommand()
1063
+ );
1064
+ if (!subcommand) {
1065
+ await reply(interaction, {
1066
+ content: "Ran subcommand is outdated or does not have a handler!"
1067
+ });
1068
+ return;
1069
+ }
1070
+ const memberHasPermission = await this.validateGuildPermission(
1071
+ client,
1072
+ interaction,
1073
+ subcommand.metadata.permission
1074
+ );
1075
+ if (!memberHasPermission) return;
1076
+ await subcommand.execute(client, interaction);
1077
+ }
1078
+ };
1079
+ var CommandBuilder = class extends SlashCommandBuilder {
1080
+ _active = true;
1081
+ _guildOnly = false;
1082
+ _ownerOnly = false;
1083
+ _permission = 0 /* USER */;
1084
+ _subcommands = new Collection();
1085
+ _ephemeralReply = false;
1086
+ /**
1087
+ * Set the command as disabled.
1088
+ *
1089
+ * @public
1090
+ * @returns {this}
1091
+ */
1092
+ disable() {
1093
+ this._active = false;
1094
+ return this;
1095
+ }
1096
+ /**
1097
+ * Set the command as guild only.
1098
+ *
1099
+ * @public
1100
+ * @returns {this}
1101
+ */
1102
+ setGuildOnly() {
1103
+ this._guildOnly = true;
1104
+ this._permission = 0 /* USER */;
1105
+ this.setContexts(InteractionContextType.Guild);
1106
+ return this;
1107
+ }
1108
+ /**
1109
+ * Set the command as public only.
1110
+ *
1111
+ * @public
1112
+ * @returns {this}
1113
+ */
1114
+ setOwnerOnly() {
1115
+ this._permission = 5 /* BOT_OWNER */;
1116
+ return this;
1117
+ }
1118
+ /**
1119
+ * Set the permission level required to run the command.
1120
+ *
1121
+ * @public
1122
+ * @param {PermissionLevel} permission
1123
+ * @returns {this}
1124
+ */
1125
+ setPermission(permission) {
1126
+ if (!this._guildOnly) return this;
1127
+ this._permission = permission;
1128
+ return this;
1129
+ }
1130
+ /**
1131
+ * Set the interaction as ephemeral.
1132
+ *
1133
+ * @public
1134
+ * @returns {this}
1135
+ */
1136
+ setEphemeralReply() {
1137
+ this._ephemeralReply = true;
1138
+ return this;
1139
+ }
1140
+ /**
1141
+ * Build the builder.
1142
+ *
1143
+ * @public
1144
+ * @returns {{ data: CommandBuilder; metadata: CommandMetadata; }}
1145
+ */
1146
+ build() {
1147
+ return {
1148
+ data: this,
1149
+ metadata: {
1150
+ active: this._active,
1151
+ guildOnly: this._guildOnly,
1152
+ ownerOnly: this._ownerOnly,
1153
+ permission: this._permission,
1154
+ subcommands: this._subcommands,
1155
+ ephemeralReply: this._ephemeralReply
1156
+ }
1157
+ };
1158
+ }
1159
+ };
1160
+ var ContextMenuCommand = class extends Command {
1161
+ /**
1162
+ * Base command handler.
1163
+ *
1164
+ * @public
1165
+ * @async
1166
+ * @param {TriviousClient} client
1167
+ * @param {ContextMenuCommandInteraction} interaction
1168
+ * @returns {*}
1169
+ */
1170
+ async execute(client, interaction) {
1171
+ const { run, metadata } = this;
1172
+ const memberHasPermission = await this.validateGuildPermission(
1173
+ client,
1174
+ interaction,
1175
+ metadata.permission,
1176
+ false
1177
+ );
1178
+ if (memberHasPermission) await run(client, interaction);
1179
+ }
1180
+ };
1181
+ var ContextMenuBuilder = class extends ContextMenuCommandBuilder {
1182
+ _active = true;
1183
+ _ownerOnly = false;
1184
+ _permission = 0 /* USER */;
1185
+ _ephemeralReply = false;
1186
+ /**
1187
+ * Set the command as disabled.
1188
+ *
1189
+ * @public
1190
+ * @returns {this}
1191
+ */
1192
+ disable() {
1193
+ this._active = false;
1194
+ return this;
1195
+ }
1196
+ /**
1197
+ * Set the command as owner only.
1198
+ *
1199
+ * @public
1200
+ * @returns {this}
1201
+ */
1202
+ setOwnerOnly() {
1203
+ this._permission = 5 /* BOT_OWNER */;
1204
+ this._ownerOnly = true;
1205
+ return this;
1206
+ }
1207
+ /**
1208
+ * Set the permission level required to run the command.
1209
+ *
1210
+ * @public
1211
+ * @param {PermissionLevel} permission
1212
+ * @returns {this}
1213
+ */
1214
+ setPermission(permission) {
1215
+ this._permission = permission;
1216
+ return this;
1217
+ }
1218
+ /**
1219
+ * Set the interaction as ephemeral.
1220
+ *
1221
+ * @public
1222
+ * @returns {this}
1223
+ */
1224
+ setEphemeralReply() {
1225
+ this._ephemeralReply = true;
1226
+ return this;
1227
+ }
1228
+ /**
1229
+ * Build the builder
1230
+ *
1231
+ * @public
1232
+ * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1233
+ */
1234
+ build() {
1235
+ return {
1236
+ data: this,
1237
+ metadata: {
1238
+ active: this._active,
1239
+ ownerOnly: this._ownerOnly,
1240
+ permission: this._permission,
1241
+ ephemeralReply: this._ephemeralReply
1242
+ }
1243
+ };
1244
+ }
1245
+ };
1246
+ var SubcommandBuilder = class extends SlashCommandSubcommandBuilder {
1247
+ _active = true;
1248
+ _ownerOnly = false;
1249
+ _permission = 0 /* USER */;
1250
+ _ephemeralReply = false;
1251
+ /**
1252
+ * Set the subcommand as disabled.
1253
+ *
1254
+ * @public
1255
+ * @returns {this}
1256
+ */
1257
+ disable() {
1258
+ this._active = false;
1259
+ return this;
1260
+ }
1261
+ /**
1262
+ * Set the subcommand as owner only.
1263
+ *
1264
+ * @public
1265
+ * @returns {this}
1266
+ */
1267
+ setOwnerOnly() {
1268
+ this._permission = 5 /* BOT_OWNER */;
1269
+ this._ownerOnly = true;
1270
+ return this;
1271
+ }
1272
+ /**
1273
+ * Set the permission level required to run the subcommand.
1274
+ *
1275
+ * @public
1276
+ * @param {PermissionLevel} permission
1277
+ * @returns {this}
1278
+ */
1279
+ setPermission(permission) {
1280
+ this._permission = permission;
1281
+ return this;
1282
+ }
1283
+ /**
1284
+ * Set the interaction as ephemeral
1285
+ *
1286
+ * @public
1287
+ * @returns {this}
1288
+ */
1289
+ setEphemeralReply() {
1290
+ this._ephemeralReply = true;
1291
+ return this;
1292
+ }
1293
+ /**
1294
+ * Build the builder.
1295
+ *
1296
+ * @public
1297
+ * @returns {{ data: SlashCommandSubcommandBuilder; metadata: SubcommandMetadata; }}
1298
+ */
1299
+ build() {
1300
+ return {
1301
+ data: this,
1302
+ metadata: {
1303
+ active: this._active,
1304
+ ownerOnly: this._ownerOnly,
1305
+ permission: this._permission,
1306
+ ephemeralReply: this._ephemeralReply
1307
+ }
1308
+ };
1309
+ }
1310
+ };
1311
+ var Subcommand = class {
1312
+ /**
1313
+ * Reply to the interaction respecting command metadata and if the interaction has already been replied to.
1314
+ *
1315
+ * @async
1316
+ * @param {ChatInputCommandInteraction<CacheType>} interaction
1317
+ * @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options
1318
+ * @returns {*}
1319
+ */
1320
+ async reply(interaction, options) {
1321
+ if (interaction.replied) {
1322
+ await interaction.editReply(options);
1323
+ return;
1324
+ }
1325
+ const newOptions = { ...options };
1326
+ if (this.metadata.ephemeralReply) newOptions.flags = ["Ephemeral"];
1327
+ await interaction.reply(newOptions);
1328
+ }
1329
+ };
1330
+
1331
+ // src/core/components/component.base.ts
1332
+ var ComponentBuilder = class {
1333
+ _customId = "";
1334
+ _permission = 0 /* USER */;
1335
+ _ephemeralReply = false;
1336
+ /**
1337
+ * Set the customId for the component.
1338
+ *
1339
+ * @public
1340
+ * @param {{
1341
+ * type: ComponentType;
1342
+ * data: string;
1343
+ * tags?: ComponentCustomIdTag[];
1344
+ * }} options
1345
+ * @returns {this}
1346
+ */
1347
+ setCustomId(options) {
1348
+ const { data, type, tags } = options;
1349
+ this._customId = `${type}:${data}${tags ? `.${tags.join(".")}` : ""}`;
1350
+ return this;
1351
+ }
1352
+ /**
1353
+ * Set the permission required to use the component.
1354
+ *
1355
+ * @public
1356
+ * @param {PermissionLevel} permission
1357
+ * @returns {this}
1358
+ */
1359
+ setPermission(permission) {
1360
+ this._permission = permission;
1361
+ return this;
1362
+ }
1363
+ /**
1364
+ * Set the interaction as ephemeral.
1365
+ *
1366
+ * @public
1367
+ * @returns {this}
1368
+ */
1369
+ setEphemeralReply() {
1370
+ this._ephemeralReply = true;
1371
+ return this;
1372
+ }
1373
+ /**
1374
+ * Builder the builder.
1375
+ *
1376
+ * @public
1377
+ * @returns {{ metadata: ComponentMetadata; }}
1378
+ */
1379
+ build() {
1380
+ return {
1381
+ metadata: {
1382
+ customId: this._customId,
1383
+ permission: this._permission,
1384
+ ephemeralReply: this._ephemeralReply
1385
+ }
1386
+ };
1387
+ }
1388
+ };
1389
+ var Component = class {
1390
+ /**
1391
+ * Validate permissions for a user/member in a guild.
1392
+ *
1393
+ * @async
1394
+ * @param {ComponentInteraction} interaction
1395
+ * @param {PermissionLevel} permission
1396
+ * @param {boolean} [doReply=true] Defaults to `true`
1397
+ * @returns {unknown}
1398
+ */
1399
+ async validateGuildPermission(client, interaction, permission, doReply = true) {
1400
+ if (interaction.guild) {
1401
+ const member = interaction.member;
1402
+ const memberHasPermission = hasPermission(client, { permission, member });
1403
+ if (!memberHasPermission) {
1404
+ if (doReply)
1405
+ await this.reply(interaction, {
1406
+ content: `You do not have permission to run this command, required permission: \`${PermissionLevel[permission]}\``
1407
+ });
1408
+ return false;
1409
+ }
1410
+ }
1411
+ return true;
1412
+ }
1413
+ /**
1414
+ * Reply to the interaction respecting command metadata and if the interaction has already been replied to.
1415
+ *
1416
+ * @async
1417
+ * @param {ComponentInteraction} interaction
1418
+ * @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options
1419
+ * @returns {*}
1420
+ */
1421
+ async reply(interaction, options) {
1422
+ if (interaction.replied) {
1423
+ await interaction.editReply(options);
1424
+ return;
1425
+ }
1426
+ const newOptions = { ...options };
1427
+ if (this.metadata.ephemeralReply) newOptions.flags = ["Ephemeral"];
1428
+ await interaction.reply(newOptions);
1429
+ }
1430
+ };
1431
+
1432
+ export { BaseRegistry, Command, CommandBuilder, CommandRegistry, Component, ComponentBuilder, ComponentRegistry, ComponentType, ContextMenuBuilder, ContextMenuCommand, PermissionLevel, SlashCommand, Subcommand, SubcommandBuilder, TriviousClient, deconstructCustomId, getPermissionLevel };
11
1433
  //# sourceMappingURL=index.js.map
12
1434
  //# sourceMappingURL=index.js.map