From b3f0d7a0fdc829e4f10bcc4b5b01125c5b2c09e0 Mon Sep 17 00:00:00 2001 From: duke Date: Sat, 26 Oct 2024 09:47:49 -0400 Subject: [PATCH] fix Signed-off-by: duke --- index.ts | 167 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 116 insertions(+), 51 deletions(-) diff --git a/index.ts b/index.ts index 1194eac..f3f37d2 100644 --- a/index.ts +++ b/index.ts @@ -11,59 +11,98 @@ import { sendMessage } from "@utils/discord"; import definePlugin from "@utils/types"; import { GuildMemberStore, UserStore } from "@webpack/common"; +import { PluginMeta } from "~plugins"; import SettingsPlugin from "../../plugins/_core/settings"; -const client = (() => { - if (IS_DISCORD_DESKTOP) return `Discord Desktop v${DiscordNative.app.getVersion()}`; - if (IS_VESKTOP) return `Vesktop v${VesktopNative.app.getVersion()}`; - if ("legcord" in window) return `Legcord v${window.legcord.version}`; +const clientVersion = (() => { + const version = IS_DISCORD_DESKTOP ? DiscordNative.app.getVersion() : IS_VESKTOP ? VesktopNative.app.getVersion() : null; + const name = IS_DISCORD_DESKTOP ? 'Desktop' : IS_VESKTOP ? "Vesktop" : typeof unsafeWindow !== "undefined" ? "UserScript" : "Web"; - // @ts-expect-error - const name = typeof unsafeWindow !== "undefined" ? "UserScript" : "Web"; - return `${name} (${navigator.userAgent})`; + return `${name}${version ? ` v${version}` : ''}`; })(); -let uptime = 0; +let uptime = Date.now(); -const line1 = "```ansi"; -// Placeholders: %username% -const line2 = "VV VV %username%"; -const line3 = " VV VV ---------------"; -// Placeholders: %ver% -const line4 = " VV VV Version: %ver%"; -// Placeholders: %client% -const line5 = " VV VV Client: %client%"; -// Placeholders: %platform% -const line6 = " VVV Platform: %platform%"; -// Placeholders: %pluginCount% -const line7 = " CCCCCCC Plugin Count: %pluginCount%"; -// Placeholders: %uptime% -const line8 = " CC Uptime: %uptime%"; -// Placeholders: %donorStatus% -const line9 = " CC Donor: %donorStatus%"; -const line10 = " CC"; -const line11 = " CCCCCCC ███████████████████████████"; -const line12 = "```"; +const lines = `\ +VV VV + VV VV + VV VV + VV VV + VVV + CCCCCCC + CC + CC + CC + CCCCCCC\ +`.split('\n'); +const sanitised = `\ +VV VV + VV VV + VV VV + VV VV + VVV + CCCCCCC + CC + CC + CC + CCCCCCC\ +`.split('\n'); + +// ```ansi +// VV VV thepotatofamine +// VV VV --------------- +// VV VV Version: v1.10.5 • 88e8fa7e (Dev) - 25 Oct 2024 +// VV VV Client: canary ~ Vesktop v1.5.3 +// VVV Platform: MacIntel +// CCCCCCC Plugin Count: 119 +// CC Uptime: 1997s +// CC Donor: yes +// CC +// CCCCCCC ███████████████████████████ +// ```; function getEnabledPlugins() { let counter = 0; + let userpluginsCount = 0; + Object.entries(Vencord.Plugins.plugins).forEach(([key, value]) => { - if (value.started) counter++; + if (value.started) if (PluginMeta[value.name].userPlugin) userpluginsCount++; else counter++; }); - return counter.toString(); + + return `${counter} (official)` + (userpluginsCount ? `, ${userpluginsCount} (userplugins)` : ''); } function getDonorStatus() { return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1042507929485586532"); } +function getContribStatus() { + return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1026534353167208489"); +} + +function humanFileSize(bytes, si = false, dp = 1) { + const thresh = si ? 1000 : 1024; + + if (Math.abs(bytes) < thresh) { + return bytes + ' B'; + } + + const units = si + ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] + : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; + let u = -1; + const r = 10 ** dp; + + do { + bytes /= thresh; + ++u; + } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1); + + + return bytes.toFixed(dp) + ' ' + units[u]; +} export default definePlugin({ name: "venfetch", description: "neofetch for vencord", authors: [Devs.nin0dev], - start() { - setInterval(() => { - uptime++; - }, 1000); - }, commands: [ { name: "venfetch", @@ -71,28 +110,54 @@ export default definePlugin({ inputType: ApplicationCommandInputType.BUILT_IN, execute: (args: Argument[], ctx: CommandContext) => { const { username } = UserStore.getCurrentUser(); - const info = { - Vencord: - `v${VERSION} • ${gitHash}` + - `${SettingsPlugin.additionalInfo} - ${Intl.DateTimeFormat("en-GB", { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}`, - Client: `${window.GLOBAL_ENV.RELEASE_CHANNEL} ~ ${client}`, - Platform: window.navigator.platform + const info: Record = { + version: `${VERSION} ~ ${gitHash}${SettingsPlugin.additionalInfo} - ${Intl.DateTimeFormat(navigator.language, { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}`, + client: `${t(window.GLOBAL_ENV.RELEASE_CHANNEL)} ~ ${clientVersion}`, + // @ts-ignore + platform: navigator.userAgentData?.platform ?? navigator.platform, + plugins: getEnabledPlugins(), + uptime: `${~~((Date.now() - uptime) / 1000)}s`, + // TODO: pr to vencord real and add to vencordnative + // memory: `${humanFileSize(VencordNative.memoryUsage().heapUsed)} / ${humanFileSize(VencordNative.memoryUsage().heapTotal)}`, + _: null, + + donor: getDonorStatus() ? 'yes' : 'no', + contributor: getContribStatus() ? 'yes' : null, + + __: null, + + __COLOR_TEST__: '███████████████████████████' + + // electron web context, want to get total memory usage }; + + const computed: [string, string | null][] = Object.entries(info).map(([key, value]) => [key, value]); + + let str = ''; + + str += `${lines[0]}${' '.repeat(25 - lines[0].length)}${username}\n`; + + for (let i = 1; i < computed.length + 1; i++) { + const line = computed[i - 1]; + + if (lines[i]) { + str += `${lines[i]}`; + + if (line && line[1] !== null && line[0] !== '__COLOR_TEST__') str += `${' '.repeat(25 - sanitised[i].length)}${t(line[0])}: ${line[1]}\n`; + else if (line[0] === '__COLOR_TEST__') str += line[0] + '\n'; else str += '\n'; + } else { + if (line && line[1] !== null && line[0] !== '__COLOR_TEST__') str += `${' '.repeat(25)}${t(line[0])}: ${line[1]}\n`; + else if (line[0] === '__COLOR_TEST__') str += `${' '.repeat(25)}${line[1]}\n`; else str += '\n'; + } + } + sendMessage(ctx.channel.id, { - content: `${line1} -${line2.replace("%username%", username)} -${line3}\n${line4.replace("%ver%", info.Vencord)} -${line5.replace("%client%", info.Client)} -${line6.replace("%platform%", info.Platform)} -${line7.replace("%pluginCount%", getEnabledPlugins())} -${line8.replace("%uptime%", `${uptime}s`)} -${line9.replace("%donorStatus%", getDonorStatus() ? "yes" : "no")} -${line10} -${line11} -${line12}` + content: `\`\`\`ansi\n${str}\n\`\`\`` }); return; } } ] }); + +const t = (e: string) => e[0].toUpperCase() + e.slice(1);