refactor rendering code

Signed-off-by: splatter <splatterxl@outlook.ie>
This commit is contained in:
duke dennis 2025-02-02 02:04:33 +00:00
parent 788c01e81a
commit c4d7b98e72
Signed by: duke
GPG key ID: A069D884579D2915

View file

@ -28,7 +28,10 @@ const clientVersion = () => {
return `${name}${version ? ` v${version}` : ''}`; return `${name}${version ? ` v${version}` : ''}`;
}; };
const lines = `\ const COLOR_TEST = '███████████████████████████';
const LOGO_WITH_ANSI = `\
\n\ \n\
\tVV VV \tVV VV
\t VV VV \t VV VV
@ -41,7 +44,7 @@ const lines = `\
\t CC \t CC
\t CCCCCCC\ \t CCCCCCC\
`.split("\n"); `.split("\n");
const sanitised = `\ const LOGO_NO_ANSI = `\
\n\ \n\
\tVV VV \tVV VV
\t VV VV \t VV VV
@ -122,7 +125,6 @@ export default definePlugin({
"NoRPC": Vencord.Plugins.isPluginEnabled("NoRPC"), "NoRPC": Vencord.Plugins.isPluginEnabled("NoRPC"),
"disabled activities": tryOrElse(() => !ShowCurrentGame.getSetting(), false), "disabled activities": tryOrElse(() => !ShowCurrentGame.getSetting(), false),
"outdated": BUILD_TIMESTAMP < Date.now() - 12096e5, "outdated": BUILD_TIMESTAMP < Date.now() - 12096e5,
"likes java": ['287555395151593473', '886685857560539176', "728342296696979526"].includes(UserStore.getCurrentUser().id),
}; };
const memory = await Native?.getMemory(); const memory = await Native?.getMemory();
@ -150,31 +152,38 @@ export default definePlugin({
___: null, ___: null,
__COLOR_TEST__: "███████████████████████████"
// electron web context, want to get total memory usage // 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]); const computed: [string, string | null][] = Object.entries(info).filter(([key, value]) => value === null || value!.length).map(([key, value]) => [key, value]);
let str = ""; 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++) { for (let i = 1; i < computed.length + 1; i++) {
const logoLine = LOGO_WITH_ANSI[i];
const line = computed[i - 1]; const line = computed[i - 1];
if (lines[i]) { if (logoLine) {
str += `${lines[i]}`; str += logoLine;
str += " ".repeat(MAGIC_NUMBER - 3 - LOGO_NO_ANSI[i].length);
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";
} else { } else {
if (line && line[1] !== null && line[0] !== "__COLOR_TEST__") str += `\t${" ".repeat(22)}${t(line[0])}: ${line[1]}\n`; str += " ".repeat(MAGIC_NUMBER);
else if (line[0] === "__COLOR_TEST__") str += `${" ".repeat(22)}${line[1]}\n`; else str += "\n";
} }
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, { sendMessage(ctx.channel.id, {
content: `\`\`\`ansi\n${str}\n\`\`\`` content: `\`\`\`ansi\n${str}\n\`\`\``
}); });