trivious 1.3.21 → 1.3.22

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 +1445 -67
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +973 -3
  4. package/dist/index.d.ts +973 -3
  5. package/dist/index.js +1434 -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,1436 @@
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 (user) {
545
+ if (permission === 5 /* BOT_OWNER */) return user.id === "424764032667484171";
546
+ return true;
547
+ }
548
+ if (member) {
549
+ const memberPermission = getPermissionLevel(client, member);
550
+ return memberPermission >= permission;
551
+ }
552
+ return false;
553
+ }
554
+ var BaseRegistry = class {
555
+ /**
556
+ * Get all of loaded T
557
+ *
558
+ * @returns {Collection<string, T>}
559
+ */
560
+ get() {
561
+ return this.items;
562
+ }
563
+ /**
564
+ * Import a file from a path to be loaded.
565
+ *
566
+ * @protected
567
+ * @async
568
+ * @template T
569
+ * @param {string} filePath
570
+ * @returns {Promise<T | null>}
571
+ */
572
+ async importFile(filePath) {
573
+ try {
574
+ const { default: file } = await import(pathToFileURL(filePath).href);
575
+ const imports = file.default ?? file;
576
+ if (!imports) return null;
577
+ if (typeof imports === "function" && imports.prototype) {
578
+ return new imports();
579
+ }
580
+ if (typeof imports === "object") {
581
+ if (Object.keys(imports).length === 0) return null;
582
+ return imports;
583
+ }
584
+ console.error(`Invalid export in ${filePath}: expected class or object`);
585
+ return null;
586
+ } catch (error) {
587
+ console.error("Failed to import:", filePath, error);
588
+ return null;
589
+ }
590
+ }
591
+ /**
592
+ * Clear file path cache.
593
+ * Does not run in production environment.
594
+ *
595
+ * @protected
596
+ * @async
597
+ * @param {string} filePath
598
+ * @returns {*}
599
+ */
600
+ async clearCache(filePath) {
601
+ if (process.env.NODE_ENV === "production") return;
602
+ try {
603
+ const resvoled = __require.resolve(filePath);
604
+ delete __require.cache[resvoled];
605
+ } catch {
606
+ }
607
+ }
608
+ };
609
+
610
+ // src/shared/typings/components.ts
611
+ var ComponentType = /* @__PURE__ */ ((ComponentType2) => {
612
+ ComponentType2["Button"] = "button";
613
+ ComponentType2["SelectMenu"] = "select";
614
+ ComponentType2["Modal"] = "modal";
615
+ return ComponentType2;
616
+ })(ComponentType || {});
617
+ var deconstructCustomId = (customId) => {
618
+ const [componentType, dataTags] = customId.split(":");
619
+ const [data, ...tags] = dataTags.split(".");
620
+ return {
621
+ componentType,
622
+ data,
623
+ tags
624
+ };
625
+ };
626
+ var CommandRegistry = class extends BaseRegistry {
627
+ items = new Collection();
628
+ /**
629
+ * Load all commands and their subcommands
630
+ *
631
+ * @async
632
+ * @param {string} [directory=getCorePath({ coreDirectory: "commands" })]
633
+ * @returns {unknown}
634
+ */
635
+ async load(directory = getCorePath({ coreDirectory: "commands" })) {
636
+ if (!await exists(directory)) {
637
+ return this;
638
+ }
639
+ const entries = await promises.readdir(directory, { withFileTypes: true });
640
+ for (const entry of entries) {
641
+ const fullPath = join(directory, entry.name);
642
+ if (!entry.isDirectory()) continue;
643
+ const indexFile = join(fullPath, "index.ts");
644
+ const indexJs = join(fullPath, "index.js");
645
+ let commandFile = "";
646
+ if (await exists(indexFile)) commandFile = indexFile;
647
+ else if (await exists(indexJs)) commandFile = indexJs;
648
+ else continue;
649
+ const command = await this.importFile(commandFile);
650
+ if (!command) continue;
651
+ if (!command.metadata.active) continue;
652
+ if (command.isSlashCommand()) {
653
+ const subcommandFiles = (await promises.readdir(fullPath)).filter(
654
+ (file) => (file.endsWith(".ts") || file.endsWith(".js")) && !file.startsWith("index.") && !file.endsWith(".d.ts")
655
+ );
656
+ for (const file of subcommandFiles) {
657
+ const subcommand = await this.importFile(join(fullPath, file));
658
+ if (!subcommand) continue;
659
+ if (!subcommand.data.name || !(subcommand.data instanceof SlashCommandSubcommandBuilder))
660
+ continue;
661
+ command.data.addSubcommand(subcommand.data);
662
+ command.metadata.subcommands.set(subcommand.data.name, subcommand);
663
+ }
664
+ }
665
+ this.items.set(command.data.name, command);
666
+ }
667
+ return this;
668
+ }
669
+ };
670
+ var ComponentRegistry = class extends BaseRegistry {
671
+ items = new Collection();
672
+ /**
673
+ * Load all components.
674
+ *
675
+ * @async
676
+ * @param {string} [directory=getCorePath({ coreDirectory: "components" })]
677
+ * @returns {Promise<this>}
678
+ */
679
+ async load(directory = getCorePath({ coreDirectory: "components" })) {
680
+ if (!await exists(directory)) {
681
+ return this;
682
+ }
683
+ const entries = await promises.readdir(directory, { withFileTypes: true });
684
+ for (const entry of entries) {
685
+ const fullPath = join(directory, entry.name);
686
+ if (!entry.isDirectory()) continue;
687
+ const componentFiles = (await promises.readdir(fullPath)).filter(
688
+ (file) => (file.endsWith(".ts") || file.endsWith(".js")) && !file.startsWith("index.") && !file.endsWith(".d.ts")
689
+ );
690
+ for (const file of componentFiles) {
691
+ const component = await this.importFile(join(fullPath, file));
692
+ if (!component) continue;
693
+ const { data } = deconstructCustomId(component.metadata.customId);
694
+ this.items.set(data, component);
695
+ }
696
+ }
697
+ return this;
698
+ }
699
+ };
700
+ var interactionCreate_default = {
701
+ name: "interactionCreate",
702
+ execute: async (client, interaction) => {
703
+ if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
704
+ const { commandName } = interaction;
705
+ const registeredCommands = client.registries.commands.get();
706
+ const command = registeredCommands.get(commandName);
707
+ if (!command) {
708
+ await interaction.reply({
709
+ content: `Command is outdated, inactive or does not have a handler!`,
710
+ flags: ["Ephemeral"]
711
+ });
712
+ return;
713
+ }
714
+ const requiredPermission = command.metadata.permission;
715
+ const hasPermission2 = await command.validateGuildPermission(
716
+ client,
717
+ interaction,
718
+ requiredPermission
719
+ );
720
+ if (!hasPermission2) return;
721
+ if (!("execute" in command)) {
722
+ await command.reply(interaction, { content: "Command does not have a way to execute! Ensure the command is a SlashCommand or ContextMenuCommand!" });
723
+ return;
724
+ }
725
+ await command.reply(interaction, { content: "Processing command..." });
726
+ if (interaction.isChatInputCommand() && command.isSlashCommand()) {
727
+ await command.execute(client, interaction);
728
+ } else if (interaction.isContextMenuCommand() && command.isContextMenuCommand()) {
729
+ await command.execute(client, interaction);
730
+ }
731
+ } else if (interaction.isMessageComponent() || interaction.isModalSubmit()) {
732
+ const { componentType, tags, data } = deconstructCustomId(interaction.customId);
733
+ if (componentType === "button" /* Button */ && !(interaction instanceof ButtonInteraction))
734
+ return;
735
+ if (componentType === "modal" /* Modal */ && !(interaction instanceof ModalSubmitInteraction))
736
+ return;
737
+ if (tags.includes("awaited")) return;
738
+ const registeredComponents = client.registries.components.get();
739
+ const component = registeredComponents.get(data);
740
+ if (!component) {
741
+ await interaction.reply({
742
+ content: `Command is outdated, inactive or does not have a handler!`,
743
+ flags: ["Ephemeral"]
744
+ });
745
+ return;
746
+ }
747
+ const requiredPermission = component.metadata.permission;
748
+ const hasPermission2 = await component.validateGuildPermission(
749
+ client,
750
+ interaction,
751
+ requiredPermission
752
+ );
753
+ if (!hasPermission2) return;
754
+ if (!interaction.isModalSubmit()) await interaction.deferUpdate();
755
+ await component.execute(client, interaction);
756
+ }
757
+ }
758
+ };
759
+
760
+ // src/core/registry/event.registry.ts
761
+ var EventRegistry = class extends BaseRegistry {
762
+ items = new Collection();
763
+ /**
764
+ * Load all events.
765
+ *
766
+ * @async
767
+ * @param {string} [directory=getCorePath({ coreDirectory: "events" })]
768
+ * @returns {Promise<this>}
769
+ */
770
+ async load(directory = getCorePath({ coreDirectory: "events" })) {
771
+ if (!await exists(directory)) return this;
772
+ const entries = await promises.readdir(directory, { withFileTypes: true });
773
+ for (const entry of entries) {
774
+ const fullPath = join(directory, entry.name);
775
+ if (entry.isDirectory()) {
776
+ await this.load(fullPath);
777
+ continue;
778
+ }
779
+ if (entry.isFile() && entry.name.endsWith(".js")) {
780
+ const event = await this.importFile(fullPath);
781
+ if (!event) continue;
782
+ this.items.set(event.name, event);
783
+ }
784
+ }
785
+ this.items.set(interactionCreate_default.name, interactionCreate_default);
786
+ return this;
787
+ }
788
+ /**
789
+ * Bind loaded events to their client events respectively.
790
+ *
791
+ * @param {TriviousClient} client
792
+ */
793
+ bind(client) {
794
+ for (const event of this.items.values()) {
795
+ const handler = (...args) => void event.execute(client, ...args);
796
+ if (event.once) client.once(event.name, handler);
797
+ else client.on(event.name, handler);
798
+ }
799
+ }
800
+ };
801
+ var ModuleRegistry = class extends BaseRegistry {
802
+ items = new Collection();
803
+ /**
804
+ * Load all modules.
805
+ *
806
+ * @async
807
+ * @param {string} [directory=getCorePath({ coreDirectory: "module" })]
808
+ * @returns {Promise<this>}
809
+ */
810
+ async load(directory = getCorePath({ coreDirectory: "module" })) {
811
+ if (!await exists(directory)) {
812
+ return this;
813
+ }
814
+ const entries = await promises.readdir(directory, { withFileTypes: true });
815
+ for (const entry of entries) {
816
+ const fullPath = join(directory, entry.name);
817
+ if (!entry.isDirectory()) continue;
818
+ const moduleFiles = (await promises.readdir(fullPath)).filter(
819
+ (file) => (file.endsWith(".ts") || file.endsWith(".js")) && !file.startsWith("index.") && !file.endsWith(".d.ts")
820
+ );
821
+ for (const file of moduleFiles) {
822
+ const moduleEvent = await this.importFile(join(fullPath, file));
823
+ if (!moduleEvent || !moduleEvent.events) continue;
824
+ this.items.set(moduleEvent.name, moduleEvent);
825
+ }
826
+ }
827
+ return this;
828
+ }
829
+ /**
830
+ * Bind all loaded modules to their client event respectively.
831
+ *
832
+ * @param {TriviousClient} client
833
+ */
834
+ bind(client) {
835
+ for (const mod of this.items.values()) {
836
+ for (const [eventName, handler] of Object.entries(mod.events)) {
837
+ if (typeof handler !== "function") continue;
838
+ const listener = (...args) => {
839
+ void handler(client, ...args);
840
+ };
841
+ client.on(eventName, listener);
842
+ }
843
+ }
844
+ }
845
+ };
846
+ var registries = () => ({
847
+ commands: new CommandRegistry(),
848
+ components: new ComponentRegistry(),
849
+ events: new EventRegistry(),
850
+ modules: new ModuleRegistry(),
851
+ async loadAll(options) {
852
+ const corePaths = options.corePaths;
853
+ const corePath = options.corePath;
854
+ await Promise.all([
855
+ this.commands.load(
856
+ corePath ? resolveUserPath(path.join(corePath, "commands")) : corePaths?.commandsPath ? resolveUserPath(corePaths.commandsPath) : void 0
857
+ ),
858
+ this.components.load(
859
+ corePath ? resolveUserPath(path.join(corePath, "components")) : corePaths?.componentsPath ? resolveUserPath(corePaths.componentsPath) : void 0
860
+ ),
861
+ this.events.load(
862
+ corePath ? resolveUserPath(path.join(corePath, "events")) : corePaths?.eventsPath ? resolveUserPath(corePaths.eventsPath) : void 0
863
+ ),
864
+ this.modules.load(
865
+ corePath ? resolveUserPath(path.join(corePath, "modules")) : corePaths?.modulesPath ? resolveUserPath(corePaths.modulesPath) : void 0
866
+ )
867
+ ]);
868
+ },
869
+ bind(client) {
870
+ this.events.bind(client);
871
+ this.modules.bind(client);
872
+ }
873
+ });
874
+
875
+ // src/core/client/trivious.client.ts
876
+ var TriviousClient = class extends Client {
877
+ /**
878
+ * Client registries.
879
+ *
880
+ * @public
881
+ * @readonly
882
+ * @type {*}
883
+ */
884
+ registries = registries();
885
+ /**
886
+ * Client copy of the constructor options.
887
+ *
888
+ * @private
889
+ * @type {TriviousClientOptions}
890
+ */
891
+ _options;
892
+ /**
893
+ * Creates an instance of TriviousClient.
894
+ *
895
+ * @constructor
896
+ * @param {TriviousClientOptions} options
897
+ */
898
+ constructor(options) {
899
+ super(options);
900
+ this._options = options;
901
+ }
902
+ /**
903
+ * Load all registries.
904
+ *
905
+ * @async
906
+ * @returns {*}
907
+ */
908
+ async register() {
909
+ const { registries: registries2 } = this;
910
+ await registries2.loadAll(this._options);
911
+ console.log(
912
+ `[Trivious] Loaded all registries (${registries2.commands.get().size} commands, ${registries2.events.get().size} events, ${registries2.components.get().size} components, ${registries2.modules.get().size} modules)`
913
+ );
914
+ }
915
+ /**
916
+ * Login and start the bot.
917
+ *
918
+ * @async
919
+ * @returns {*}
920
+ */
921
+ async start() {
922
+ if (!process.env[this._options.tokenReference]) {
923
+ if (process.env.NODE_ENV !== "production") return;
924
+ else throw new Error("[Trivious] Invalid token reference");
925
+ }
926
+ this.registries.bind(this);
927
+ await this.login(process.env[this._options.tokenReference]);
928
+ }
929
+ /**
930
+ * Deploy all commands.
931
+ *
932
+ * @async
933
+ * @returns {*}
934
+ */
935
+ async deploy() {
936
+ const clientId = process.env[this._options.clientIdReference];
937
+ const token = process.env[this._options.tokenReference];
938
+ if (!clientId || !token) throw new Error("[Trivious] Invalid clientId or token reference");
939
+ const slashCommands = Array.from(this.registries.commands.get().values());
940
+ const body = [...slashCommands.map((command) => command.toJSON())];
941
+ const rest = new REST({ version: "10" }).setToken(token);
942
+ await rest.put(Routes.applicationCommands(clientId), { body });
943
+ console.log(`[Trivious] Deployed ${body.length} commands`);
944
+ }
945
+ /**
946
+ * Set the roles tied to a permission level.
947
+ *
948
+ * @param {Record<string, PermissionLevel>} roles
949
+ */
950
+ setRolePermissions(roles) {
951
+ this._options.rolePermissions = roles;
952
+ }
953
+ get rolePermissions() {
954
+ return this._options.rolePermissions ?? {};
955
+ }
956
+ };
957
+ var Command = class {
958
+ /**
959
+ * Returns whether the command is a SlashCommand.
960
+ *
961
+ * @public
962
+ * @param {Command} this
963
+ * @returns {this is SlashCommand}
964
+ */
965
+ isSlashCommand() {
966
+ return this.data instanceof SlashCommandBuilder && this instanceof SlashCommand;
967
+ }
968
+ /**
969
+ * Returns whether the command is a ContextMenuCommand.
970
+ *
971
+ * @public
972
+ * @param {Command} this
973
+ * @returns {this is ContextMenuCommand}
974
+ */
975
+ isContextMenuCommand() {
976
+ return this.data instanceof ContextMenuCommandBuilder && this instanceof ContextMenuCommand;
977
+ }
978
+ /**
979
+ * Returns JSON of the command builder.
980
+ *
981
+ * @public
982
+ * @returns {*}
983
+ */
984
+ toJSON() {
985
+ return this.data.toJSON();
986
+ }
987
+ /**
988
+ * Reply to the interaction respecting command metadata and if the interaction has already been replied to.
989
+ *
990
+ * @public
991
+ * @async
992
+ * @param {CommandInteraction} interaction
993
+ * @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options
994
+ * @returns {*}
995
+ */
996
+ async reply(interaction, options) {
997
+ if (interaction.replied) {
998
+ await interaction.editReply(options);
999
+ return;
1000
+ }
1001
+ const newOptions = { ...options };
1002
+ if (this.metadata.ephemeralReply) newOptions.flags = ["Ephemeral"];
1003
+ await interaction.reply(newOptions);
1004
+ }
1005
+ /**
1006
+ * Validate permissions for a user/member in a guild.
1007
+ *
1008
+ * @async
1009
+ * @param {CommandInteraction} interaction
1010
+ * @param {PermissionLevel} permission
1011
+ * @param {boolean} [doReply=true]
1012
+ * @returns {unknown}
1013
+ */
1014
+ async validateGuildPermission(client, interaction, permission, doReply = true) {
1015
+ const isContextMenu = interaction.isContextMenuCommand();
1016
+ const isChatInput = interaction.isChatInputCommand();
1017
+ const requiresGuildCheck = isContextMenu || isChatInput && (this.isSlashCommand() ? this.metadata.guildOnly : false);
1018
+ if (!requiresGuildCheck) return true;
1019
+ const member = interaction.member;
1020
+ const memberHasPermission = hasPermission(client, { permission, member });
1021
+ if (!memberHasPermission && doReply) {
1022
+ await this.reply(interaction, {
1023
+ content: `You do not have permission to run this command, required permission: \`${PermissionLevel[permission]}\``
1024
+ });
1025
+ }
1026
+ return memberHasPermission;
1027
+ }
1028
+ };
1029
+ var SlashCommand = class extends Command {
1030
+ /**
1031
+ * Optional function to run if the SlashCommand has no subcommands or for extra fuctionality.
1032
+ *
1033
+ * @abstract
1034
+ * @type {?(
1035
+ * client: TriviousClient,
1036
+ * interaction: ChatInputCommandInteraction
1037
+ * ) => Promise<void>}
1038
+ */
1039
+ run;
1040
+ /**
1041
+ * General handler for the command and its subcommand, if applicable.
1042
+ *
1043
+ * @public
1044
+ * @async
1045
+ * @param {TriviousClient} client
1046
+ * @param {ChatInputCommandInteraction} interaction
1047
+ * @returns {*}
1048
+ */
1049
+ async execute(client, interaction) {
1050
+ const { run, reply, metadata } = this;
1051
+ const { options } = interaction;
1052
+ if (run) {
1053
+ const memberHasPermission2 = await this.validateGuildPermission(
1054
+ client,
1055
+ interaction,
1056
+ metadata.permission,
1057
+ false
1058
+ );
1059
+ if (memberHasPermission2) await run(client, interaction);
1060
+ }
1061
+ const subcommands = metadata.subcommands;
1062
+ if (subcommands.size <= 0) return;
1063
+ const subcommand = metadata.subcommands.find(
1064
+ (subcmd) => subcmd.data.name === options.getSubcommand()
1065
+ );
1066
+ if (!subcommand) {
1067
+ await reply(interaction, {
1068
+ content: "Ran subcommand is outdated or does not have a handler!"
1069
+ });
1070
+ return;
1071
+ }
1072
+ const memberHasPermission = await this.validateGuildPermission(
1073
+ client,
1074
+ interaction,
1075
+ subcommand.metadata.permission
1076
+ );
1077
+ if (!memberHasPermission) return;
1078
+ await subcommand.execute(client, interaction);
1079
+ }
1080
+ };
1081
+ var CommandBuilder = class extends SlashCommandBuilder {
1082
+ _active = true;
1083
+ _guildOnly = false;
1084
+ _ownerOnly = false;
1085
+ _permission = 0 /* USER */;
1086
+ _subcommands = new Collection();
1087
+ _ephemeralReply = false;
1088
+ /**
1089
+ * Set the command as disabled.
1090
+ *
1091
+ * @public
1092
+ * @returns {this}
1093
+ */
1094
+ disable() {
1095
+ this._active = false;
1096
+ return this;
1097
+ }
1098
+ /**
1099
+ * Set the command as guild only.
1100
+ *
1101
+ * @public
1102
+ * @returns {this}
1103
+ */
1104
+ setGuildOnly() {
1105
+ this._guildOnly = true;
1106
+ this._permission = 0 /* USER */;
1107
+ this.setContexts(InteractionContextType.Guild);
1108
+ return this;
1109
+ }
1110
+ /**
1111
+ * Set the command as public only.
1112
+ *
1113
+ * @public
1114
+ * @returns {this}
1115
+ */
1116
+ setOwnerOnly() {
1117
+ this._permission = 5 /* BOT_OWNER */;
1118
+ return this;
1119
+ }
1120
+ /**
1121
+ * Set the permission level required to run the command.
1122
+ *
1123
+ * @public
1124
+ * @param {PermissionLevel} permission
1125
+ * @returns {this}
1126
+ */
1127
+ setPermission(permission) {
1128
+ if (!this._guildOnly) return this;
1129
+ this._permission = permission;
1130
+ return this;
1131
+ }
1132
+ /**
1133
+ * Set the interaction as ephemeral.
1134
+ *
1135
+ * @public
1136
+ * @returns {this}
1137
+ */
1138
+ setEphemeralReply() {
1139
+ this._ephemeralReply = true;
1140
+ return this;
1141
+ }
1142
+ /**
1143
+ * Build the builder.
1144
+ *
1145
+ * @public
1146
+ * @returns {{ data: CommandBuilder; metadata: CommandMetadata; }}
1147
+ */
1148
+ build() {
1149
+ return {
1150
+ data: this,
1151
+ metadata: {
1152
+ active: this._active,
1153
+ guildOnly: this._guildOnly,
1154
+ ownerOnly: this._ownerOnly,
1155
+ permission: this._permission,
1156
+ subcommands: this._subcommands,
1157
+ ephemeralReply: this._ephemeralReply
1158
+ }
1159
+ };
1160
+ }
1161
+ };
1162
+ var ContextMenuCommand = class extends Command {
1163
+ /**
1164
+ * Base command handler.
1165
+ *
1166
+ * @public
1167
+ * @async
1168
+ * @param {TriviousClient} client
1169
+ * @param {ContextMenuCommandInteraction} interaction
1170
+ * @returns {*}
1171
+ */
1172
+ async execute(client, interaction) {
1173
+ const { run, metadata } = this;
1174
+ const memberHasPermission = await this.validateGuildPermission(
1175
+ client,
1176
+ interaction,
1177
+ metadata.permission,
1178
+ false
1179
+ );
1180
+ if (memberHasPermission) await run(client, interaction);
1181
+ }
1182
+ };
1183
+ var ContextMenuBuilder = class extends ContextMenuCommandBuilder {
1184
+ _active = true;
1185
+ _ownerOnly = false;
1186
+ _permission = 0 /* USER */;
1187
+ _ephemeralReply = false;
1188
+ /**
1189
+ * Set the command as disabled.
1190
+ *
1191
+ * @public
1192
+ * @returns {this}
1193
+ */
1194
+ disable() {
1195
+ this._active = false;
1196
+ return this;
1197
+ }
1198
+ /**
1199
+ * Set the command as owner only.
1200
+ *
1201
+ * @public
1202
+ * @returns {this}
1203
+ */
1204
+ setOwnerOnly() {
1205
+ this._permission = 5 /* BOT_OWNER */;
1206
+ this._ownerOnly = true;
1207
+ return this;
1208
+ }
1209
+ /**
1210
+ * Set the permission level required to run the command.
1211
+ *
1212
+ * @public
1213
+ * @param {PermissionLevel} permission
1214
+ * @returns {this}
1215
+ */
1216
+ setPermission(permission) {
1217
+ this._permission = permission;
1218
+ return this;
1219
+ }
1220
+ /**
1221
+ * Set the interaction as ephemeral.
1222
+ *
1223
+ * @public
1224
+ * @returns {this}
1225
+ */
1226
+ setEphemeralReply() {
1227
+ this._ephemeralReply = true;
1228
+ return this;
1229
+ }
1230
+ /**
1231
+ * Build the builder
1232
+ *
1233
+ * @public
1234
+ * @returns {{ data: ContextMenuBuilder; metadata: ContextMenuMetadata; }}
1235
+ */
1236
+ build() {
1237
+ return {
1238
+ data: this,
1239
+ metadata: {
1240
+ active: this._active,
1241
+ ownerOnly: this._ownerOnly,
1242
+ permission: this._permission,
1243
+ ephemeralReply: this._ephemeralReply
1244
+ }
1245
+ };
1246
+ }
1247
+ };
1248
+ var SubcommandBuilder = class extends SlashCommandSubcommandBuilder {
1249
+ _active = true;
1250
+ _ownerOnly = false;
1251
+ _permission = 0 /* USER */;
1252
+ _ephemeralReply = false;
1253
+ /**
1254
+ * Set the subcommand as disabled.
1255
+ *
1256
+ * @public
1257
+ * @returns {this}
1258
+ */
1259
+ disable() {
1260
+ this._active = false;
1261
+ return this;
1262
+ }
1263
+ /**
1264
+ * Set the subcommand as owner only.
1265
+ *
1266
+ * @public
1267
+ * @returns {this}
1268
+ */
1269
+ setOwnerOnly() {
1270
+ this._permission = 5 /* BOT_OWNER */;
1271
+ this._ownerOnly = true;
1272
+ return this;
1273
+ }
1274
+ /**
1275
+ * Set the permission level required to run the subcommand.
1276
+ *
1277
+ * @public
1278
+ * @param {PermissionLevel} permission
1279
+ * @returns {this}
1280
+ */
1281
+ setPermission(permission) {
1282
+ this._permission = permission;
1283
+ return this;
1284
+ }
1285
+ /**
1286
+ * Set the interaction as ephemeral
1287
+ *
1288
+ * @public
1289
+ * @returns {this}
1290
+ */
1291
+ setEphemeralReply() {
1292
+ this._ephemeralReply = true;
1293
+ return this;
1294
+ }
1295
+ /**
1296
+ * Build the builder.
1297
+ *
1298
+ * @public
1299
+ * @returns {{ data: SlashCommandSubcommandBuilder; metadata: SubcommandMetadata; }}
1300
+ */
1301
+ build() {
1302
+ return {
1303
+ data: this,
1304
+ metadata: {
1305
+ active: this._active,
1306
+ ownerOnly: this._ownerOnly,
1307
+ permission: this._permission,
1308
+ ephemeralReply: this._ephemeralReply
1309
+ }
1310
+ };
1311
+ }
1312
+ };
1313
+ var Subcommand = class {
1314
+ /**
1315
+ * Reply to the interaction respecting command metadata and if the interaction has already been replied to.
1316
+ *
1317
+ * @async
1318
+ * @param {ChatInputCommandInteraction<CacheType>} interaction
1319
+ * @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options
1320
+ * @returns {*}
1321
+ */
1322
+ async reply(interaction, options) {
1323
+ if (interaction.replied) {
1324
+ await interaction.editReply(options);
1325
+ return;
1326
+ }
1327
+ const newOptions = { ...options };
1328
+ if (this.metadata.ephemeralReply) newOptions.flags = ["Ephemeral"];
1329
+ await interaction.reply(newOptions);
1330
+ }
1331
+ };
1332
+
1333
+ // src/core/components/component.base.ts
1334
+ var ComponentBuilder = class {
1335
+ _customId = "";
1336
+ _permission = 0 /* USER */;
1337
+ _ephemeralReply = false;
1338
+ /**
1339
+ * Set the customId for the component.
1340
+ *
1341
+ * @public
1342
+ * @param {{
1343
+ * type: ComponentType;
1344
+ * data: string;
1345
+ * tags?: ComponentCustomIdTag[];
1346
+ * }} options
1347
+ * @returns {this}
1348
+ */
1349
+ setCustomId(options) {
1350
+ const { data, type, tags } = options;
1351
+ this._customId = `${type}:${data}${tags ? `.${tags.join(".")}` : ""}`;
1352
+ return this;
1353
+ }
1354
+ /**
1355
+ * Set the permission required to use the component.
1356
+ *
1357
+ * @public
1358
+ * @param {PermissionLevel} permission
1359
+ * @returns {this}
1360
+ */
1361
+ setPermission(permission) {
1362
+ this._permission = permission;
1363
+ return this;
1364
+ }
1365
+ /**
1366
+ * Set the interaction as ephemeral.
1367
+ *
1368
+ * @public
1369
+ * @returns {this}
1370
+ */
1371
+ setEphemeralReply() {
1372
+ this._ephemeralReply = true;
1373
+ return this;
1374
+ }
1375
+ /**
1376
+ * Builder the builder.
1377
+ *
1378
+ * @public
1379
+ * @returns {{ metadata: ComponentMetadata; }}
1380
+ */
1381
+ build() {
1382
+ return {
1383
+ metadata: {
1384
+ customId: this._customId,
1385
+ permission: this._permission,
1386
+ ephemeralReply: this._ephemeralReply
1387
+ }
1388
+ };
1389
+ }
1390
+ };
1391
+ var Component = class {
1392
+ /**
1393
+ * Validate permissions for a user/member in a guild.
1394
+ *
1395
+ * @async
1396
+ * @param {ComponentInteraction} interaction
1397
+ * @param {PermissionLevel} permission
1398
+ * @param {boolean} [doReply=true] Defaults to `true`
1399
+ * @returns {unknown}
1400
+ */
1401
+ async validateGuildPermission(client, interaction, permission, doReply = true) {
1402
+ if (interaction.guild) {
1403
+ const member = interaction.member;
1404
+ const memberHasPermission = hasPermission(client, { permission, member });
1405
+ if (!memberHasPermission) {
1406
+ if (doReply)
1407
+ await this.reply(interaction, {
1408
+ content: `You do not have permission to run this command, required permission: \`${PermissionLevel[permission]}\``
1409
+ });
1410
+ return false;
1411
+ }
1412
+ }
1413
+ return true;
1414
+ }
1415
+ /**
1416
+ * Reply to the interaction respecting command metadata and if the interaction has already been replied to.
1417
+ *
1418
+ * @async
1419
+ * @param {ComponentInteraction} interaction
1420
+ * @param {(MessagePayload | InteractionEditReplyOptions | InteractionReplyOptions)} options
1421
+ * @returns {*}
1422
+ */
1423
+ async reply(interaction, options) {
1424
+ if (interaction.replied) {
1425
+ await interaction.editReply(options);
1426
+ return;
1427
+ }
1428
+ const newOptions = { ...options };
1429
+ if (this.metadata.ephemeralReply) newOptions.flags = ["Ephemeral"];
1430
+ await interaction.reply(newOptions);
1431
+ }
1432
+ };
1433
+
1434
+ export { BaseRegistry, Command, CommandBuilder, CommandRegistry, Component, ComponentBuilder, ComponentRegistry, ComponentType, ContextMenuBuilder, ContextMenuCommand, PermissionLevel, SlashCommand, Subcommand, SubcommandBuilder, TriviousClient, deconstructCustomId, getPermissionLevel };
11
1435
  //# sourceMappingURL=index.js.map
12
1436
  //# sourceMappingURL=index.js.map