Plugin
QuestionMarkReplace
Replace all question marks with chosen string, if message only contains question marks.
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";8
import { definePluginSettings } from "@api/Settings";9
import { Devs } from "@utils/constants";10
import definePlugin, { OptionType } from "@utils/types";11
12
const settings = definePluginSettings({13
replace: {14
type: OptionType.STRING,15
description: "Replace with",16
default: ":face_with_monocle:"17
},18
});19
20
21
function 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
31
export 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