Skip to content

Commit

Permalink
Merge branch 'preSendModeration' into sqaaakoi-stable-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sqaaakoi committed Aug 26, 2024
2 parents 3dc6a74 + 5710f4b commit 4a68c0b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/plugins/preSendModeration/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { findByCodeLazy, findLazy } from "@webpack";
import { find, findByCodeLazy } from "@webpack";

const splitWords = findByCodeLazy("/[\\p{Pd}\\p{Pc}\\p{Po}]/gu.test");

// Utility class
const Trie = findByCodeLazy("this.trie.suffix");

const makeTrieSearchFromWordListItem = (item: any) => {
let module: any[];
const trie = new Trie();
let trie: typeof Trie;
return (search: string) => {
if (module === undefined) {
module = findLazy(m => Array.isArray(m) && m.includes(item));
trie.addWords(module);
if (trie === undefined) {
trie = new Trie();
trie.addWords(find(m => Array.isArray(m) && m.includes(item)));
}
return trie.search(splitWords(search));
};
Expand All @@ -27,4 +26,4 @@ export const Filters = {
Profanity: makeTrieSearchFromWordListItem("fuck"),
"Sexual Content": makeTrieSearchFromWordListItem("69ing"),
Slurs: makeTrieSearchFromWordListItem("fags"),
};
} as Record<PropertyKey, (search: string) => any>;

0 comments on commit 4a68c0b

Please sign in to comment.