VcNarrator: Improve username cleaning to support non ascii chars
This commit is contained in:
parent
9023d45d9e
commit
7568bbaed0
1 changed files with 14 additions and 6 deletions
|
@ -59,17 +59,20 @@ function speak(text: string, settings: any = Settings.plugins.VcNarrator) {
|
||||||
speechSynthesis.speak(speech);
|
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")
|
return str.normalize("NFKC")
|
||||||
.replace(/[^\w ]/g, "")
|
.replace(replacer, "")
|
||||||
.trim()
|
.trim();
|
||||||
|| fallback;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatText(str: string, user: string, channel: string) {
|
function formatText(str: string, user: string, channel: string) {
|
||||||
return str
|
return str
|
||||||
.replaceAll("{{USER}}", clean(user, user ? "Someone" : ""))
|
.replaceAll("{{USER}}", clean(user) || user ? "Someone" : "")
|
||||||
.replaceAll("{{CHANNEL}}", clean(channel, "channel"));
|
.replaceAll("{{CHANNEL}}", clean(channel) || "channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -235,6 +238,11 @@ export default definePlugin({
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
|
latinOnly: {
|
||||||
|
description: "Strip non latin characters from names before saying them",
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
joinMessage: {
|
joinMessage: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Join Message",
|
description: "Join Message",
|
||||||
|
|
Loading…
Reference in a new issue