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";
|
2024-10-27 11:56:54 -04:00
|
|
|
|
import definePlugin, { Plugin } from "@utils/types";
|
2024-10-25 17:46:10 -04:00
|
|
|
|
import { GuildMemberStore, UserStore } from "@webpack/common";
|
|
|
|
|
|
2024-10-27 11:56:54 -04:00
|
|
|
|
import plugins, { PluginMeta } from "~plugins";
|
2024-10-26 08:39:06 -04:00
|
|
|
|
|
2024-10-27 11:56:54 -04:00
|
|
|
|
import { isPluginDev } from "@utils/misc";
|
2024-10-27 11:57:50 -04:00
|
|
|
|
import SettingsPlugin from "../../plugins/_core/settings";
|
2024-10-25 17:46:10 -04:00
|
|
|
|
|
2024-10-27 10:58:43 -04:00
|
|
|
|
const clientVersion = () => {
|
2024-10-26 09:47:49 -04:00
|
|
|
|
const version = IS_DISCORD_DESKTOP ? DiscordNative.app.getVersion() : IS_VESKTOP ? VesktopNative.app.getVersion() : null;
|
2024-10-27 10:58:43 -04:00
|
|
|
|
// @ts-ignore
|
2024-10-26 12:06:32 -04:00
|
|
|
|
const name = IS_DISCORD_DESKTOP ? "Desktop" : IS_VESKTOP ? "Vesktop" : typeof unsafeWindow !== "undefined" ? "UserScript" : "Web";
|
2024-10-25 17:46:10 -04:00
|
|
|
|
|
2024-10-26 09:47:49 -04:00
|
|
|
|
return `${name}${version ? ` v${version}` : ''}`;
|
2024-10-27 10:58:43 -04:00
|
|
|
|
};
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
|
|
|
|
const lines = `\
|
|
|
|
|
VV VV
|
|
|
|
|
VV VV
|
|
|
|
|
VV VV
|
|
|
|
|
VV VV
|
|
|
|
|
VVV
|
|
|
|
|
[2;35mCCCCCCC
|
|
|
|
|
[2;35mCC
|
|
|
|
|
[2;35mCC
|
|
|
|
|
[2;35mCC
|
|
|
|
|
[2;35mCCCCCCC[0m\
|
2024-10-26 12:06:32 -04:00
|
|
|
|
`.split("\n");
|
2024-10-26 09:47:49 -04:00
|
|
|
|
const sanitised = `\
|
|
|
|
|
VV VV
|
|
|
|
|
VV VV
|
|
|
|
|
VV VV
|
|
|
|
|
VV VV
|
|
|
|
|
VVV
|
|
|
|
|
CCCCCCC
|
|
|
|
|
CC
|
|
|
|
|
CC
|
|
|
|
|
CC
|
|
|
|
|
CCCCCCC\
|
2024-10-26 12:06:32 -04:00
|
|
|
|
`.split("\n");
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
|
|
|
|
// ```ansi
|
|
|
|
|
// VV VV thepotatofamine
|
|
|
|
|
// VV VV ---------------
|
|
|
|
|
// VV VV Version: v1.10.5 • 88e8fa7e (Dev) - 25 Oct 2024
|
|
|
|
|
// VV VV [2;35m[0m[2;35mClient: [0m[0mcanary ~ Vesktop v1.5.3[0m[2;35m[0m
|
|
|
|
|
// VVV [2;35m[0m[2;35mPlatform: [0m[0mMacIntel[0m[2;35m[0m
|
|
|
|
|
// [2;35mCCCCCCC [2;35m[0m[2;35mPlugin Count: [0m[0m119[0m[2;35m[0m
|
|
|
|
|
// [2;35mCC [2;35m[0m[2;35mUptime: [0m[0m1997s[0m[2;35m[0m
|
|
|
|
|
// [2;35mCC [2;35m[0m[2;35mDonor: [0m[0myes[0m[2;35m[0m
|
|
|
|
|
// [2;35mCC
|
|
|
|
|
// [2;35mCCCCCCC[0m [2;40m[2;30m███[0m[2;40m[0m[2;31m[0m[2;30m███[0m[2;31m███[0m[2;32m███[0m[2;33m███[0m[2;34m███[0m[2;35m███[0m[2;36m███[0m[2;37m███[0m
|
|
|
|
|
// ```;
|
2024-10-25 17:46:10 -04:00
|
|
|
|
|
2024-10-27 11:56:54 -04:00
|
|
|
|
const isApiPlugin = (plugin: Plugin) => plugin.name.endsWith("API") || plugin.required;
|
|
|
|
|
|
2024-10-25 17:46:10 -04:00
|
|
|
|
function getEnabledPlugins() {
|
|
|
|
|
let counter = 0;
|
2024-10-27 11:56:54 -04:00
|
|
|
|
let total = 0;
|
2024-10-26 09:47:49 -04:00
|
|
|
|
let userpluginsCount = 0;
|
2024-10-27 11:56:54 -04:00
|
|
|
|
let totalUserplugins = 0;
|
|
|
|
|
|
|
|
|
|
Object.values(plugins).filter((plugin) => !isApiPlugin(plugin)).forEach((plugin) => {
|
|
|
|
|
if (PluginMeta[plugin.name].userPlugin) {
|
|
|
|
|
if (plugin.started) userpluginsCount++;
|
|
|
|
|
totalUserplugins++;
|
|
|
|
|
} else {
|
|
|
|
|
if (plugin.started) counter++;
|
|
|
|
|
total++;
|
|
|
|
|
};
|
2024-10-25 17:46:10 -04:00
|
|
|
|
});
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
2024-10-27 11:59:15 -04:00
|
|
|
|
return `${counter} / ${total} (official)` + (totalUserplugins ? `, ${userpluginsCount} / ${totalUserplugins} (userplugins)` : "");
|
2024-10-25 17:46:10 -04:00
|
|
|
|
}
|
|
|
|
|
function getDonorStatus() {
|
|
|
|
|
return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1042507929485586532");
|
|
|
|
|
}
|
2024-10-26 09:47:49 -04:00
|
|
|
|
function getContribStatus() {
|
2024-10-27 11:56:54 -04:00
|
|
|
|
const userId = UserStore.getCurrentUser().id;
|
|
|
|
|
return isPluginDev(userId) || GuildMemberStore.getMember("1015060230222131221", userId).roles.includes("1026534353167208489");
|
2024-10-26 09:47:49 -04:00
|
|
|
|
}
|
2024-10-26 08:39:06 -04:00
|
|
|
|
|
2024-10-26 09:47:49 -04:00
|
|
|
|
function humanFileSize(bytes, si = false, dp = 1) {
|
|
|
|
|
const thresh = si ? 1000 : 1024;
|
2024-10-26 08:39:06 -04:00
|
|
|
|
|
2024-10-26 09:47:49 -04:00
|
|
|
|
if (Math.abs(bytes) < thresh) {
|
2024-10-26 12:06:32 -04:00
|
|
|
|
return bytes + " B";
|
2024-10-26 09:47:49 -04:00
|
|
|
|
}
|
2024-10-26 08:39:06 -04:00
|
|
|
|
|
2024-10-26 09:47:49 -04:00
|
|
|
|
const units = si
|
2024-10-26 12:06:32 -04:00
|
|
|
|
? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
|
|
|
|
: ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
2024-10-26 09:47:49 -04:00
|
|
|
|
let u = -1;
|
|
|
|
|
const r = 10 ** dp;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
bytes /= thresh;
|
|
|
|
|
++u;
|
|
|
|
|
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
|
|
|
|
|
|
|
|
|
|
|
2024-10-26 12:06:32 -04:00
|
|
|
|
return bytes.toFixed(dp) + " " + units[u];
|
2024-10-26 08:39:06 -04:00
|
|
|
|
}
|
2024-10-25 17:46:10 -04:00
|
|
|
|
|
2024-10-27 11:57:50 -04:00
|
|
|
|
let BUILD_NUMBER;
|
|
|
|
|
let VERSION_HASH;
|
|
|
|
|
|
2024-10-25 17:46:10 -04:00
|
|
|
|
export default definePlugin({
|
|
|
|
|
name: "venfetch",
|
|
|
|
|
description: "neofetch for vencord",
|
|
|
|
|
authors: [Devs.nin0dev],
|
2024-10-27 11:57:50 -04:00
|
|
|
|
patches: [
|
|
|
|
|
{
|
|
|
|
|
find: /.log\("[BUILD INFO]/,
|
|
|
|
|
replacement: [
|
|
|
|
|
{
|
|
|
|
|
match: /Build Number: "\).concat\(("\d+")/,
|
|
|
|
|
replace: "Build Number: \").concat($self.setBuildNumber($1)"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
match: /Version Hash: \"\).concat\(("\w+")/,
|
|
|
|
|
replace: "Version Hash: \").concat($self.setVersionHash($1)"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
setBuildNumber(buildNumber) {
|
|
|
|
|
return BUILD_NUMBER = buildNumber;
|
|
|
|
|
},
|
|
|
|
|
setVersionHash(versionHash) {
|
|
|
|
|
return VERSION_HASH = versionHash;
|
|
|
|
|
},
|
2024-10-25 17:46:10 -04:00
|
|
|
|
commands: [
|
|
|
|
|
{
|
|
|
|
|
name: "venfetch",
|
|
|
|
|
description: "neofetch for vencord",
|
|
|
|
|
inputType: ApplicationCommandInputType.BUILT_IN,
|
|
|
|
|
execute: (args: Argument[], ctx: CommandContext) => {
|
|
|
|
|
const { username } = UserStore.getCurrentUser();
|
2024-10-26 09:47:49 -04:00
|
|
|
|
const info: Record<string, string | null> = {
|
|
|
|
|
version: `${VERSION} ~ ${gitHash}${SettingsPlugin.additionalInfo} - ${Intl.DateTimeFormat(navigator.language, { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}`,
|
2024-10-27 10:58:43 -04:00
|
|
|
|
client: `${t(window.GLOBAL_ENV.RELEASE_CHANNEL)} ~ ${clientVersion()}`,
|
2024-10-27 11:57:50 -04:00
|
|
|
|
// TODO: fix this
|
|
|
|
|
// build: `${BUILD_NUMBER ?? "Unknown"} (${VERSION_HASH?.slice(0, 7) ?? 'unknown'})`,
|
2024-10-26 09:47:49 -04:00
|
|
|
|
// @ts-ignore
|
2024-10-27 11:57:50 -04:00
|
|
|
|
platform: navigator.userAgentData?.platform ? `${navigator.userAgentData?.platform} (${navigator.platform})` : navigator.platform,
|
2024-10-26 09:47:49 -04:00
|
|
|
|
plugins: getEnabledPlugins(),
|
2024-10-27 11:56:54 -04:00
|
|
|
|
uptime: `${~~((Date.now() - window.GLOBAL_ENV.HTML_TIMESTAMP) / 1000)}s`,
|
2024-10-26 09:47:49 -04:00
|
|
|
|
// TODO: pr to vencord real and add to vencordnative
|
|
|
|
|
// memory: `${humanFileSize(VencordNative.memoryUsage().heapUsed)} / ${humanFileSize(VencordNative.memoryUsage().heapTotal)}`,
|
|
|
|
|
_: null,
|
|
|
|
|
|
2024-10-26 12:06:32 -04:00
|
|
|
|
donor: getDonorStatus() ? "yes" : "no",
|
2024-10-27 11:57:50 -04:00
|
|
|
|
contributor: getContribStatus() ? "yes" : "no",
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
|
|
|
|
__: null,
|
|
|
|
|
|
2024-10-26 12:06:32 -04:00
|
|
|
|
__COLOR_TEST__: "[2;40m[2;30m███[0m[2;40m[0m[2;31m[0m[2;30m███[0m[2;31m███[0m[2;32m███[0m[2;33m███[0m[2;34m███[0m[2;35m███[0m[2;36m███[0m[2;37m███[0m"
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
|
|
|
|
// electron web context, want to get total memory usage
|
2024-10-25 17:46:10 -04:00
|
|
|
|
};
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
|
|
|
|
const computed: [string, string | null][] = Object.entries(info).map(([key, value]) => [key, value]);
|
|
|
|
|
|
2024-10-26 12:06:32 -04:00
|
|
|
|
let str = "";
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
2024-10-26 12:06:32 -04:00
|
|
|
|
str += `${lines[0]}${" ".repeat(25 - lines[0].length)}[1;2m[4;2m[0m[0m[4;2m[1;2m${username}[0m[0m\n`;
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
|
|
|
|
for (let i = 1; i < computed.length + 1; i++) {
|
|
|
|
|
const line = computed[i - 1];
|
|
|
|
|
|
|
|
|
|
if (lines[i]) {
|
|
|
|
|
str += `${lines[i]}`;
|
|
|
|
|
|
2024-10-26 12:06:32 -04:00
|
|
|
|
if (line && line[1] !== null && line[0] !== "__COLOR_TEST__") str += `${" ".repeat(25 - sanitised[i].length)}[2;35m[0m[2;35m${t(line[0])}: [0m[0m${line[1]}[0m[2;35m[0m\n`;
|
|
|
|
|
else if (line[0] === "__COLOR_TEST__") str += line[0] + "\n"; else str += "\n";
|
2024-10-26 09:47:49 -04:00
|
|
|
|
} else {
|
2024-10-26 12:06:32 -04:00
|
|
|
|
if (line && line[1] !== null && line[0] !== "__COLOR_TEST__") str += `${" ".repeat(25)}[2;35m[0m[2;35m${t(line[0])}: [0m[0m${line[1]}[0m[2;35m[0m\n`;
|
|
|
|
|
else if (line[0] === "__COLOR_TEST__") str += `${" ".repeat(25)}${line[1]}\n`; else str += "\n";
|
2024-10-26 09:47:49 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-25 17:46:10 -04:00
|
|
|
|
sendMessage(ctx.channel.id, {
|
2024-10-26 09:47:49 -04:00
|
|
|
|
content: `\`\`\`ansi\n${str}\n\`\`\``
|
2024-10-25 17:46:10 -04:00
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
});
|
2024-10-26 09:47:49 -04:00
|
|
|
|
|
2024-10-27 11:56:54 -04:00
|
|
|
|
const t = (e: string) => e.length > 0 ? e[0].toUpperCase() + e.slice(1) : "";
|