DiscordDevBanner: Redo

This commit is contained in:
thororen1234 2025-08-03 19:37:14 -04:00
parent 5dbde80ce7
commit 0bfbaa9cb6
No known key found for this signature in database
4 changed files with 166 additions and 19 deletions

View file

@ -0,0 +1,36 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2025 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
const settings = definePluginSettings({
autoFillArguments: {
description: "Automatically fill command with all arguements instead of just required ones",
type: OptionType.BOOLEAN,
default: true,
}
});
export default definePlugin({
name: "BetterCommands",
description: "Enhances the command system with miscellaneous improvements.",
authors: [EquicordDevs.thororen],
settings,
patches: [
{
find: 'applicationCommand",',
predicate: () => settings.store.autoFillArguments,
replacement: [
{
match: /!\i\.has.{0,10}&&\(\i\.required.{0,20}\]\)/,
replace: "true"
},
]
}
]
});

View file

@ -4,11 +4,49 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { migratePluginSettings } from "@api/Settings";
import "./styles.css";
import { EquicordDevs } from "@utils/constants";
import definePlugin from "@utils/types";
import SettingsPlugin from "plugins/_core/settings";
import gitHash from "~git-hash";
import { settings } from "./settings";
function getVersion(): string {
if (IS_DEV) return "Dev";
if (IS_WEB) return "Web";
if (IS_VESKTOP) return `Vesktop v${VesktopNative.app.getVersion()}`;
if (IS_EQUIBOP) return `Equibop v${VesktopNative.app.getVersion()}`;
if (IS_STANDALONE) return "Standalone";
return "";
}
export function transform(state?: string): string {
const { RELEASE_CHANNEL, BUILD_NUMBER, VERSION_HASH } = window.GLOBAL_ENV;
const buildChannel: string = names[RELEASE_CHANNEL] || RELEASE_CHANNEL.charAt(0).toUpperCase() + RELEASE_CHANNEL.slice(1);
const { chromiumVersion, electronVersion, } = SettingsPlugin;
const format = settings.store.format ?? "{buildChannel} {buildNumber} ({buildHash}) | {equicordName} {equicordVersion} ({equicordHash})";
const baseFormat = state ?? format;
const formatted = baseFormat
.replace(/{discordName}/g, "Discord")
.replace(/{buildChannel}/g, buildChannel)
.replace(/{buildNumber}/g, BUILD_NUMBER)
.replace(/{buildHash}/g, VERSION_HASH.slice(0, 9))
.replace(/{equicordName}/g, "Equicord")
.replace(/{equicordVersion}/g, VERSION)
.replace(/{equicordHash}/g, gitHash)
.replace(/{equicordPlatform}/g, getVersion())
.replace(/{electronName}/g, "Electron")
.replace(/{electronVersion}/g, electronVersion)
.replace(/{chromiumName}/g, "Chromium")
.replace(/{chromiumVersion}/g, chromiumVersion);
return formatted;
}
// By default Discord only seems to only display 'Staging' so we map the names ourself
const names: Record<string, string> = {
stable: "Stable",
ptb: "PTB",
@ -16,14 +54,11 @@ const names: Record<string, string> = {
staging: "Staging"
};
// Useless for the normal User, but useful for me
migratePluginSettings("DiscordDevBanner", "devBanner");
export default definePlugin({
name: "DiscordDevBanner",
description: "Enables the Discord developer banner, in which displays the build-ID",
authors: [EquicordDevs.KrystalSkull],
authors: [EquicordDevs.KrystalSkull, EquicordDevs.thororen],
settings,
patches: [
{
find: ".devBanner,",
@ -37,20 +72,11 @@ export default definePlugin({
replace: "$1null;"
},
{
match: /\i\.\i\.format\(.{0,15},{buildNumber:(.{0,10})}\)/,
replace: "$self.transform($1)"
match: /\i\.\i\.format\(.{0,40}\)/,
replace: "$self.transform()"
},
]
}
],
transform(buildNumber: string) {
const releaseChannel: string = window.GLOBAL_ENV.RELEASE_CHANNEL;
if (names[releaseChannel]) {
return `${names[releaseChannel]} ${buildNumber}`;
} else {
return `${releaseChannel.charAt(0).toUpperCase() + releaseChannel.slice(1)} ${buildNumber}`;
}
},
transform,
});

View file

@ -0,0 +1,76 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2025 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { OptionType } from "@utils/types";
import { Forms, TextInput, useState } from "@webpack/common";
import { transform } from ".";
export const settings = definePluginSettings({
format: {
component: ({ setValue }) => FormatSetting(setValue),
type: OptionType.COMPONENT,
default: "{buildChannel} {buildNumber} ({buildHash}) | {equicordName} {equicordVersion} ({equicordHash})",
restartNeeded: true
}
});
function FormatSetting(setValue) {
const { format } = settings.store;
const [state, setState] = useState(format ?? "{buildChannel} {buildNumber} ({buildHash}) | {equicordName} {equicordVersion} ({equicordHash})");
const [error, setError] = useState<string | null>(null);
const placeholderInfo = [
"{discordName} - The word 'Discord'",
"{buildChannel} - Discord build channel (e.g. Stable)",
"{buildNumber} - Discord build number (e.g. 123456)",
"{buildHash} - Discord build hash (e.g. 123456789)",
"{equicordName} - The word 'Equicord'",
"{equicordVersion} - Version of Equicord (e.g. 1.0.0)",
"{equicordHash} - Equicord build hash (e.g. 123456789)",
"{equicordPlatform} - Platform Equicord is running on (e.g. Dev)",
"{electronName} - The word 'Electron'",
"{electronVersion} - Electron runtime version (e.g. 25.0.0)",
"{chromiumName} - The word 'Chromium'",
"{chromiumVersion} - Chromium engine version (e.g. 125.0.0.0)",
];
function handleChange(newValue) {
if (!newValue.trim()) {
setError("Format cannot be empty.");
return;
}
setError(null);
setState(newValue);
setValue(newValue);
}
const preview = transform(state);
return (
<Forms.FormSection>
<Forms.FormTitle>Custom Format</Forms.FormTitle>
<Forms.FormText className={"vc-discord-dev-banner"}>
The format to transform the build number to. You can use the following placeholders:
{"\n\n"}
{placeholderInfo.join("\n")}
{"\n\n"}
</Forms.FormText>
<Forms.FormText className="vc-discord-dev-banner">Preview: {preview}</Forms.FormText>
<TextInput
value={state}
onChange={handleChange}
placeholder="{buildChannel} {buildNumber} ({buildHash}) | {equicordName} {equicordVersion} ({equicordHash})"
/>
{error && (
<Forms.FormText className={"vc-discord-dev-banner-error"}>{error}</Forms.FormText>
)}
</Forms.FormSection>
);
}

View file

@ -0,0 +1,9 @@
.vc-discord-dev-banner {
white-space: pre-wrap;
padding: 2px;
}
.vc-discord-dev-banner-error {
margin-top: 8px;
color: var(--text-danger);
}