venfetch/index.ts

111 lines
4.7 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";
2024-10-26 08:39:06 -04:00
import plugins, { PluginMeta } from "~plugins";
2024-10-25 17:46:10 -04:00
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})`;
})();
2024-10-26 08:39:06 -04:00
const launchTime = Date.now();
2024-10-25 17:46:10 -04:00
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");
}
2024-10-26 08:39:06 -04:00
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
};
}
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 = {
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
};
2024-10-26 08:39:06 -04:00
const pluggers = getPluginCount();
2024-10-25 17:46:10 -04:00
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)}
2024-10-26 08:39:06 -04:00
${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")}
2024-10-25 17:46:10 -04:00
${line10}
${line11}
${line12}`
});
return;
}
}
]
});