trivious 1.3.17 → 1.3.18

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