aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-05-29 16:00:02 +0200
committerV <vendicated@riseup.net>2023-05-30 15:23:32 +0200
commit7568bbaed07a75e3f68ba6cec8c013825c9ed046 (patch)
tree478511f6f34c712bfa864ccf173cf163f80bf20c /src/plugins
parent9023d45d9e594c49b09e4c7c0e6f23f539dad3d2 (diff)
downloadVencord-7568bbaed07a75e3f68ba6cec8c013825c9ed046.tar.gz
Vencord-7568bbaed07a75e3f68ba6cec8c013825c9ed046.tar.bz2
Vencord-7568bbaed07a75e3f68ba6cec8c013825c9ed046.zip
VcNarrator: Improve username cleaning to support non ascii chars
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/vcNarrator.tsx20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/plugins/vcNarrator.tsx b/src/plugins/vcNarrator.tsx
index b8f0fde..caca70d 100644
--- a/src/plugins/vcNarrator.tsx
+++ b/src/plugins/vcNarrator.tsx
@@ -59,17 +59,20 @@ function speak(text: string, settings: any = Settings.plugins.VcNarrator) {
speechSynthesis.speak(speech);
}
-function clean(str: string, fallback: string) {
+function clean(str: string) {
+ const replacer = Settings.plugins.VcNarrator.latinOnly
+ ? /[^\p{Script=Latin}\p{Number}\p{Punctuation}\s]/gu
+ : /[^\p{Letter}\p{Number}\p{Punctuation}\s]/gu;
+
return str.normalize("NFKC")
- .replace(/[^\w ]/g, "")
- .trim()
- || fallback;
+ .replace(replacer, "")
+ .trim();
}
function formatText(str: string, user: string, channel: string) {
return str
- .replaceAll("{{USER}}", clean(user, user ? "Someone" : ""))
- .replaceAll("{{CHANNEL}}", clean(channel, "channel"));
+ .replaceAll("{{USER}}", clean(user) || user ? "Someone" : "")
+ .replaceAll("{{CHANNEL}}", clean(channel) || "channel");
}
/*
@@ -235,6 +238,11 @@ export default definePlugin({
type: OptionType.BOOLEAN,
default: false
},
+ latinOnly: {
+ description: "Strip non latin characters from names before saying them",
+ type: OptionType.BOOLEAN,
+ default: false
+ },
joinMessage: {
type: OptionType.STRING,
description: "Join Message",