Merge branch 'main' of https://git.nin0.dev/userplugins/venfetch
This commit is contained in:
commit
ab8ed7f905
1 changed files with 112 additions and 58 deletions
170
index.ts
170
index.ts
|
@ -11,64 +11,93 @@ import { sendMessage } from "@utils/discord";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { GuildMemberStore, UserStore } from "@webpack/common";
|
import { GuildMemberStore, UserStore } from "@webpack/common";
|
||||||
|
|
||||||
import plugins, { PluginMeta } from "~plugins";
|
import { PluginMeta } from "~plugins";
|
||||||
|
|
||||||
import SettingsPlugin from "../../plugins/_core/settings";
|
import SettingsPlugin from "../../plugins/_core/settings";
|
||||||
|
|
||||||
const client = (() => {
|
const clientVersion = (() => {
|
||||||
if (IS_DISCORD_DESKTOP) return `Discord Desktop v${DiscordNative.app.getVersion()}`;
|
const version = IS_DISCORD_DESKTOP ? DiscordNative.app.getVersion() : IS_VESKTOP ? VesktopNative.app.getVersion() : null;
|
||||||
if (IS_VESKTOP) return `Vesktop v${VesktopNative.app.getVersion()}`;
|
const name = IS_DISCORD_DESKTOP ? "Desktop" : IS_VESKTOP ? "Vesktop" : typeof unsafeWindow !== "undefined" ? "UserScript" : "Web";
|
||||||
if ("legcord" in window) return `Legcord v${window.legcord.version}`;
|
|
||||||
|
|
||||||
// @ts-expect-error
|
return `${name}${version ? ` v${version}` : ""}`;
|
||||||
const name = typeof unsafeWindow !== "undefined" ? "UserScript" : "Web";
|
|
||||||
return `${name} (${navigator.userAgent})`;
|
|
||||||
})();
|
})();
|
||||||
const launchTime = Date.now();
|
const uptime = Date.now();
|
||||||
|
|
||||||
const line1 = "```ansi";
|
const lines = `\
|
||||||
// Placeholders: %username%
|
VV VV
|
||||||
const line2 = "VV VV [1;2m[4;2m[0m[0m[4;2m[1;2m%username%[0m[0m";
|
VV VV
|
||||||
const line3 = " VV VV ---------------";
|
VV VV
|
||||||
// Placeholders: %ver%
|
VV VV
|
||||||
const line4 = " VV VV [2;35m[0m[2;35mVersion: [0m[0m%ver%[0m[2;35m[0m";
|
VVV
|
||||||
// Placeholders: %client%
|
[2;35mCCCCCCC
|
||||||
const line5 = " VV VV [2;35m[0m[2;35mClient: [0m[0m%client%[0m[2;35m[0m";
|
[2;35mCC
|
||||||
// Placeholders: %platform%
|
[2;35mCC
|
||||||
const line6 = " VVV [2;35m[0m[2;35mPlatform: [0m[0m%platform%[0m[2;35m[0m";
|
[2;35mCC
|
||||||
// Placeholders: %pluginCount%
|
[2;35mCCCCCCC[0m\
|
||||||
const line7 = " [2;35mCCCCCCC [2;35m[0m[2;35mPlugin Count: [0m[0m%pluginCount%[0m[2;35m[0m";
|
`.split("\n");
|
||||||
// Placeholders: %uptime%
|
const sanitised = `\
|
||||||
const line8 = " [2;35mCC [2;35m[0m[2;35mUptime: [0m[0m%uptime%[0m[2;35m[0m";
|
VV VV
|
||||||
// Placeholders: %donorStatus%
|
VV VV
|
||||||
const line9 = " [2;35mCC [2;35m[0m[2;35mDonor: [0m[0m%donorStatus%[0m[2;35m[0m";
|
VV VV
|
||||||
const line10 = " [2;35mCC";
|
VV VV
|
||||||
const line11 = " [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";
|
VVV
|
||||||
const line12 = "```";
|
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 [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
|
||||||
|
// ```;
|
||||||
|
|
||||||
function getEnabledPlugins() {
|
function getEnabledPlugins() {
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
|
let userpluginsCount = 0;
|
||||||
|
|
||||||
Object.entries(Vencord.Plugins.plugins).forEach(([key, value]) => {
|
Object.entries(Vencord.Plugins.plugins).forEach(([key, value]) => {
|
||||||
if (value.started) counter++;
|
if (value.started) if (PluginMeta[value.name].userPlugin) userpluginsCount++; else counter++;
|
||||||
});
|
});
|
||||||
return counter.toString();
|
|
||||||
|
return `${counter} (official)` + (userpluginsCount ? `, ${userpluginsCount} (userplugins)` : "");
|
||||||
}
|
}
|
||||||
function getDonorStatus() {
|
function getDonorStatus() {
|
||||||
return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1042507929485586532");
|
return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1042507929485586532");
|
||||||
}
|
}
|
||||||
function getPluginCount() {
|
function getContribStatus() {
|
||||||
const isApiPlugin = (plugin: string) => plugin.endsWith("API") || plugins[plugin].required;
|
return GuildMemberStore.getMember("1015060230222131221", UserStore.getCurrentUser().id).roles.includes("1026534353167208489");
|
||||||
|
}
|
||||||
|
|
||||||
const enabledPlugins = Object.keys(plugins)
|
function humanFileSize(bytes, si = false, dp = 1) {
|
||||||
.filter(p => Vencord.Plugins.isPluginEnabled(p) && !isApiPlugin(p));
|
const thresh = si ? 1000 : 1024;
|
||||||
|
|
||||||
const enabledStockPlugins = enabledPlugins.filter(p => !PluginMeta[p].userPlugin);
|
if (Math.abs(bytes) < thresh) {
|
||||||
const enabledUserPlugins = enabledPlugins.filter(p => PluginMeta[p].userPlugin);
|
return bytes + " B";
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
const units = si
|
||||||
stock: enabledStockPlugins.length,
|
? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
||||||
user: enabledUserPlugins.length
|
: ["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];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
|
@ -82,29 +111,54 @@ export default definePlugin({
|
||||||
inputType: ApplicationCommandInputType.BUILT_IN,
|
inputType: ApplicationCommandInputType.BUILT_IN,
|
||||||
execute: (args: Argument[], ctx: CommandContext) => {
|
execute: (args: Argument[], ctx: CommandContext) => {
|
||||||
const { username } = UserStore.getCurrentUser();
|
const { username } = UserStore.getCurrentUser();
|
||||||
const info = {
|
const info: Record<string, string | null> = {
|
||||||
Vencord:
|
version: `${VERSION} ~ ${gitHash}${SettingsPlugin.additionalInfo} - ${Intl.DateTimeFormat(navigator.language, { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}`,
|
||||||
`v${VERSION} • ${gitHash}` +
|
client: `${t(window.GLOBAL_ENV.RELEASE_CHANNEL)} ~ ${clientVersion}`,
|
||||||
`${SettingsPlugin.additionalInfo} - ${Intl.DateTimeFormat("en-GB", { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}`,
|
// @ts-ignore
|
||||||
Client: `${window.GLOBAL_ENV.RELEASE_CHANNEL} ~ ${client}`,
|
platform: navigator.userAgentData?.platform ?? navigator.platform,
|
||||||
Platform: window.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__: "[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"
|
||||||
|
|
||||||
|
// electron web context, want to get total memory usage
|
||||||
};
|
};
|
||||||
const pluggers = getPluginCount();
|
|
||||||
|
const computed: [string, string | null][] = Object.entries(info).map(([key, value]) => [key, value]);
|
||||||
|
|
||||||
|
let str = "";
|
||||||
|
|
||||||
|
str += `${lines[0]}${" ".repeat(25 - lines[0].length)}[1;2m[4;2m[0m[0m[4;2m[1;2m${username}[0m[0m\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)}[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";
|
||||||
|
} else {
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage(ctx.channel.id, {
|
sendMessage(ctx.channel.id, {
|
||||||
content: `${line1}
|
content: `\`\`\`ansi\n${str}\n\`\`\``
|
||||||
${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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const t = (e: string) => e[0].toUpperCase() + e.slice(1);
|
||||||
|
|
Loading…
Reference in a new issue