QuestionMarkReplacement: Use TextReplace

This commit is contained in:
thororen1234 2026-03-20 13:25:05 -04:00
parent d180234a57
commit 9e12799d1d
No known key found for this signature in database
4 changed files with 8 additions and 59 deletions

View file

@ -16,7 +16,7 @@ import { Icon } from "@vencord/discord-types";
import { Clickable, TextInput, useCallback, useEffect, useMemo, useState } from "@webpack/common";
import { IconsDef } from "../types";
import { getIconsModule } from "../utils";
import { IconsModule } from "../utils";
import { openIconModal } from "./Modals";
let cachedIcons: IconsDef | null = null;
@ -24,9 +24,8 @@ let cachedIcons: IconsDef | null = null;
function getIcons(): IconsDef {
if (cachedIcons) return cachedIcons;
const iconsModule = getIconsModule();
cachedIcons = Object.fromEntries(
Object.entries(iconsModule).filter(([name, fn]) =>
Object.entries(IconsModule).filter(([name, fn]) =>
typeof fn === "function" && name.endsWith("Icon")
)
);

View file

@ -12,7 +12,7 @@ import { CssColorData, IconSize } from "./types";
let colorKeys: string[] = [];
const Colors = findByPropsLazy("colors", "layout");
const IconsModule = findByPropsLazy("AngleBracketsIcon", "StaffBadgeIcon") as Record<string, Icon>;
export const IconsModule = findByPropsLazy("AngleBracketsIcon", "StaffBadgeIcon") as Record<string, Icon>;
export const iconSizesInPx: Record<string, number> = findByPropsLazy("md", "lg", "xxs");
export const iconSizes: IconSize[] = ["xxs", "xs", "sm", "md", "lg"];
@ -37,10 +37,6 @@ export const cssColors = new Proxy({} as Record<number, CssColorData>, {
}
});
export function getIconsModule(): Record<string, Icon> {
return IconsModule;
}
waitFor(["colors", "layout"], m => {
colorKeys = Object.keys(m.colors);
});

View file

@ -16,9 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ErrorBoundary from "@components/ErrorBoundary";
import { EquicordDevs } from "@utils/constants";
import definePlugin from "@utils/types";
import { Message } from "@vencord/discord-types";
import { findComponentByCodeLazy } from "@webpack";
const PinIcon = findComponentByCodeLazy("1-.06-.63L6.16");
@ -31,11 +31,11 @@ export default definePlugin({
find: "isUnsupported})",
replacement: {
match: /WITH_CONTENT\}\)/,
replace: "$&,$self.PinnedIcon(arguments[0].message)"
replace: "$&,$self.renderPinIcon(arguments[0].message)"
}
}
],
PinnedIcon({ pinned }: Message) {
return pinned ? (<PinIcon size="xs" style={{ position: "absolute", right: "0", top: "0" }} />) : null;
}
renderPinIcon: ErrorBoundary.wrap(message => {
return message?.pinned ? (<PinIcon size="xs" style={{ position: "absolute", right: "0", top: "0" }} />) : null;
}, { noop: true })
});

View file

@ -1,46 +0,0 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { addMessagePreSendListener, removeMessagePreSendListener } from "@api/MessageEvents";
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
const settings = definePluginSettings({
replace: {
type: OptionType.STRING,
description: "Replace with",
default: ":face_with_monocle:"
},
});
function replaceQuestionMarks(content: string): string {
const allQuestionMarks = content.split("").every(char => char === "?");
if (allQuestionMarks) {
return content.replace(/\?/g, settings.store.replace);
} else {
return content;
}
}
export default definePlugin({
name: "QuestionMarkReplacement",
description: "Replace all question marks with chosen string, if message only contains question marks.",
authors: [Devs.nyx],
settings,
start() {
this.preSend = addMessagePreSendListener((_, msg) => {
msg.content = replaceQuestionMarks(msg.content);
});
},
stop() {
removeMessagePreSendListener(this.preSend);
}
});