do good changes

This commit is contained in:
camila314 2024-06-24 01:56:14 -05:00
parent 31b18b221d
commit bac0ac1b6b

View file

@ -44,9 +44,9 @@ async function removeKeywordEntry(idx: number, forceUpdate: () => void) {
forceUpdate(); forceUpdate();
} }
function safeMatchesRegex(s: string, r: string) { function safeMatchesRegex(str: string, regex: string) {
try { try {
return s.match(new RegExp(r)); return str.match(new RegExp(regex));
} catch { } catch {
return false; return false;
} }
@ -57,24 +57,24 @@ enum ListType {
Whitelist = "Whitelist" Whitelist = "Whitelist"
} }
function highlightKeywords(s: string, r: Array<string>) { function highlightKeywords(str: string, regexes: Array<string>) {
let regex: RegExp; let regex: RegExp;
try { try {
regex = new RegExp(r.join("|"), "g"); regex = new RegExp(regexes.join("|"), "g");
} catch { } catch {
return [s]; return [str];
} }
const matches = s.match(regex); const matches = str.match(regex);
if (!matches) if (!matches)
return [s]; return [str];
const parts = [...matches.map(e => { const parts = [...matches.map(e => {
const idx = s.indexOf(e); const idx = str.indexOf(e);
const before = s.substring(0, idx); const before = str.substring(0, idx);
s = s.substring(idx + e.length); str = str.substring(idx + e.length);
return before; return before;
}, s), s]; }, str), str];
return parts.map(e => [ return parts.map(e => [
(<span>{e}</span>), (<span>{e}</span>),
@ -318,18 +318,16 @@ export default definePlugin({
} }
const whitelistMode = entry.listType === ListType.Whitelist; const whitelistMode = entry.listType === ListType.Whitelist;
if (!whitelistMode && listed) { if (!whitelistMode && listed) {
return; return;
} }
if (whitelistMode && !listed) { if (whitelistMode && !listed) {
return; return;
} }
if (settings.store.ignoreBots && m.author.bot && (!whitelistMode || !entry.listIds.includes(m.author.id))) {
if (settings.store.ignoreBots && m.author.bot) {
if (!whitelistMode || !entry.listIds.includes(m.author.id)) {
return; return;
} }
}
if (safeMatchesRegex(m.content, entry.regex)) { if (safeMatchesRegex(m.content, entry.regex)) {
matches = true; matches = true;