Compare commits
9 commits
Author | SHA1 | Date | |
---|---|---|---|
b8f77887ac | |||
c4d7b98e72 | |||
788c01e81a | |||
cb617a8ed7 | |||
f095065fd5 | |||
808dfc8247 | |||
5c867c19f9 | |||
59c84ebb5d | |||
585a1035c0 |
2 changed files with 150 additions and 127 deletions
269
index.ts
269
index.ts
|
@ -8,14 +8,18 @@ import { ApplicationCommandInputType, Argument, CommandContext } from "@api/Comm
|
||||||
import { gitHash } from "@shared/vencordUserAgent";
|
import { gitHash } from "@shared/vencordUserAgent";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { sendMessage } from "@utils/discord";
|
import { sendMessage } from "@utils/discord";
|
||||||
import definePlugin, { Plugin } from "@utils/types";
|
import definePlugin, { Plugin, PluginNative } 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 { isPluginDev } from "@utils/misc";
|
import { isPluginDev, tryOrElse } from "@utils/misc";
|
||||||
|
import { findByCodeLazy } from "@webpack";
|
||||||
|
import { getUserSettingLazy } from "../../api/UserSettings.js";
|
||||||
import SettingsPlugin from "../../plugins/_core/settings";
|
import SettingsPlugin from "../../plugins/_core/settings";
|
||||||
|
|
||||||
|
const Native = VencordNative.pluginHelpers.venfetch as PluginNative<typeof import("./native")>;
|
||||||
|
|
||||||
const clientVersion = () => {
|
const clientVersion = () => {
|
||||||
const version = IS_DISCORD_DESKTOP ? DiscordNative.app.getVersion() : IS_VESKTOP ? VesktopNative.app.getVersion() : null;
|
const version = IS_DISCORD_DESKTOP ? DiscordNative.app.getVersion() : IS_VESKTOP ? VesktopNative.app.getVersion() : null;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -24,29 +28,34 @@ const clientVersion = () => {
|
||||||
return `${name}${version ? ` v${version}` : ''}`;
|
return `${name}${version ? ` v${version}` : ''}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const lines = `\
|
const 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';
|
||||||
VV VV
|
|
||||||
VV VV
|
|
||||||
VV VV
|
const LOGO_WITH_ANSI = `\
|
||||||
VV VV
|
\n\
|
||||||
VVV
|
\tVV VV
|
||||||
[2;35mCCCCCCC
|
\t VV VV
|
||||||
[2;35mCC
|
\t VV VV
|
||||||
[2;35mCC
|
\t VV VV
|
||||||
[2;35mCC
|
\t VVV
|
||||||
[2;35mCCCCCCC[0m\
|
\t [2;35mCCCCCCC
|
||||||
|
\t [2;35mCC
|
||||||
|
\t [2;35mCC
|
||||||
|
\t [2;35mCC
|
||||||
|
\t [2;35mCCCCCCC[0m\
|
||||||
`.split("\n");
|
`.split("\n");
|
||||||
const sanitised = `\
|
const LOGO_NO_ANSI = `\
|
||||||
VV VV
|
\n\
|
||||||
VV VV
|
\tVV VV
|
||||||
VV VV
|
\t VV VV
|
||||||
VV VV
|
\t VV VV
|
||||||
VVV
|
\t VV VV
|
||||||
CCCCCCC
|
\t VVV
|
||||||
CC
|
\t CCCCCCC
|
||||||
CC
|
\t CC
|
||||||
CC
|
\t CC
|
||||||
CCCCCCC\
|
\t CC
|
||||||
|
\t CCCCCCC\
|
||||||
`.split("\n");
|
`.split("\n");
|
||||||
|
|
||||||
// ```ansi
|
// ```ansi
|
||||||
|
@ -62,25 +71,31 @@ VV VV
|
||||||
// [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
|
// [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
|
||||||
// ```;
|
// ```;
|
||||||
|
|
||||||
const isApiPlugin = (plugin: Plugin) => plugin.name.endsWith("API") || plugin.required;
|
const isApiPlugin = (plugin: Plugin) => plugin.name?.endsWith("API") || plugin.required;
|
||||||
|
|
||||||
function getEnabledPlugins() {
|
function getEnabledPlugins() {
|
||||||
let counter = 0;
|
const counters = {
|
||||||
let total = 0;
|
official: {
|
||||||
let userpluginsCount = 0;
|
enabled: 0,
|
||||||
let totalUserplugins = 0;
|
total: 0
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
enabled: 0,
|
||||||
|
total: 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Object.values(plugins).filter((plugin) => !isApiPlugin(plugin)).forEach((plugin) => {
|
Object.values(Vencord.Plugins.plugins).filter((plugin) => !isApiPlugin(plugin)).forEach((plugin) => {
|
||||||
if (PluginMeta[plugin.name].userPlugin) {
|
if (PluginMeta[plugin.name]?.userPlugin) {
|
||||||
if (plugin.started) userpluginsCount++;
|
if (plugin.started) counters.user.enabled++;
|
||||||
totalUserplugins++;
|
counters.user.total++;
|
||||||
} else {
|
} else {
|
||||||
if (plugin.started) counter++;
|
if (plugin.started) counters.official.enabled++;
|
||||||
total++;
|
counters.official.total++;
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return `${counter} / ${total} (official)` + (totalUserplugins ? `, ${userpluginsCount} / ${totalUserplugins} (userplugins)` : "");
|
return `${counters.official.enabled} / ${counters.official.total} (official)` + (counters.user.total ? `, ${counters.user.enabled} / ${counters.user.total} (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");
|
||||||
|
@ -90,6 +105,95 @@ function getContribStatus() {
|
||||||
return isPluginDev(userId) || GuildMemberStore.getMember("1015060230222131221", userId).roles.includes("1026534353167208489");
|
return isPluginDev(userId) || GuildMemberStore.getMember("1015060230222131221", userId).roles.includes("1026534353167208489");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const getVersions = findByCodeLazy("logsUploaded:new Date().toISOString(),");
|
||||||
|
const ShowCurrentGame = getUserSettingLazy<boolean>("status", "showCurrentGame")!;
|
||||||
|
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "venfetch",
|
||||||
|
description: "neofetch for vencord",
|
||||||
|
authors: [Devs.nin0dev],
|
||||||
|
commands: [
|
||||||
|
{
|
||||||
|
name: "venfetch",
|
||||||
|
description: "neofetch for vencord",
|
||||||
|
inputType: ApplicationCommandInputType.BUILT_IN,
|
||||||
|
execute: async (args: Argument[], ctx: CommandContext) => {
|
||||||
|
const commonIssues = {
|
||||||
|
"NoRPC": Vencord.Plugins.isPluginEnabled("NoRPC"),
|
||||||
|
"disabled activities": tryOrElse(() => !ShowCurrentGame.getSetting(), false),
|
||||||
|
"outdated": BUILD_TIMESTAMP < Date.now() - 12096e5,
|
||||||
|
};
|
||||||
|
|
||||||
|
const memory = await Native?.getMemory();
|
||||||
|
|
||||||
|
const { username } = UserStore.getCurrentUser();
|
||||||
|
const versions = getVersions();
|
||||||
|
const info: Record<string, string | null> = {
|
||||||
|
version: `${VERSION} ~ ${gitHash}${SettingsPlugin.additionalInfo} - ${Intl.DateTimeFormat(navigator.language, { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}${!IS_STANDALONE ? ` ~ dev` : ""}`,
|
||||||
|
client: `${t(window.GLOBAL_ENV.RELEASE_CHANNEL)} ~ ${clientVersion()}`,
|
||||||
|
'Build Number': `${versions.buildNumber} ~ Hash: ${versions.versionHash?.slice(0, 7) ?? 'unknown'}`,
|
||||||
|
issues: Object.entries(commonIssues).filter(([_, value]) => value).map(([key]) => key).join(", ") || '',
|
||||||
|
|
||||||
|
_: null,
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
platform: navigator.userAgentData?.platform ? `${navigator.userAgentData?.platform} (${navigator.platform})` : navigator.platform,
|
||||||
|
plugins: getEnabledPlugins(),
|
||||||
|
uptime: `${~~((Date.now() - window.GLOBAL_ENV.HTML_TIMESTAMP) / 1000)}s`,
|
||||||
|
memory: memory ? `${humanFileSize(memory.heapUsed)} / ${humanFileSize(memory.heapTotal)}` : '',
|
||||||
|
|
||||||
|
__: null,
|
||||||
|
|
||||||
|
donor: getDonorStatus() ? "yes" : "no",
|
||||||
|
contributor: getContribStatus() ? "yes" : "no",
|
||||||
|
|
||||||
|
___: null,
|
||||||
|
|
||||||
|
// electron web context, want to get total memory usage
|
||||||
|
};
|
||||||
|
|
||||||
|
const computed: [string, string | null][] = Object.entries(info).filter(([key, value]) => value === null || value!.length).map(([key, value]) => [key, value]);
|
||||||
|
|
||||||
|
let str = "";
|
||||||
|
const MAGIC_NUMBER = 25;
|
||||||
|
|
||||||
|
str += `${LOGO_WITH_ANSI[0]}${" ".repeat(MAGIC_NUMBER - LOGO_NO_ANSI[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 logoLine = LOGO_WITH_ANSI[i];
|
||||||
|
const line = computed[i - 1];
|
||||||
|
|
||||||
|
if (logoLine) {
|
||||||
|
str += logoLine;
|
||||||
|
str += " ".repeat(MAGIC_NUMBER - 3 - LOGO_NO_ANSI[i].length);
|
||||||
|
} else {
|
||||||
|
str += " ".repeat(MAGIC_NUMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [key, value] = line;
|
||||||
|
|
||||||
|
if (!key.startsWith("_") && value) {
|
||||||
|
str += `[2;35m${key[0].toUpperCase()}${key.slice(1)}: [0m${value}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
str += '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
str += `${" ".repeat(MAGIC_NUMBER)}${COLOR_TEST}\n`;
|
||||||
|
|
||||||
|
sendMessage(ctx.channel.id, {
|
||||||
|
content: `\`\`\`ansi\n${str}\n\`\`\``
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const t = (e: string) => e.length > 0 ? e[0].toUpperCase() + e.slice(1) : "";
|
||||||
function humanFileSize(bytes, si = false, dp = 1) {
|
function humanFileSize(bytes, si = false, dp = 1) {
|
||||||
const thresh = si ? 1000 : 1024;
|
const thresh = si ? 1000 : 1024;
|
||||||
|
|
||||||
|
@ -111,92 +215,3 @@ function humanFileSize(bytes, si = false, dp = 1) {
|
||||||
|
|
||||||
return bytes.toFixed(dp) + " " + units[u];
|
return bytes.toFixed(dp) + " " + units[u];
|
||||||
}
|
}
|
||||||
|
|
||||||
let BUILD_NUMBER;
|
|
||||||
let VERSION_HASH;
|
|
||||||
|
|
||||||
export default definePlugin({
|
|
||||||
name: "venfetch",
|
|
||||||
description: "neofetch for vencord",
|
|
||||||
authors: [Devs.nin0dev],
|
|
||||||
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;
|
|
||||||
},
|
|
||||||
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()}`,
|
|
||||||
// TODO: fix this
|
|
||||||
// build: `${BUILD_NUMBER ?? "Unknown"} (${VERSION_HASH?.slice(0, 7) ?? 'unknown'})`,
|
|
||||||
// @ts-ignore
|
|
||||||
platform: navigator.userAgentData?.platform ? `${navigator.userAgentData?.platform} (${navigator.platform})` : navigator.platform,
|
|
||||||
plugins: getEnabledPlugins(),
|
|
||||||
uptime: `${~~((Date.now() - window.GLOBAL_ENV.HTML_TIMESTAMP) / 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" : "no",
|
|
||||||
|
|
||||||
__: 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 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, {
|
|
||||||
content: `\`\`\`ansi\n${str}\n\`\`\``
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
const t = (e: string) => e.length > 0 ? e[0].toUpperCase() + e.slice(1) : "";
|
|
||||||
|
|
8
native.ts
Normal file
8
native.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
export function getMemory() {
|
||||||
|
const memory = process.memoryUsage();
|
||||||
|
return {
|
||||||
|
heapUsed: memory.heapUsed,
|
||||||
|
heapTotal: memory.heapTotal
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue