mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-25 16:56:23 +00:00
no longer crashes on invalid regex
This commit is contained in:
parent
4b4ad65c6e
commit
808c664d93
1 changed files with 9 additions and 1 deletions
|
@ -34,6 +34,14 @@ async function addRegex(updater: () => void) {
|
|||
updater();
|
||||
}
|
||||
|
||||
function safeMatchesRegex(s: string, r: string) {
|
||||
try {
|
||||
return s.match(new RegExp(r));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const settings = definePluginSettings({
|
||||
replace: {
|
||||
type: OptionType.COMPONENT,
|
||||
|
@ -107,7 +115,7 @@ export default definePlugin({
|
|||
},
|
||||
|
||||
applyRegexes(m) {
|
||||
if (regexes.some(r => r != "" && m.content.match(new RegExp(r)))) {
|
||||
if (regexes.some(r => r != "" && safeMatchesRegex(m.content, r))) {
|
||||
m.mentions.push(me);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue