trivious 2.3.4 → 2.3.5
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.
|
@@ -19,6 +19,10 @@ async function commandDeploy(client) {
|
|
|
19
19
|
const newHash = createHash("sha256").update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString()).digest("hex");
|
|
20
20
|
let oldHash = "";
|
|
21
21
|
if (existsSync(hashFile)) oldHash = readFileSync(hashFile, "utf-8");
|
|
22
|
+
if (body.length === 0 && !oldHash) {
|
|
23
|
+
console.debug(`[Trivious] No commands found, skipping deployment.`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
22
26
|
if (newHash === oldHash) {
|
|
23
27
|
console.debug(`[Trivious] No changes in commands found, skipping deployment.`);
|
|
24
28
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/client/deploy.client.ts"],"sourcesContent":["import { TriviousError } from \"@utility/errors.js\";\nimport { createHash } from \"crypto\";\nimport { REST, Routes } from \"discord.js\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport TriviousClient from \"./trivious.client.js\";\n\nexport default async function commandDeploy(client: TriviousClient) {\n\tconst { commandHashConfig } = client.trivious;\n\n\tconst clientId = process.env[client.trivious.credentials.clientIdReference];\n\tconst token = process.env[client.trivious.credentials.tokenReference];\n\tif (!clientId || !token)\n\t\tthrow new TriviousError(\"Invalid clientId or token environment variable\");\n\n\tconst commands = client.stores.commands;\n\tconst body = [\n\t\t...commands.chatInput.map((command) => command.data.toJSON()),\n\t\t...commands.context.map((command) => command.data.toJSON()),\n\t];\n\n\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\tconst hashFile = join(commandHashConfig.persistentDataPath || \"data\", \"commands.hash\");\n\t\tconst newHash = createHash(\"sha256\")\n\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t.digest(\"hex\");\n\n\t\tlet oldHash = \"\";\n\t\tif (existsSync(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\n\t\tif (newHash === oldHash) {\n\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment.`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst hashDirectory = dirname(hashFile);\n\t\tif (!existsSync(hashDirectory)) {\n\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t}\n\n\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t}\n\n\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\tconsole.debug(`[Trivious] Deployed ${body.length} commands`);\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,MAAM,cAAc;AAC7B,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,SAAS,YAAY;AAG9B,eAAO,cAAqC,QAAwB;AACnE,QAAM,EAAE,kBAAkB,IAAI,OAAO;AAErC,QAAM,WAAW,QAAQ,IAAI,OAAO,SAAS,YAAY,iBAAiB;AAC1E,QAAM,QAAQ,QAAQ,IAAI,OAAO,SAAS,YAAY,cAAc;AACpE,MAAI,CAAC,YAAY,CAAC;AACjB,UAAM,IAAI,cAAc,gDAAgD;AAEzE,QAAM,WAAW,OAAO,OAAO;AAC/B,QAAM,OAAO;AAAA,IACZ,GAAG,SAAS,UAAU,IAAI,CAAC,YAAY,QAAQ,KAAK,OAAO,CAAC;AAAA,IAC5D,GAAG,SAAS,QAAQ,IAAI,CAAC,YAAY,QAAQ,KAAK,OAAO,CAAC;AAAA,EAC3D;AAEA,MAAI,qBAAqB,kBAAkB,SAAS;AACnD,UAAM,WAAW,KAAK,kBAAkB,sBAAsB,QAAQ,eAAe;AACrF,UAAM,UAAU,WAAW,QAAQ,EACjC,OAAO,KAAK,UAAU,KAAK,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,EACnF,OAAO,KAAK;AAEd,QAAI,UAAU;AACd,QAAI,WAAW,QAAQ,EAAG,WAAU,aAAa,UAAU,OAAO;AAElE,QAAI,YAAY,SAAS;AACxB,cAAQ,MAAM,+DAA+D;AAC7E;AAAA,IACD;AAEA,UAAM,gBAAgB,QAAQ,QAAQ;AACtC,QAAI,CAAC,WAAW,aAAa,GAAG;AAC/B,gBAAU,eAAe,EAAE,WAAW,KAAK,CAAC;AAAA,IAC7C;AAEA,kBAAc,UAAU,SAAS,EAAE,UAAU,QAAQ,CAAC;AACtD,YAAQ,MAAM,wCAAwC,QAAQ,EAAE;AAAA,EACjE;AAEA,QAAM,OAAO,IAAI,KAAK,EAAE,SAAS,KAAK,CAAC,EAAE,SAAS,KAAK;AACvD,QAAM,KAAK,IAAI,OAAO,oBAAoB,QAAQ,GAAG,EAAE,KAAK,CAAC;AAC7D,UAAQ,MAAM,uBAAuB,KAAK,MAAM,WAAW;AAC5D;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/features/client/deploy.client.ts"],"sourcesContent":["import { TriviousError } from \"@utility/errors.js\";\nimport { createHash } from \"crypto\";\nimport { REST, Routes } from \"discord.js\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport TriviousClient from \"./trivious.client.js\";\n\nexport default async function commandDeploy(client: TriviousClient) {\n\tconst { commandHashConfig } = client.trivious;\n\n\tconst clientId = process.env[client.trivious.credentials.clientIdReference];\n\tconst token = process.env[client.trivious.credentials.tokenReference];\n\tif (!clientId || !token)\n\t\tthrow new TriviousError(\"Invalid clientId or token environment variable\");\n\n\tconst commands = client.stores.commands;\n\tconst body = [\n\t\t...commands.chatInput.map((command) => command.data.toJSON()),\n\t\t...commands.context.map((command) => command.data.toJSON()),\n\t];\n\n\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\tconst hashFile = join(commandHashConfig.persistentDataPath || \"data\", \"commands.hash\");\n\t\tconst newHash = createHash(\"sha256\")\n\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t.digest(\"hex\");\n\n\t\tlet oldHash = \"\";\n\t\tif (existsSync(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\n\t\tif (body.length === 0 && !oldHash) {\n\t\t\tconsole.debug(`[Trivious] No commands found, skipping deployment.`);\n\t\t\treturn;\n\t\t}\n\n\t\tif (newHash === oldHash) {\n\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment.`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst hashDirectory = dirname(hashFile);\n\t\tif (!existsSync(hashDirectory)) {\n\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t}\n\n\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t}\n\n\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\tconsole.debug(`[Trivious] Deployed ${body.length} commands`);\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,MAAM,cAAc;AAC7B,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,SAAS,SAAS,YAAY;AAG9B,eAAO,cAAqC,QAAwB;AACnE,QAAM,EAAE,kBAAkB,IAAI,OAAO;AAErC,QAAM,WAAW,QAAQ,IAAI,OAAO,SAAS,YAAY,iBAAiB;AAC1E,QAAM,QAAQ,QAAQ,IAAI,OAAO,SAAS,YAAY,cAAc;AACpE,MAAI,CAAC,YAAY,CAAC;AACjB,UAAM,IAAI,cAAc,gDAAgD;AAEzE,QAAM,WAAW,OAAO,OAAO;AAC/B,QAAM,OAAO;AAAA,IACZ,GAAG,SAAS,UAAU,IAAI,CAAC,YAAY,QAAQ,KAAK,OAAO,CAAC;AAAA,IAC5D,GAAG,SAAS,QAAQ,IAAI,CAAC,YAAY,QAAQ,KAAK,OAAO,CAAC;AAAA,EAC3D;AAEA,MAAI,qBAAqB,kBAAkB,SAAS;AACnD,UAAM,WAAW,KAAK,kBAAkB,sBAAsB,QAAQ,eAAe;AACrF,UAAM,UAAU,WAAW,QAAQ,EACjC,OAAO,KAAK,UAAU,KAAK,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,EACnF,OAAO,KAAK;AAEd,QAAI,UAAU;AACd,QAAI,WAAW,QAAQ,EAAG,WAAU,aAAa,UAAU,OAAO;AAElE,QAAI,KAAK,WAAW,KAAK,CAAC,SAAS;AAClC,cAAQ,MAAM,oDAAoD;AAClE;AAAA,IACD;AAEA,QAAI,YAAY,SAAS;AACxB,cAAQ,MAAM,+DAA+D;AAC7E;AAAA,IACD;AAEA,UAAM,gBAAgB,QAAQ,QAAQ;AACtC,QAAI,CAAC,WAAW,aAAa,GAAG;AAC/B,gBAAU,eAAe,EAAE,WAAW,KAAK,CAAC;AAAA,IAC7C;AAEA,kBAAc,UAAU,SAAS,EAAE,UAAU,QAAQ,CAAC;AACtD,YAAQ,MAAM,wCAAwC,QAAQ,EAAE;AAAA,EACjE;AAEA,QAAM,OAAO,IAAI,KAAK,EAAE,SAAS,KAAK,CAAC,EAAE,SAAS,KAAK;AACvD,QAAM,KAAK,IAAI,OAAO,oBAAoB,QAAQ,GAAG,EAAE,KAAK,CAAC;AAC7D,UAAQ,MAAM,uBAAuB,KAAK,MAAM,WAAW;AAC5D;","names":[]}
|
|
@@ -3,6 +3,7 @@ import path from "path";
|
|
|
3
3
|
import { pathToFileURL } from "url";
|
|
4
4
|
const fileCache = /* @__PURE__ */ new Map();
|
|
5
5
|
function importFile(filePath) {
|
|
6
|
+
if (filePath.endsWith(".d.ts") || filePath.endsWith(".js.map")) return null;
|
|
6
7
|
const absolutePath = path.resolve(filePath);
|
|
7
8
|
if (fileCache.has(absolutePath)) return fileCache.get(absolutePath);
|
|
8
9
|
const processPromise = (async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utility/functions.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\n\nconst fileCache = new Map<string, Promise<any | null>>();\nexport function importFile<T>(filePath: string)
|
|
1
|
+
{"version":3,"sources":["../../src/utility/functions.ts"],"sourcesContent":["import { promises as fs } from \"fs\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\n\nconst fileCache = new Map<string, Promise<any | null>>();\nexport function importFile<T>(filePath: string) {\n\tif (filePath.endsWith(\".d.ts\") || filePath.endsWith(\".js.map\")) return null;\n\tconst absolutePath = path.resolve(filePath);\n\tif (fileCache.has(absolutePath)) return fileCache.get(absolutePath)!;\n\n\tconst processPromise = (async () => {\n\t\ttry {\n\t\t\tconst { default: file } = await import(pathToFileURL(absolutePath).href);\n\t\t\tif (!file) return null;\n\n\t\t\tconst imports = file.default || file;\n\t\t\tif (typeof imports === \"function\" && imports.prototype) return new imports() as T;\n\t\t\tif (typeof imports === \"object\" && imports !== null) {\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\treturn null;\n\t\t} catch (err: any) {\n\t\t\tconsole.warn(`[Trivious] Error while import file ${filePath}`, err);\n\t\t\treturn null;\n\t\t}\n\t})();\n\n\tfileCache.set(absolutePath, processPromise);\n\tprocessPromise.then((result) => {\n\t\tif (result === null) fileCache.delete(absolutePath);\n\t});\n\treturn processPromise;\n}\n\nexport function clearFileImportsCache() {\n\tfileCache.clear();\n}\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"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAC/B,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,MAAM,YAAY,oBAAI,IAAiC;AAChD,SAAS,WAAc,UAAkB;AAC/C,MAAI,SAAS,SAAS,OAAO,KAAK,SAAS,SAAS,SAAS,EAAG,QAAO;AACvE,QAAM,eAAe,KAAK,QAAQ,QAAQ;AAC1C,MAAI,UAAU,IAAI,YAAY,EAAG,QAAO,UAAU,IAAI,YAAY;AAElE,QAAM,kBAAkB,YAAY;AACnC,QAAI;AACH,YAAM,EAAE,SAAS,KAAK,IAAI,MAAM,OAAO,cAAc,YAAY,EAAE;AACnE,UAAI,CAAC,KAAM,QAAO;AAElB,YAAM,UAAU,KAAK,WAAW;AAChC,UAAI,OAAO,YAAY,cAAc,QAAQ,UAAW,QAAO,IAAI,QAAQ;AAC3E,UAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AACpD,YAAI,OAAO,KAAK,OAAO,EAAE,WAAW,EAAG,QAAO;AAC9C,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,IACR,SAAS,KAAU;AAClB,cAAQ,KAAK,sCAAsC,QAAQ,IAAI,GAAG;AAClE,aAAO;AAAA,IACR;AAAA,EACD,GAAG;AAEH,YAAU,IAAI,cAAc,cAAc;AAC1C,iBAAe,KAAK,CAAC,WAAW;AAC/B,QAAI,WAAW,KAAM,WAAU,OAAO,YAAY;AAAA,EACnD,CAAC;AACD,SAAO;AACR;AAEO,SAAS,wBAAwB;AACvC,YAAU,MAAM;AACjB;AAEA,eAAsB,OAAOA,OAAc;AAC1C,MAAI;AACH,UAAM,GAAG,OAAOA,KAAI;AACpB,WAAO;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;","names":["path"]}
|