venfetch/index.ts
2024-10-26 08:39:06 -04:00

111 lines
4.7 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 from "@utils/types";
import { GuildMemberStore, UserStore } from "@webpack/common";
import plugins, { 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}`;
// @ts-expect-error
const name = typeof unsafeWindow !== "undefined" ? "UserScript" : "Web";
return `${name} (${navigator.userAgent})`;
})();
const launchTime = 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 = "```";
function getEnabledPlugins() {
let counter = 0;
Object.entries(Vencord.Plugins.plugins).forEach(([key, value]) => {
if (value.started) counter++;
});
return counter.toString();
}
function getDonorStatus() {
return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1042507929485586532");
}
function getPluginCount() {
const isApiPlugin = (plugin: string) => plugin.endsWith("API") || plugins[plugin].required;
const enabledPlugins = Object.keys(plugins)
.filter(p => Vencord.Plugins.isPluginEnabled(p) && !isApiPlugin(p));
const enabledStockPlugins = enabledPlugins.filter(p => !PluginMeta[p].userPlugin);
const enabledUserPlugins = enabledPlugins.filter(p => PluginMeta[p].userPlugin);
return {
stock: enabledStockPlugins.length,
user: enabledUserPlugins.length
};
}
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 = {
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 pluggers = getPluginCount();
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%", `${pluggers.stock} official, ${pluggers.user} userplugins`)}
${line8.replace("%uptime%", `${Math.floor((Date.now() - launchTime) / 1000)}s`)}
${line9.replace("%donorStatus%", getDonorStatus() ? "yop" : "nop")}
${line10}
${line11}
${line12}`
});
return;
}
}
]
});