From c4d7b98e72ce70ea7ad0c930096b9a4a60a94fe0 Mon Sep 17 00:00:00 2001 From: splatter Date: Sun, 2 Feb 2025 02:04:33 +0000 Subject: [PATCH] refactor rendering code Signed-off-by: splatter --- index.ts | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/index.ts b/index.ts index d58f73b..1b375a8 100644 --- a/index.ts +++ b/index.ts @@ -28,7 +28,10 @@ const clientVersion = () => { return `${name}${version ? ` v${version}` : ''}`; }; -const lines = `\ +const COLOR_TEST = '███████████████████████████'; + + +const LOGO_WITH_ANSI = `\ \n\ \tVV VV \t VV VV @@ -41,7 +44,7 @@ const lines = `\ \t CC \t CCCCCCC\ `.split("\n"); -const sanitised = `\ +const LOGO_NO_ANSI = `\ \n\ \tVV VV \t VV VV @@ -122,7 +125,6 @@ export default definePlugin({ "NoRPC": Vencord.Plugins.isPluginEnabled("NoRPC"), "disabled activities": tryOrElse(() => !ShowCurrentGame.getSetting(), false), "outdated": BUILD_TIMESTAMP < Date.now() - 12096e5, - "likes java": ['287555395151593473', '886685857560539176', "728342296696979526"].includes(UserStore.getCurrentUser().id), }; const memory = await Native?.getMemory(); @@ -150,31 +152,38 @@ export default definePlugin({ ___: null, - __COLOR_TEST__: "███████████████████████████" - // electron web context, want to get total memory usage }; const computed: [string, string | null][] = Object.entries(info).filter(([key, value]) => value === null || value!.length).map(([key, value]) => [key, value]); let str = ""; + const MAGIC_NUMBER = 25; - str += `${lines[0]}${" ".repeat(25 - lines[0].length)}${username}\n`; + str += `${LOGO_WITH_ANSI[0]}${" ".repeat(MAGIC_NUMBER - LOGO_NO_ANSI[0].length)}${username}\n`; for (let i = 1; i < computed.length + 1; i++) { + const logoLine = LOGO_WITH_ANSI[i]; const line = computed[i - 1]; - if (lines[i]) { - str += `${lines[i]}`; - - if (line && line[1] !== null && line[0] !== "__COLOR_TEST__") str += `${" ".repeat(22 - sanitised[i].length)}${t(line[0])}: ${line[1]}\n`; - else if (line[0] === "__COLOR_TEST__") str += line[0] + "\n"; else str += "\n"; + if (logoLine) { + str += logoLine; + str += " ".repeat(MAGIC_NUMBER - 3 - LOGO_NO_ANSI[i].length); } else { - if (line && line[1] !== null && line[0] !== "__COLOR_TEST__") str += `\t${" ".repeat(22)}${t(line[0])}: ${line[1]}\n`; - else if (line[0] === "__COLOR_TEST__") str += `${" ".repeat(22)}${line[1]}\n`; else str += "\n"; + str += " ".repeat(MAGIC_NUMBER); } + + const [key, value] = line; + + if (!key.startsWith("_") && value) { + str += `${key[0].toUpperCase()}${key.slice(1)}: ${value}`; + } + + str += '\n'; } + str += `${" ".repeat(MAGIC_NUMBER)}${COLOR_TEST}\n`; + sendMessage(ctx.channel.id, { content: `\`\`\`ansi\n${str}\n\`\`\`` });