venfetch/index.ts
splatter 788c01e81a
add memory
Signed-off-by: splatter <splatterxl@outlook.ie>
2025-02-01 15:04:42 +00:00

208 lines
8.4 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { ApplicationCommandInputType, Argument, CommandContext } from "@api/Commands";
import { gitHash } from "@shared/vencordUserAgent";
import { Devs } from "@utils/constants";
import { sendMessage } from "@utils/discord";
import definePlugin, { Plugin, PluginNative } from "@utils/types";
import { GuildMemberStore, UserStore } from "@webpack/common";
import { PluginMeta } from "~plugins";
import { isPluginDev, tryOrElse } from "@utils/misc";
import { findByCodeLazy } from "@webpack";
import { getUserSettingLazy } from "../../api/UserSettings.js";
import SettingsPlugin from "../../plugins/_core/settings";
const Native = VencordNative.pluginHelpers.venfetch as PluginNative<typeof import("./native")>;
const clientVersion = () => {
const version = IS_DISCORD_DESKTOP ? DiscordNative.app.getVersion() : IS_VESKTOP ? VesktopNative.app.getVersion() : null;
// @ts-ignore
const name = IS_DISCORD_DESKTOP ? "Desktop" : IS_VESKTOP ? "Vesktop" : typeof unsafeWindow !== "undefined" ? "UserScript" : "Web";
return `${name}${version ? ` v${version}` : ''}`;
};
const lines = `\
\n\
\tVV VV
\t VV VV
\t VV VV
\t VV VV
\t VVV
\t CCCCCCC
\t CC
\t CC
\t CC
\t CCCCCCC\
`.split("\n");
const sanitised = `\
\n\
\tVV VV
\t VV VV
\t VV VV
\t VV VV
\t VVV
\t CCCCCCC
\t CC
\t CC
\t CC
\t 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 ███████████████████████████
// ```;
const isApiPlugin = (plugin: Plugin) => plugin.name.endsWith("API") || plugin.required;
function getEnabledPlugins() {
const counters = {
official: {
enabled: 0,
total: 0
},
user: {
enabled: 0,
total: 0
}
};
Object.values(Vencord.Plugins.plugins).filter((plugin) => !isApiPlugin(plugin)).forEach((plugin) => {
if (PluginMeta[plugin.name]?.userPlugin) {
if (plugin.started) counters.user.enabled++;
counters.user.total++;
} else {
if (plugin.started) counters.official.enabled++;
counters.official.total++;
}
});
return `${counters.official.enabled} / ${counters.official.total} (official)` + (counters.user.total ? `, ${counters.user.enabled} / ${counters.user.total} (userplugins)` : "");
}
function getDonorStatus() {
return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1042507929485586532");
}
function getContribStatus() {
const userId = UserStore.getCurrentUser().id;
return isPluginDev(userId) || GuildMemberStore.getMember("1015060230222131221", userId).roles.includes("1026534353167208489");
}
const getVersions = findByCodeLazy("logsUploaded:new Date().toISOString(),");
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame")!;
export default definePlugin({
name: "venfetch",
description: "neofetch for vencord",
authors: [Devs.nin0dev],
commands: [
{
name: "venfetch",
description: "neofetch for vencord",
inputType: ApplicationCommandInputType.BUILT_IN,
execute: async (args: Argument[], ctx: CommandContext) => {
const commonIssues = {
"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();
const { username } = UserStore.getCurrentUser();
const versions = getVersions();
const info: Record<string, string | null> = {
version: `${VERSION} ~ ${gitHash}${SettingsPlugin.additionalInfo} - ${Intl.DateTimeFormat(navigator.language, { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}${!IS_STANDALONE ? ` ~ dev` : ""}`,
client: `${t(window.GLOBAL_ENV.RELEASE_CHANNEL)} ~ ${clientVersion()}`,
'Build Number': `${versions.buildNumber} ~ Hash: ${versions.versionHash?.slice(0, 7) ?? 'unknown'}`,
issues: Object.entries(commonIssues).filter(([_, value]) => value).map(([key]) => key).join(", ") || '',
_: null,
// @ts-ignore
platform: navigator.userAgentData?.platform ? `${navigator.userAgentData?.platform} (${navigator.platform})` : navigator.platform,
plugins: getEnabledPlugins(),
uptime: `${~~((Date.now() - window.GLOBAL_ENV.HTML_TIMESTAMP) / 1000)}s`,
memory: memory ? `${humanFileSize(memory.heapUsed)} / ${humanFileSize(memory.heapTotal)}` : '',
__: null,
donor: getDonorStatus() ? "yes" : "no",
contributor: getContribStatus() ? "yes" : "no",
___: 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 = "";
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(22 - 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 += `\t${" ".repeat(22)}${t(line[0])}: ${line[1]}\n`;
else if (line[0] === "__COLOR_TEST__") str += `${" ".repeat(22)}${line[1]}\n`; else str += "\n";
}
}
sendMessage(ctx.channel.id, {
content: `\`\`\`ansi\n${str}\n\`\`\``
});
return;
}
}
]
});
const t = (e: string) => e.length > 0 ? e[0].toUpperCase() + e.slice(1) : "";
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];
}