trivious 1.3.17 → 1.3.19
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/core/client/trivious.client.cjs +90 -0
- package/dist/core/client/trivious.client.cjs.map +1 -0
- package/dist/core/client/trivious.client.d.cts +3 -0
- package/dist/core/client/trivious.client.d.ts +3 -0
- package/dist/core/client/trivious.client.js +88 -0
- package/dist/core/client/trivious.client.js.map +1 -0
- package/dist/core/commands/command.base.cjs +224 -0
- package/dist/core/commands/command.base.cjs.map +1 -0
- package/dist/core/commands/command.base.d.cts +3 -0
- package/dist/core/commands/command.base.d.ts +3 -0
- package/dist/core/commands/command.base.js +214 -0
- package/dist/core/commands/command.base.js.map +1 -0
- package/dist/core/commands/contextcommand.base.cjs +98 -0
- package/dist/core/commands/contextcommand.base.cjs.map +1 -0
- package/dist/core/commands/contextcommand.base.d.cts +3 -0
- package/dist/core/commands/contextcommand.base.d.ts +3 -0
- package/dist/core/commands/contextcommand.base.js +93 -0
- package/dist/core/commands/contextcommand.base.js.map +1 -0
- package/dist/core/commands/subcommand.base.cjs +96 -0
- package/dist/core/commands/subcommand.base.cjs.map +1 -0
- package/dist/core/commands/subcommand.base.d.cts +3 -0
- package/dist/core/commands/subcommand.base.d.ts +3 -0
- package/dist/core/commands/subcommand.base.js +91 -0
- package/dist/core/commands/subcommand.base.js.map +1 -0
- package/dist/core/components/component.base.cjs +111 -0
- package/dist/core/components/component.base.cjs.map +1 -0
- package/dist/core/components/component.base.d.cts +3 -0
- package/dist/core/components/component.base.d.ts +3 -0
- package/dist/core/components/component.base.js +106 -0
- package/dist/core/components/component.base.js.map +1 -0
- package/dist/core/events/interactionCreate.cjs +68 -0
- package/dist/core/events/interactionCreate.cjs.map +1 -0
- package/dist/core/events/interactionCreate.d.cts +10 -0
- package/dist/core/events/interactionCreate.d.ts +10 -0
- package/dist/core/events/interactionCreate.js +66 -0
- package/dist/core/events/interactionCreate.js.map +1 -0
- package/dist/core/registry/command.registry.cjs +56 -0
- package/dist/core/registry/command.registry.cjs.map +1 -0
- package/dist/core/registry/command.registry.d.cts +3 -0
- package/dist/core/registry/command.registry.d.ts +3 -0
- package/dist/core/registry/command.registry.js +54 -0
- package/dist/core/registry/command.registry.js.map +1 -0
- package/dist/core/registry/component.registry.cjs +42 -0
- package/dist/core/registry/component.registry.cjs.map +1 -0
- package/dist/core/registry/component.registry.d.cts +3 -0
- package/dist/core/registry/component.registry.d.ts +3 -0
- package/dist/core/registry/component.registry.js +40 -0
- package/dist/core/registry/component.registry.js.map +1 -0
- package/dist/core/registry/event.registry.cjs +57 -0
- package/dist/core/registry/event.registry.cjs.map +1 -0
- package/dist/core/registry/event.registry.d.cts +3 -0
- package/dist/core/registry/event.registry.d.ts +3 -0
- package/dist/core/registry/event.registry.js +51 -0
- package/dist/core/registry/event.registry.js.map +1 -0
- package/dist/core/registry/index.cjs +49 -0
- package/dist/core/registry/index.cjs.map +1 -0
- package/dist/core/registry/index.d.cts +19 -0
- package/dist/core/registry/index.d.ts +19 -0
- package/dist/core/registry/index.js +39 -0
- package/dist/core/registry/index.js.map +1 -0
- package/dist/core/registry/module.registry.cjs +57 -0
- package/dist/core/registry/module.registry.cjs.map +1 -0
- package/dist/core/registry/module.registry.d.cts +3 -0
- package/dist/core/registry/module.registry.d.ts +3 -0
- package/dist/core/registry/module.registry.js +55 -0
- package/dist/core/registry/module.registry.js.map +1 -0
- package/dist/index-BPaYmWRO.d.ts +927 -0
- package/dist/index-CU2Xl9Xo.d.cts +927 -0
- package/dist/index.cjs +67 -1446
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -974
- package/dist/index.d.ts +2 -974
- package/dist/index.js +10 -1436
- package/dist/index.js.map +1 -1
- package/dist/shared/typings/client.cjs +4 -0
- package/dist/shared/typings/client.cjs.map +1 -0
- package/dist/shared/typings/client.d.cts +3 -0
- package/dist/shared/typings/client.d.ts +3 -0
- package/dist/shared/typings/client.js +3 -0
- package/dist/shared/typings/client.js.map +1 -0
- package/dist/shared/typings/commands.cjs +4 -0
- package/dist/shared/typings/commands.cjs.map +1 -0
- package/dist/shared/typings/commands.d.cts +3 -0
- package/dist/shared/typings/commands.d.ts +3 -0
- package/dist/shared/typings/commands.js +3 -0
- package/dist/shared/typings/commands.js.map +1 -0
- package/dist/shared/typings/components.cjs +22 -0
- package/dist/shared/typings/components.cjs.map +1 -0
- package/dist/shared/typings/components.d.cts +3 -0
- package/dist/shared/typings/components.d.ts +3 -0
- package/dist/shared/typings/components.js +19 -0
- package/dist/shared/typings/components.js.map +1 -0
- package/dist/shared/typings/events.cjs +4 -0
- package/dist/shared/typings/events.cjs.map +1 -0
- package/dist/shared/typings/events.d.cts +3 -0
- package/dist/shared/typings/events.d.ts +3 -0
- package/dist/shared/typings/events.js +3 -0
- package/dist/shared/typings/events.js.map +1 -0
- package/dist/shared/typings/index.cjs +56 -0
- package/dist/shared/typings/index.cjs.map +1 -0
- package/dist/shared/typings/index.d.cts +3 -0
- package/dist/shared/typings/index.d.ts +3 -0
- package/dist/shared/typings/index.js +9 -0
- package/dist/shared/typings/index.js.map +1 -0
- package/dist/shared/typings/module.cjs +4 -0
- package/dist/shared/typings/module.cjs.map +1 -0
- package/dist/shared/typings/module.d.cts +3 -0
- package/dist/shared/typings/module.d.ts +3 -0
- package/dist/shared/typings/module.js +3 -0
- package/dist/shared/typings/module.js.map +1 -0
- package/dist/shared/typings/permissions.cjs +22 -0
- package/dist/shared/typings/permissions.cjs.map +1 -0
- package/dist/shared/typings/permissions.d.cts +3 -0
- package/dist/shared/typings/permissions.d.ts +3 -0
- package/dist/shared/typings/permissions.js +19 -0
- package/dist/shared/typings/permissions.js.map +1 -0
- package/dist/shared/typings/registry.cjs +63 -0
- package/dist/shared/typings/registry.cjs.map +1 -0
- package/dist/shared/typings/registry.d.cts +51 -0
- package/dist/shared/typings/registry.d.ts +51 -0
- package/dist/shared/typings/registry.js +61 -0
- package/dist/shared/typings/registry.js.map +1 -0
- package/dist/shared/utility/functions.cjs +81 -0
- package/dist/shared/utility/functions.cjs.map +1 -0
- package/dist/shared/utility/functions.d.cts +56 -0
- package/dist/shared/utility/functions.d.ts +56 -0
- package/dist/shared/utility/functions.js +74 -0
- package/dist/shared/utility/functions.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var url = require('url');
|
|
4
|
+
|
|
5
|
+
class BaseRegistry {
|
|
6
|
+
/**
|
|
7
|
+
* Get all of loaded T
|
|
8
|
+
*
|
|
9
|
+
* @returns {Collection<string, T>}
|
|
10
|
+
*/
|
|
11
|
+
get() {
|
|
12
|
+
return this.items;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Import a file from a path to be loaded.
|
|
16
|
+
*
|
|
17
|
+
* @protected
|
|
18
|
+
* @async
|
|
19
|
+
* @template T
|
|
20
|
+
* @param {string} filePath
|
|
21
|
+
* @returns {Promise<T | null>}
|
|
22
|
+
*/
|
|
23
|
+
async importFile(filePath) {
|
|
24
|
+
try {
|
|
25
|
+
const { default: file } = await import(url.pathToFileURL(filePath).href);
|
|
26
|
+
const imports = file.default ?? file;
|
|
27
|
+
if (!imports) return null;
|
|
28
|
+
if (typeof imports === "function" && imports.prototype) {
|
|
29
|
+
return new imports();
|
|
30
|
+
}
|
|
31
|
+
if (typeof imports === "object") {
|
|
32
|
+
if (Object.keys(imports).length === 0) return null;
|
|
33
|
+
return imports;
|
|
34
|
+
}
|
|
35
|
+
console.error(`Invalid export in ${filePath}: expected class or object`);
|
|
36
|
+
return null;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error("Failed to import:", filePath, error);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Clear file path cache.
|
|
44
|
+
* Does not run in production environment.
|
|
45
|
+
*
|
|
46
|
+
* @protected
|
|
47
|
+
* @async
|
|
48
|
+
* @param {string} filePath
|
|
49
|
+
* @returns {*}
|
|
50
|
+
*/
|
|
51
|
+
async clearCache(filePath) {
|
|
52
|
+
if (process.env.NODE_ENV === "production") return;
|
|
53
|
+
try {
|
|
54
|
+
const resvoled = require.resolve(filePath);
|
|
55
|
+
delete require.cache[resvoled];
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.BaseRegistry = BaseRegistry;
|
|
62
|
+
//# sourceMappingURL=registry.cjs.map
|
|
63
|
+
//# sourceMappingURL=registry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/typings/registry.ts"],"names":["pathToFileURL"],"mappings":";;;;AAYO,MAAe,YAAA,CAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBrC,GAAA,GAAM;AACL,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAgB,WAAc,QAAA,EAAqC;AAClE,IAAA,IAAI;AACH,MAAA,MAAM,EAAE,SAAS,IAAA,EAAK,GAAI,MAAM,OAAOA,iBAAA,CAAc,QAAQ,CAAA,CAAE,IAAA,CAAA;AAC/D,MAAA,MAAM,OAAA,GAAU,KAAK,OAAA,IAAW,IAAA;AAEhC,MAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AAErB,MAAA,IAAI,OAAO,OAAA,KAAY,UAAA,IAAc,OAAA,CAAQ,SAAA,EAAW;AACvD,QAAA,OAAO,IAAI,OAAA,EAAQ;AAAA,MACpB;AAEA,MAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAChC,QAAA,IAAI,OAAO,IAAA,CAAK,OAAO,CAAA,CAAE,MAAA,KAAW,GAAG,OAAO,IAAA;AAC9C,QAAA,OAAO,OAAA;AAAA,MACR;AAEA,MAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,kBAAA,EAAqB,QAAQ,CAAA,0BAAA,CAA4B,CAAA;AACvE,MAAA,OAAO,IAAA;AAAA,IACR,SAAS,KAAA,EAAY;AACpB,MAAA,OAAA,CAAQ,KAAA,CAAM,mBAAA,EAAqB,QAAA,EAAU,KAAK,CAAA;AAClD,MAAA,OAAO,IAAA;AAAA,IACR;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAgB,WAAW,QAAA,EAAkB;AAC5C,IAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AAC3C,IAAA,IAAI;AACH,MAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,OAAA,CAAQ,QAAQ,CAAA;AACzC,MAAA,OAAO,OAAA,CAAQ,MAAM,QAAQ,CAAA;AAAA,IAC9B,CAAA,CAAA,MAAQ;AAAA,IAAC;AAAA,EACV;AACD","file":"registry.cjs","sourcesContent":["import { Collection } from \"discord.js\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * Base registry for loading, getting and binding core events and functions.\n *\n * @export\n * @abstract\n * @class BaseRegistry\n * @typedef {BaseRegistry}\n * @template T\n */\nexport abstract class BaseRegistry<T> {\n\tprotected abstract items: Collection<string, T>;\n\t/**\n\t * Load all of T\n\t *\n\t * @protected\n\t * @abstract\n\t * @param {string} directory\n\t * @returns {Promise<this>}\n\t */\n\tprotected abstract load(directory: string): Promise<this>;\n\n\t/**\n\t * Get all of loaded T\n\t *\n\t * @returns {Collection<string, T>}\n\t */\n\tget() {\n\t\treturn this.items;\n\t}\n\n\t/**\n\t * Import a file from a path to be loaded.\n\t *\n\t * @protected\n\t * @async\n\t * @template T\n\t * @param {string} filePath\n\t * @returns {Promise<T | null>}\n\t */\n\tprotected async importFile<T>(filePath: string): Promise<T | null> {\n\t\ttry {\n\t\t\tconst { default: file } = await import(pathToFileURL(filePath).href);\n\t\t\tconst imports = file.default ?? file;\n\n\t\t\tif (!imports) return null;\n\n\t\t\tif (typeof imports === \"function\" && imports.prototype) {\n\t\t\t\treturn new imports();\n\t\t\t}\n\n\t\t\tif (typeof imports === \"object\") {\n\t\t\t\tif (Object.keys(imports).length === 0) return null;\n\t\t\t\treturn imports as T;\n\t\t\t}\n\n\t\t\tconsole.error(`Invalid export in ${filePath}: expected class or object`);\n\t\t\treturn null;\n\t\t} catch (error: any) {\n\t\t\tconsole.error(\"Failed to import:\", filePath, error);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Clear file path cache.\n\t * Does not run in production environment.\n\t *\n\t * @protected\n\t * @async\n\t * @param {string} filePath\n\t * @returns {*}\n\t */\n\tprotected async clearCache(filePath: string) {\n\t\tif (process.env.NODE_ENV === \"production\") return;\n\t\ttry {\n\t\t\tconst resvoled = require.resolve(filePath);\n\t\t\tdelete require.cache[resvoled];\n\t\t} catch {}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Collection } from 'discord.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base registry for loading, getting and binding core events and functions.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @abstract
|
|
8
|
+
* @class BaseRegistry
|
|
9
|
+
* @typedef {BaseRegistry}
|
|
10
|
+
* @template T
|
|
11
|
+
*/
|
|
12
|
+
declare abstract class BaseRegistry<T> {
|
|
13
|
+
protected abstract items: Collection<string, T>;
|
|
14
|
+
/**
|
|
15
|
+
* Load all of T
|
|
16
|
+
*
|
|
17
|
+
* @protected
|
|
18
|
+
* @abstract
|
|
19
|
+
* @param {string} directory
|
|
20
|
+
* @returns {Promise<this>}
|
|
21
|
+
*/
|
|
22
|
+
protected abstract load(directory: string): Promise<this>;
|
|
23
|
+
/**
|
|
24
|
+
* Get all of loaded T
|
|
25
|
+
*
|
|
26
|
+
* @returns {Collection<string, T>}
|
|
27
|
+
*/
|
|
28
|
+
get(): Collection<string, T>;
|
|
29
|
+
/**
|
|
30
|
+
* Import a file from a path to be loaded.
|
|
31
|
+
*
|
|
32
|
+
* @protected
|
|
33
|
+
* @async
|
|
34
|
+
* @template T
|
|
35
|
+
* @param {string} filePath
|
|
36
|
+
* @returns {Promise<T | null>}
|
|
37
|
+
*/
|
|
38
|
+
protected importFile<T>(filePath: string): Promise<T | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Clear file path cache.
|
|
41
|
+
* Does not run in production environment.
|
|
42
|
+
*
|
|
43
|
+
* @protected
|
|
44
|
+
* @async
|
|
45
|
+
* @param {string} filePath
|
|
46
|
+
* @returns {*}
|
|
47
|
+
*/
|
|
48
|
+
protected clearCache(filePath: string): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { BaseRegistry };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Collection } from 'discord.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base registry for loading, getting and binding core events and functions.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @abstract
|
|
8
|
+
* @class BaseRegistry
|
|
9
|
+
* @typedef {BaseRegistry}
|
|
10
|
+
* @template T
|
|
11
|
+
*/
|
|
12
|
+
declare abstract class BaseRegistry<T> {
|
|
13
|
+
protected abstract items: Collection<string, T>;
|
|
14
|
+
/**
|
|
15
|
+
* Load all of T
|
|
16
|
+
*
|
|
17
|
+
* @protected
|
|
18
|
+
* @abstract
|
|
19
|
+
* @param {string} directory
|
|
20
|
+
* @returns {Promise<this>}
|
|
21
|
+
*/
|
|
22
|
+
protected abstract load(directory: string): Promise<this>;
|
|
23
|
+
/**
|
|
24
|
+
* Get all of loaded T
|
|
25
|
+
*
|
|
26
|
+
* @returns {Collection<string, T>}
|
|
27
|
+
*/
|
|
28
|
+
get(): Collection<string, T>;
|
|
29
|
+
/**
|
|
30
|
+
* Import a file from a path to be loaded.
|
|
31
|
+
*
|
|
32
|
+
* @protected
|
|
33
|
+
* @async
|
|
34
|
+
* @template T
|
|
35
|
+
* @param {string} filePath
|
|
36
|
+
* @returns {Promise<T | null>}
|
|
37
|
+
*/
|
|
38
|
+
protected importFile<T>(filePath: string): Promise<T | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Clear file path cache.
|
|
41
|
+
* Does not run in production environment.
|
|
42
|
+
*
|
|
43
|
+
* @protected
|
|
44
|
+
* @async
|
|
45
|
+
* @param {string} filePath
|
|
46
|
+
* @returns {*}
|
|
47
|
+
*/
|
|
48
|
+
protected clearCache(filePath: string): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { BaseRegistry };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { pathToFileURL } from 'url';
|
|
2
|
+
|
|
3
|
+
class BaseRegistry {
|
|
4
|
+
/**
|
|
5
|
+
* Get all of loaded T
|
|
6
|
+
*
|
|
7
|
+
* @returns {Collection<string, T>}
|
|
8
|
+
*/
|
|
9
|
+
get() {
|
|
10
|
+
return this.items;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Import a file from a path to be loaded.
|
|
14
|
+
*
|
|
15
|
+
* @protected
|
|
16
|
+
* @async
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {string} filePath
|
|
19
|
+
* @returns {Promise<T | null>}
|
|
20
|
+
*/
|
|
21
|
+
async importFile(filePath) {
|
|
22
|
+
try {
|
|
23
|
+
const { default: file } = await import(pathToFileURL(filePath).href);
|
|
24
|
+
const imports = file.default ?? file;
|
|
25
|
+
if (!imports) return null;
|
|
26
|
+
if (typeof imports === "function" && imports.prototype) {
|
|
27
|
+
return new imports();
|
|
28
|
+
}
|
|
29
|
+
if (typeof imports === "object") {
|
|
30
|
+
if (Object.keys(imports).length === 0) return null;
|
|
31
|
+
return imports;
|
|
32
|
+
}
|
|
33
|
+
console.error(`Invalid export in ${filePath}: expected class or object`);
|
|
34
|
+
return null;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error("Failed to import:", filePath, error);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Clear file path cache.
|
|
42
|
+
* Does not run in production environment.
|
|
43
|
+
*
|
|
44
|
+
* @protected
|
|
45
|
+
* @async
|
|
46
|
+
* @param {string} filePath
|
|
47
|
+
* @returns {*}
|
|
48
|
+
*/
|
|
49
|
+
async clearCache(filePath) {
|
|
50
|
+
if (process.env.NODE_ENV === "production") return;
|
|
51
|
+
try {
|
|
52
|
+
const resvoled = require.resolve(filePath);
|
|
53
|
+
delete require.cache[resvoled];
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { BaseRegistry };
|
|
60
|
+
//# sourceMappingURL=registry.js.map
|
|
61
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/typings/registry.ts"],"names":[],"mappings":";;AAYO,MAAe,YAAA,CAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBrC,GAAA,GAAM;AACL,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAgB,WAAc,QAAA,EAAqC;AAClE,IAAA,IAAI;AACH,MAAA,MAAM,EAAE,SAAS,IAAA,EAAK,GAAI,MAAM,OAAO,aAAA,CAAc,QAAQ,CAAA,CAAE,IAAA,CAAA;AAC/D,MAAA,MAAM,OAAA,GAAU,KAAK,OAAA,IAAW,IAAA;AAEhC,MAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AAErB,MAAA,IAAI,OAAO,OAAA,KAAY,UAAA,IAAc,OAAA,CAAQ,SAAA,EAAW;AACvD,QAAA,OAAO,IAAI,OAAA,EAAQ;AAAA,MACpB;AAEA,MAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAChC,QAAA,IAAI,OAAO,IAAA,CAAK,OAAO,CAAA,CAAE,MAAA,KAAW,GAAG,OAAO,IAAA;AAC9C,QAAA,OAAO,OAAA;AAAA,MACR;AAEA,MAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,kBAAA,EAAqB,QAAQ,CAAA,0BAAA,CAA4B,CAAA;AACvE,MAAA,OAAO,IAAA;AAAA,IACR,SAAS,KAAA,EAAY;AACpB,MAAA,OAAA,CAAQ,KAAA,CAAM,mBAAA,EAAqB,QAAA,EAAU,KAAK,CAAA;AAClD,MAAA,OAAO,IAAA;AAAA,IACR;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAgB,WAAW,QAAA,EAAkB;AAC5C,IAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AAC3C,IAAA,IAAI;AACH,MAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,OAAA,CAAQ,QAAQ,CAAA;AACzC,MAAA,OAAO,OAAA,CAAQ,MAAM,QAAQ,CAAA;AAAA,IAC9B,CAAA,CAAA,MAAQ;AAAA,IAAC;AAAA,EACV;AACD","file":"registry.js","sourcesContent":["import { Collection } from \"discord.js\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * Base registry for loading, getting and binding core events and functions.\n *\n * @export\n * @abstract\n * @class BaseRegistry\n * @typedef {BaseRegistry}\n * @template T\n */\nexport abstract class BaseRegistry<T> {\n\tprotected abstract items: Collection<string, T>;\n\t/**\n\t * Load all of T\n\t *\n\t * @protected\n\t * @abstract\n\t * @param {string} directory\n\t * @returns {Promise<this>}\n\t */\n\tprotected abstract load(directory: string): Promise<this>;\n\n\t/**\n\t * Get all of loaded T\n\t *\n\t * @returns {Collection<string, T>}\n\t */\n\tget() {\n\t\treturn this.items;\n\t}\n\n\t/**\n\t * Import a file from a path to be loaded.\n\t *\n\t * @protected\n\t * @async\n\t * @template T\n\t * @param {string} filePath\n\t * @returns {Promise<T | null>}\n\t */\n\tprotected async importFile<T>(filePath: string): Promise<T | null> {\n\t\ttry {\n\t\t\tconst { default: file } = await import(pathToFileURL(filePath).href);\n\t\t\tconst imports = file.default ?? file;\n\n\t\t\tif (!imports) return null;\n\n\t\t\tif (typeof imports === \"function\" && imports.prototype) {\n\t\t\t\treturn new imports();\n\t\t\t}\n\n\t\t\tif (typeof imports === \"object\") {\n\t\t\t\tif (Object.keys(imports).length === 0) return null;\n\t\t\t\treturn imports as T;\n\t\t\t}\n\n\t\t\tconsole.error(`Invalid export in ${filePath}: expected class or object`);\n\t\t\treturn null;\n\t\t} catch (error: any) {\n\t\t\tconsole.error(\"Failed to import:\", filePath, error);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Clear file path cache.\n\t * Does not run in production environment.\n\t *\n\t * @protected\n\t * @async\n\t * @param {string} filePath\n\t * @returns {*}\n\t */\n\tprotected async clearCache(filePath: string) {\n\t\tif (process.env.NODE_ENV === \"production\") return;\n\t\ttry {\n\t\t\tconst resvoled = require.resolve(filePath);\n\t\t\tdelete require.cache[resvoled];\n\t\t} catch {}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var node_path = require('node:path');
|
|
5
|
+
var url = require('url');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var permissions_js = require('../typings/permissions.js');
|
|
8
|
+
|
|
9
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
+
const __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('functions.cjs', document.baseURI).href)));
|
|
11
|
+
const __dirname$1 = path.dirname(__filename$1);
|
|
12
|
+
const getPackageRoot = () => {
|
|
13
|
+
let dir = __dirname$1;
|
|
14
|
+
while (dir !== path.dirname(dir)) {
|
|
15
|
+
if (fs.existsSync(node_path.join(dir, "package.json")) || fs.existsSync(node_path.join(dir, "node_modules"))) {
|
|
16
|
+
return dir;
|
|
17
|
+
}
|
|
18
|
+
dir = path.dirname(dir);
|
|
19
|
+
}
|
|
20
|
+
return __dirname$1;
|
|
21
|
+
};
|
|
22
|
+
const FRAMEWORK_PACKAGE_ROOT = getPackageRoot();
|
|
23
|
+
function getCorePath(options) {
|
|
24
|
+
const { userPath, coreDirectory } = options;
|
|
25
|
+
if (userPath) {
|
|
26
|
+
return resolveUserPath(userPath);
|
|
27
|
+
}
|
|
28
|
+
const builtInCandidates = [
|
|
29
|
+
node_path.join(FRAMEWORK_PACKAGE_ROOT, "lib", coreDirectory),
|
|
30
|
+
node_path.join(FRAMEWORK_PACKAGE_ROOT, "dist", coreDirectory)
|
|
31
|
+
];
|
|
32
|
+
for (const candidate of builtInCandidates) {
|
|
33
|
+
if (fs.existsSync(candidate)) {
|
|
34
|
+
return candidate;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return node_path.join(FRAMEWORK_PACKAGE_ROOT, "lib", coreDirectory);
|
|
38
|
+
}
|
|
39
|
+
function resolveUserPath(relativePath) {
|
|
40
|
+
const candidates = [
|
|
41
|
+
node_path.join(process.cwd(), relativePath),
|
|
42
|
+
node_path.join(process.cwd(), "lib", relativePath),
|
|
43
|
+
node_path.join(process.cwd(), "dist", relativePath),
|
|
44
|
+
node_path.join(FRAMEWORK_PACKAGE_ROOT, relativePath),
|
|
45
|
+
node_path.join(FRAMEWORK_PACKAGE_ROOT, "lib", relativePath),
|
|
46
|
+
node_path.join(FRAMEWORK_PACKAGE_ROOT, "dist", relativePath)
|
|
47
|
+
];
|
|
48
|
+
for (const candidate of candidates) {
|
|
49
|
+
const full = node_path.resolve(candidate);
|
|
50
|
+
if (fs.existsSync(full)) return full;
|
|
51
|
+
}
|
|
52
|
+
return node_path.join(process.cwd(), relativePath);
|
|
53
|
+
}
|
|
54
|
+
async function exists(path) {
|
|
55
|
+
try {
|
|
56
|
+
await fs.promises.access(path);
|
|
57
|
+
return true;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function hasPermission(client, options) {
|
|
63
|
+
const { permission, user, member } = options;
|
|
64
|
+
if (user) {
|
|
65
|
+
if (permission === permissions_js.PermissionLevel.BOT_OWNER) return user.id === "424764032667484171";
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (member) {
|
|
69
|
+
const memberPermission = permissions_js.getPermissionLevel(client, member);
|
|
70
|
+
return memberPermission >= permission;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
exports.FRAMEWORK_PACKAGE_ROOT = FRAMEWORK_PACKAGE_ROOT;
|
|
76
|
+
exports.exists = exists;
|
|
77
|
+
exports.getCorePath = getCorePath;
|
|
78
|
+
exports.hasPermission = hasPermission;
|
|
79
|
+
exports.resolveUserPath = resolveUserPath;
|
|
80
|
+
//# sourceMappingURL=functions.cjs.map
|
|
81
|
+
//# sourceMappingURL=functions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/utility/functions.ts"],"names":["__filename","fileURLToPath","__dirname","dirname","existsSync","join","resolve","fs","PermissionLevel","getPermissionLevel"],"mappings":"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","file":"functions.cjs","sourcesContent":["import TriviousClient from \"../../core/client/trivious.client.js\";\nimport { promises as fs, existsSync } from \"fs\";\nimport { join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"url\";\nimport { dirname } from \"path\";\nimport { getPermissionLevel, PermissionLevel } from \"../typings/permissions.js\";\nimport { GuildMember, User } from \"discord.js\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\n/**\n * Get the package root.\n *\n * @returns {string}\n */\nconst getPackageRoot = (): string => {\n\tlet dir = __dirname;\n\n\twhile (dir !== dirname(dir)) {\n\t\tif (existsSync(join(dir, \"package.json\")) || existsSync(join(dir, \"node_modules\"))) {\n\t\t\treturn dir;\n\t\t}\n\t\tdir = dirname(dir);\n\t}\n\treturn __dirname;\n};\n\n/**\n * Framework package root.\n *\n * @type {string}\n */\nexport const FRAMEWORK_PACKAGE_ROOT = getPackageRoot();\n\n/**\n * Get the core path.\n *\n * @export\n * @param {{ userPath?: string; coreDirectory: string }} options\n * @returns {string}\n */\nexport function getCorePath(options: { userPath?: string; coreDirectory: string }): string {\n\tconst { userPath, coreDirectory } = options;\n\tif (userPath) {\n\t\treturn resolveUserPath(userPath);\n\t}\n\n\tconst builtInCandidates = [\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, \"lib\", coreDirectory),\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, \"dist\", coreDirectory),\n\t];\n\n\tfor (const candidate of builtInCandidates) {\n\t\tif (existsSync(candidate)) {\n\t\t\treturn candidate;\n\t\t}\n\t}\n\n\treturn join(FRAMEWORK_PACKAGE_ROOT, \"lib\", coreDirectory);\n}\n\n/**\n * Resolve a user given core path.\n *\n * @export\n * @param {string} relativePath\n * @returns {string}\n */\nexport function resolveUserPath(relativePath: string): string {\n\tconst candidates = [\n\t\tjoin(process.cwd(), relativePath),\n\n\t\tjoin(process.cwd(), \"lib\", relativePath),\n\t\tjoin(process.cwd(), \"dist\", relativePath),\n\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, relativePath),\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, \"lib\", relativePath),\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, \"dist\", relativePath),\n\t];\n\n\tfor (const candidate of candidates) {\n\t\tconst full = resolve(candidate);\n\t\tif (existsSync(full)) return full;\n\t}\n\n\treturn join(process.cwd(), relativePath);\n}\n\n/**\n * Whether a directory or file exists.\n *\n * @export\n * @async\n * @param {string} path\n * @returns {unknown}\n */\nexport async function exists(path: string) {\n\ttry {\n\t\tawait fs.access(path);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Whether a user/member has permission.\n *\n * @export\n * @param {{\n * \tpermission: PermissionLevel;\n * \tuser?: User;\n * \tmember?: GuildMember;\n * }} options\n * @returns {boolean}\n */\nexport function hasPermission(\n\tclient: TriviousClient,\n\toptions: {\n\t\tpermission: PermissionLevel;\n\t\tuser?: User;\n\t\tmember?: GuildMember;\n\t}\n) {\n\tconst { permission, user, member } = options;\n\n\tif (user) {\n\t\tif (permission === PermissionLevel.BOT_OWNER) return user.id === \"424764032667484171\";\n\t\treturn true;\n\t}\n\n\tif (member) {\n\t\tconst memberPermission = getPermissionLevel(client, member);\n\t\treturn memberPermission >= permission;\n\t}\n\n\treturn false;\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { T as TriviousClient, P as PermissionLevel } from '../../index-CU2Xl9Xo.cjs';
|
|
2
|
+
import { User, GuildMember } from 'discord.js';
|
|
3
|
+
import '../typings/registry.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Framework package root.
|
|
7
|
+
*
|
|
8
|
+
* @type {string}
|
|
9
|
+
*/
|
|
10
|
+
declare const FRAMEWORK_PACKAGE_ROOT: string;
|
|
11
|
+
/**
|
|
12
|
+
* Get the core path.
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @param {{ userPath?: string; coreDirectory: string }} options
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
declare function getCorePath(options: {
|
|
19
|
+
userPath?: string;
|
|
20
|
+
coreDirectory: string;
|
|
21
|
+
}): string;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a user given core path.
|
|
24
|
+
*
|
|
25
|
+
* @export
|
|
26
|
+
* @param {string} relativePath
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
declare function resolveUserPath(relativePath: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a directory or file exists.
|
|
32
|
+
*
|
|
33
|
+
* @export
|
|
34
|
+
* @async
|
|
35
|
+
* @param {string} path
|
|
36
|
+
* @returns {unknown}
|
|
37
|
+
*/
|
|
38
|
+
declare function exists(path: string): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Whether a user/member has permission.
|
|
41
|
+
*
|
|
42
|
+
* @export
|
|
43
|
+
* @param {{
|
|
44
|
+
* permission: PermissionLevel;
|
|
45
|
+
* user?: User;
|
|
46
|
+
* member?: GuildMember;
|
|
47
|
+
* }} options
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
declare function hasPermission(client: TriviousClient, options: {
|
|
51
|
+
permission: PermissionLevel;
|
|
52
|
+
user?: User;
|
|
53
|
+
member?: GuildMember;
|
|
54
|
+
}): boolean;
|
|
55
|
+
|
|
56
|
+
export { FRAMEWORK_PACKAGE_ROOT, exists, getCorePath, hasPermission, resolveUserPath };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { T as TriviousClient, P as PermissionLevel } from '../../index-BPaYmWRO.js';
|
|
2
|
+
import { User, GuildMember } from 'discord.js';
|
|
3
|
+
import '../typings/registry.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Framework package root.
|
|
7
|
+
*
|
|
8
|
+
* @type {string}
|
|
9
|
+
*/
|
|
10
|
+
declare const FRAMEWORK_PACKAGE_ROOT: string;
|
|
11
|
+
/**
|
|
12
|
+
* Get the core path.
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @param {{ userPath?: string; coreDirectory: string }} options
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
declare function getCorePath(options: {
|
|
19
|
+
userPath?: string;
|
|
20
|
+
coreDirectory: string;
|
|
21
|
+
}): string;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a user given core path.
|
|
24
|
+
*
|
|
25
|
+
* @export
|
|
26
|
+
* @param {string} relativePath
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
declare function resolveUserPath(relativePath: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a directory or file exists.
|
|
32
|
+
*
|
|
33
|
+
* @export
|
|
34
|
+
* @async
|
|
35
|
+
* @param {string} path
|
|
36
|
+
* @returns {unknown}
|
|
37
|
+
*/
|
|
38
|
+
declare function exists(path: string): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Whether a user/member has permission.
|
|
41
|
+
*
|
|
42
|
+
* @export
|
|
43
|
+
* @param {{
|
|
44
|
+
* permission: PermissionLevel;
|
|
45
|
+
* user?: User;
|
|
46
|
+
* member?: GuildMember;
|
|
47
|
+
* }} options
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
declare function hasPermission(client: TriviousClient, options: {
|
|
51
|
+
permission: PermissionLevel;
|
|
52
|
+
user?: User;
|
|
53
|
+
member?: GuildMember;
|
|
54
|
+
}): boolean;
|
|
55
|
+
|
|
56
|
+
export { FRAMEWORK_PACKAGE_ROOT, exists, getCorePath, hasPermission, resolveUserPath };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { existsSync, promises } from 'fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
import { PermissionLevel, getPermissionLevel } from '../typings/permissions.js';
|
|
6
|
+
|
|
7
|
+
const __filename$1 = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname$1 = dirname(__filename$1);
|
|
9
|
+
const getPackageRoot = () => {
|
|
10
|
+
let dir = __dirname$1;
|
|
11
|
+
while (dir !== dirname(dir)) {
|
|
12
|
+
if (existsSync(join(dir, "package.json")) || existsSync(join(dir, "node_modules"))) {
|
|
13
|
+
return dir;
|
|
14
|
+
}
|
|
15
|
+
dir = dirname(dir);
|
|
16
|
+
}
|
|
17
|
+
return __dirname$1;
|
|
18
|
+
};
|
|
19
|
+
const FRAMEWORK_PACKAGE_ROOT = getPackageRoot();
|
|
20
|
+
function getCorePath(options) {
|
|
21
|
+
const { userPath, coreDirectory } = options;
|
|
22
|
+
if (userPath) {
|
|
23
|
+
return resolveUserPath(userPath);
|
|
24
|
+
}
|
|
25
|
+
const builtInCandidates = [
|
|
26
|
+
join(FRAMEWORK_PACKAGE_ROOT, "lib", coreDirectory),
|
|
27
|
+
join(FRAMEWORK_PACKAGE_ROOT, "dist", coreDirectory)
|
|
28
|
+
];
|
|
29
|
+
for (const candidate of builtInCandidates) {
|
|
30
|
+
if (existsSync(candidate)) {
|
|
31
|
+
return candidate;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return join(FRAMEWORK_PACKAGE_ROOT, "lib", coreDirectory);
|
|
35
|
+
}
|
|
36
|
+
function resolveUserPath(relativePath) {
|
|
37
|
+
const candidates = [
|
|
38
|
+
join(process.cwd(), relativePath),
|
|
39
|
+
join(process.cwd(), "lib", relativePath),
|
|
40
|
+
join(process.cwd(), "dist", relativePath),
|
|
41
|
+
join(FRAMEWORK_PACKAGE_ROOT, relativePath),
|
|
42
|
+
join(FRAMEWORK_PACKAGE_ROOT, "lib", relativePath),
|
|
43
|
+
join(FRAMEWORK_PACKAGE_ROOT, "dist", relativePath)
|
|
44
|
+
];
|
|
45
|
+
for (const candidate of candidates) {
|
|
46
|
+
const full = resolve(candidate);
|
|
47
|
+
if (existsSync(full)) return full;
|
|
48
|
+
}
|
|
49
|
+
return join(process.cwd(), relativePath);
|
|
50
|
+
}
|
|
51
|
+
async function exists(path) {
|
|
52
|
+
try {
|
|
53
|
+
await promises.access(path);
|
|
54
|
+
return true;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function hasPermission(client, options) {
|
|
60
|
+
const { permission, user, member } = options;
|
|
61
|
+
if (user) {
|
|
62
|
+
if (permission === PermissionLevel.BOT_OWNER) return user.id === "424764032667484171";
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (member) {
|
|
66
|
+
const memberPermission = getPermissionLevel(client, member);
|
|
67
|
+
return memberPermission >= permission;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { FRAMEWORK_PACKAGE_ROOT, exists, getCorePath, hasPermission, resolveUserPath };
|
|
73
|
+
//# sourceMappingURL=functions.js.map
|
|
74
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/shared/utility/functions.ts"],"names":["__filename","__dirname","fs"],"mappings":"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","file":"functions.js","sourcesContent":["import TriviousClient from \"../../core/client/trivious.client.js\";\nimport { promises as fs, existsSync } from \"fs\";\nimport { join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"url\";\nimport { dirname } from \"path\";\nimport { getPermissionLevel, PermissionLevel } from \"../typings/permissions.js\";\nimport { GuildMember, User } from \"discord.js\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\n/**\n * Get the package root.\n *\n * @returns {string}\n */\nconst getPackageRoot = (): string => {\n\tlet dir = __dirname;\n\n\twhile (dir !== dirname(dir)) {\n\t\tif (existsSync(join(dir, \"package.json\")) || existsSync(join(dir, \"node_modules\"))) {\n\t\t\treturn dir;\n\t\t}\n\t\tdir = dirname(dir);\n\t}\n\treturn __dirname;\n};\n\n/**\n * Framework package root.\n *\n * @type {string}\n */\nexport const FRAMEWORK_PACKAGE_ROOT = getPackageRoot();\n\n/**\n * Get the core path.\n *\n * @export\n * @param {{ userPath?: string; coreDirectory: string }} options\n * @returns {string}\n */\nexport function getCorePath(options: { userPath?: string; coreDirectory: string }): string {\n\tconst { userPath, coreDirectory } = options;\n\tif (userPath) {\n\t\treturn resolveUserPath(userPath);\n\t}\n\n\tconst builtInCandidates = [\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, \"lib\", coreDirectory),\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, \"dist\", coreDirectory),\n\t];\n\n\tfor (const candidate of builtInCandidates) {\n\t\tif (existsSync(candidate)) {\n\t\t\treturn candidate;\n\t\t}\n\t}\n\n\treturn join(FRAMEWORK_PACKAGE_ROOT, \"lib\", coreDirectory);\n}\n\n/**\n * Resolve a user given core path.\n *\n * @export\n * @param {string} relativePath\n * @returns {string}\n */\nexport function resolveUserPath(relativePath: string): string {\n\tconst candidates = [\n\t\tjoin(process.cwd(), relativePath),\n\n\t\tjoin(process.cwd(), \"lib\", relativePath),\n\t\tjoin(process.cwd(), \"dist\", relativePath),\n\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, relativePath),\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, \"lib\", relativePath),\n\t\tjoin(FRAMEWORK_PACKAGE_ROOT, \"dist\", relativePath),\n\t];\n\n\tfor (const candidate of candidates) {\n\t\tconst full = resolve(candidate);\n\t\tif (existsSync(full)) return full;\n\t}\n\n\treturn join(process.cwd(), relativePath);\n}\n\n/**\n * Whether a directory or file exists.\n *\n * @export\n * @async\n * @param {string} path\n * @returns {unknown}\n */\nexport async function exists(path: string) {\n\ttry {\n\t\tawait fs.access(path);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Whether a user/member has permission.\n *\n * @export\n * @param {{\n * \tpermission: PermissionLevel;\n * \tuser?: User;\n * \tmember?: GuildMember;\n * }} options\n * @returns {boolean}\n */\nexport function hasPermission(\n\tclient: TriviousClient,\n\toptions: {\n\t\tpermission: PermissionLevel;\n\t\tuser?: User;\n\t\tmember?: GuildMember;\n\t}\n) {\n\tconst { permission, user, member } = options;\n\n\tif (user) {\n\t\tif (permission === PermissionLevel.BOT_OWNER) return user.id === \"424764032667484171\";\n\t\treturn true;\n\t}\n\n\tif (member) {\n\t\tconst memberPermission = getPermissionLevel(client, member);\n\t\treturn memberPermission >= permission;\n\t}\n\n\treturn false;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trivious",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"discord-bot",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
-
"main": "./dist/index.
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|