Plugin

QuestionMarkReplace

Replace all question marks with chosen string, if message only contains question marks.

index.tsx
Download

Source

src/plugins/questionMarkReplacement/index.tsx
1/*
2 * FiveCord — a Discord client mod
3 * Copyright (c) 2025 FiveCord
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
8import { definePluginSettings } from "@api/Settings";
9import { Devs } from "@utils/constants";
10import definePlugin, { OptionType } from "@utils/types";
11
12const settings = definePluginSettings({
13 replace: {
14 type: OptionType.STRING,
15 description: "Replace with",
16 default: ":face_with_monocle:"
17 },
18});
19
20
21function replaceQuestionMarks(content: string): string {
22 const allQuestionMarks = content.split("").every(char => char === "?");
23
24 if (allQuestionMarks) {
25 return content.replace(/\?/g, settings.store.replace);
26 } else {
27 return content;
28 }
29}
30
31export default definePlugin({
32 name: "QuestionMarkReplace",
33 description: "Replace all question marks with chosen string, if message only contains question marks.",
34 authors: [Devs.FiveCord],
35
36 settings,
37
38 start() {
39 this.preSend = addPreSendListener((_, msg) => {
40 msg.content = replaceQuestionMarks(msg.content);
41 });
42 },
43
44 stop() {
45 removePreSendListener(this.preSend);
46 }
47});
48