From 13464586736fbdae17523a1b8f1c1152ba400f2a Mon Sep 17 00:00:00 2001 From: Dani Date: Tue, 28 May 2024 12:12:16 -0700 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=85=20Add=20cuts-runner=20base=20imp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/callsystems/tests/cuts.js | 97 +++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/callsystems/tests/cuts.js diff --git a/src/callsystems/tests/cuts.js b/src/callsystems/tests/cuts.js new file mode 100644 index 0000000..8caad2b --- /dev/null +++ b/src/callsystems/tests/cuts.js @@ -0,0 +1,97 @@ +import { Collection } from "discord.js"; +import { Callsystem } from "../../lib/callsystems/index.js"; +import { nanoid } from "nanoid"; +import lodash from "lodash"; + +// from https://github.com/prathercc/date-to-discord-snowflake/blob/main/index.js +const generateSnowflake = (date = new Date()) => + ((BigInt(date.valueOf()) - BigInt(1420070400000)) << BigInt(22)).toString(); + +const getResult = async ({ messageId, channel, reply, client, env }, tests) => + await Promise.all( + tests.map(async ({ id, test }) => { + const m = await channel.messages.fetch(messageId).catch(() => {}); + + if (!test?.packageId?.startsWith("cs.tests") && tests.length === 1) { + m.reply(`Test ${id} is not a CUTS unit test.`).catch(() => {}); + return { + embeds: [], + results: [], + }; + } + + m.content = m.content + "\ncuts.run"; + + const testClass = new test({ env, message: m, client }); + return await testClass.activate().catch((e) => { + console.error(e); + return []; + }); + }), + ); + +export default class HistoryConsoleUnitTest extends Callsystem { + constructor(opts) { + const { env, message, client, defaultModel, defaultProvider } = opts || {}; + super({ env, message, client, defaultModel, defaultProvider }); + } + + static get packageId() { + return "cs.spongedsc.cuts-runner"; + } + + static get name() { + return "CUTS Runner"; + } + + static get version() { + return "0.0.1"; + } + + static get releaseDate() { + return new Date("2024-05-28"); + } + + static get capabilities() { + return ["legacy"]; + } + + static get managerOptions() { + return {}; + } + + async activate() { + const { env, message, client } = this; + + if (!message?.mentions?.has(client?.user?.id)) return []; + if (message.content.split(" ")[1] !== "cuts.run") return []; + const args = message.content.split(" ").slice(2); + const testId = args[0]; + if (!testId) { + message.reply("Please provide a test ID.").catch(() => {}); + return []; + } + + const tests = + testId === "all" + ? Array.from(client.callsystemsMap.keys()) + .map((c) => ({ + id: c, + test: client.callsystemsMap.get(c), + })) + .filter((t) => t.id.startsWith("cs.tests") && !t.id.includes("non-cuts") && t.id.endsWith("-latest")) + : [ + { + id: testId, + test: client.callsystemsMap.get(testId + "-latest"), + }, + ]; + + const results = await getResult( + { messageId: message.id, channel: message.channel, reply: message.reply, client, env }, + tests.filter((t) => t !== null), + ); + + return results; + } +} From 0863b95b03d2afac10fb2a3340cd06e83d1e06b5 Mon Sep 17 00:00:00 2001 From: Dani Date: Tue, 28 May 2024 12:13:34 -0700 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20Remove=20unused=20deps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/callsystems/tests/cuts.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/callsystems/tests/cuts.js b/src/callsystems/tests/cuts.js index 8caad2b..71e45a9 100644 --- a/src/callsystems/tests/cuts.js +++ b/src/callsystems/tests/cuts.js @@ -1,8 +1,4 @@ -import { Collection } from "discord.js"; import { Callsystem } from "../../lib/callsystems/index.js"; -import { nanoid } from "nanoid"; -import lodash from "lodash"; - // from https://github.com/prathercc/date-to-discord-snowflake/blob/main/index.js const generateSnowflake = (date = new Date()) => ((BigInt(date.valueOf()) - BigInt(1420070400000)) << BigInt(22)).toString(); From c432d25ea901e65a9537578f4917553dbd0301b8 Mon Sep 17 00:00:00 2001 From: Dani Date: Fri, 31 May 2024 00:12:09 -0700 Subject: [PATCH 3/6] Update src/callsystems/tests/cuts.js Co-authored-by: Arti <59352535+artifishvr@users.noreply.github.com> --- src/callsystems/tests/cuts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/callsystems/tests/cuts.js b/src/callsystems/tests/cuts.js index 71e45a9..cc1eab1 100644 --- a/src/callsystems/tests/cuts.js +++ b/src/callsystems/tests/cuts.js @@ -1,5 +1,5 @@ import { Callsystem } from "../../lib/callsystems/index.js"; -// from https://github.com/prathercc/date-to-discord-snowflake/blob/main/index.js + const generateSnowflake = (date = new Date()) => ((BigInt(date.valueOf()) - BigInt(1420070400000)) << BigInt(22)).toString(); From 4a2d74f482c30d92aa47d6fd9b65b5583e84ecc3 Mon Sep 17 00:00:00 2001 From: Dani Date: Fri, 31 May 2024 00:12:14 -0700 Subject: [PATCH 4/6] Update src/callsystems/tests/cuts.js Co-authored-by: Arti <59352535+artifishvr@users.noreply.github.com> --- src/callsystems/tests/cuts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/callsystems/tests/cuts.js b/src/callsystems/tests/cuts.js index cc1eab1..c377f16 100644 --- a/src/callsystems/tests/cuts.js +++ b/src/callsystems/tests/cuts.js @@ -1,7 +1,7 @@ import { Callsystem } from "../../lib/callsystems/index.js"; const generateSnowflake = (date = new Date()) => - ((BigInt(date.valueOf()) - BigInt(1420070400000)) << BigInt(22)).toString(); + const getResult = async ({ messageId, channel, reply, client, env }, tests) => await Promise.all( From d0940430794adb7e5fe104616b0863093afcc59d Mon Sep 17 00:00:00 2001 From: Dani Date: Fri, 31 May 2024 00:12:19 -0700 Subject: [PATCH 5/6] Update src/callsystems/tests/cuts.js Co-authored-by: Arti <59352535+artifishvr@users.noreply.github.com> --- src/callsystems/tests/cuts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/callsystems/tests/cuts.js b/src/callsystems/tests/cuts.js index c377f16..b518914 100644 --- a/src/callsystems/tests/cuts.js +++ b/src/callsystems/tests/cuts.js @@ -1,6 +1,6 @@ import { Callsystem } from "../../lib/callsystems/index.js"; -const generateSnowflake = (date = new Date()) => + const getResult = async ({ messageId, channel, reply, client, env }, tests) => From 5d3c7c3685fa932fe2ee1543e1e670e77f3a61c3 Mon Sep 17 00:00:00 2001 From: Dani Date: Fri, 31 May 2024 00:13:13 -0700 Subject: [PATCH 6/6] move cuts runner to spongedsc folder --- src/callsystems/{tests => spongedsc}/cuts.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/callsystems/{tests => spongedsc}/cuts.js (100%) diff --git a/src/callsystems/tests/cuts.js b/src/callsystems/spongedsc/cuts.js similarity index 100% rename from src/callsystems/tests/cuts.js rename to src/callsystems/spongedsc/cuts.js