trivious 1.3.1

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