venfetch-fork/index.ts

166 lines
6.5 KiB
TypeScript
Raw Normal View History

2024-10-25 17:46:10 -04:00
/*
* 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 from "@utils/types";
import { GuildMemberStore, UserStore } from "@webpack/common";
import { PluginMeta } from "~plugins";
2024-10-26 08:39:06 -04:00
2024-10-25 17:46:10 -04:00
import SettingsPlugin from "../../plugins/_core/settings";
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";
2024-10-25 17:46:10 -04:00
return `${name}${version ? ` v${version}` : ''}`;
};
const uptime = Date.now();
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 ███████████████████████████
// ```;
2024-10-25 17:46:10 -04:00
function getEnabledPlugins() {
let counter = 0;
let userpluginsCount = 0;
2024-10-25 17:46:10 -04:00
Object.entries(Vencord.Plugins.plugins).forEach(([key, value]) => {
if (value.started) if (PluginMeta[value.name].userPlugin) userpluginsCount++; else counter++;
2024-10-25 17:46:10 -04:00
});
return `${counter} (official)` + (userpluginsCount ? `, ${userpluginsCount} (userplugins)` : "");
2024-10-25 17:46:10 -04:00
}
function getDonorStatus() {
return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1042507929485586532");
}
function getContribStatus() {
return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1026534353167208489");
}
2024-10-26 08:39:06 -04:00
function humanFileSize(bytes, si = false, dp = 1) {
const thresh = si ? 1000 : 1024;
2024-10-26 08:39:06 -04:00
if (Math.abs(bytes) < thresh) {
return bytes + " B";
}
2024-10-26 08:39:06 -04:00
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];
2024-10-26 08:39:06 -04:00
}
2024-10-25 17:46:10 -04:00
export default definePlugin({
name: "venfetch",
description: "neofetch for vencord",
authors: [Devs.nin0dev],
commands: [
{
name: "venfetch",
description: "neofetch for vencord",
inputType: ApplicationCommandInputType.BUILT_IN,
execute: (args: Argument[], ctx: CommandContext) => {
const { username } = UserStore.getCurrentUser();
const info: Record<string, string | null> = {
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
2024-10-25 17:46:10 -04:00
};
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";
}
}
2024-10-25 17:46:10 -04:00
sendMessage(ctx.channel.id, {
content: `\`\`\`ansi\n${str}\n\`\`\``
2024-10-25 17:46:10 -04:00
});
return;
}
}
]
});
const t = (e: string) => e[0].toUpperCase() + e.slice(1);