diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2020-07-27 13:34:20 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-27 13:34:20 +0900 |
| commit | cf43dd6ec530ba4a3f589ae917e89533b352f6a3 (patch) | |
| tree | 76f35d06299b40370ec061ee5ed58182847d2e6e /src/client/scripts | |
| parent | refactor(client): Do not mutate prop directly (diff) | |
| download | sharkey-cf43dd6ec530ba4a3f589ae917e89533b352f6a3.tar.gz sharkey-cf43dd6ec530ba4a3f589ae917e89533b352f6a3.tar.bz2 sharkey-cf43dd6ec530ba4a3f589ae917e89533b352f6a3.zip | |
ワードミュート (#6594)
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
Diffstat (limited to 'src/client/scripts')
| -rw-r--r-- | src/client/scripts/check-word-mute.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/client/scripts/check-word-mute.ts b/src/client/scripts/check-word-mute.ts new file mode 100644 index 0000000000..3b1fa75b1e --- /dev/null +++ b/src/client/scripts/check-word-mute.ts @@ -0,0 +1,26 @@ +export async function checkWordMute(note: Record<string, any>, me: Record<string, any> | null | undefined, mutedWords: string[][]): Promise<boolean> { + // 自分自身 + if (me && (note.userId === me.id)) return false; + + const words = mutedWords + // Clean up + .map(xs => xs.filter(x => x !== '')) + .filter(xs => xs.length > 0); + + if (words.length > 0) { + if (note.text == null) return false; + + const matched = words.some(and => + and.every(keyword => { + const regexp = keyword.match(/^\/(.+)\/(.*)$/); + if (regexp) { + return new RegExp(regexp[1], regexp[2]).test(note.text!); + } + return note.text!.includes(keyword); + })); + + if (matched) return true; + } + + return false; +} |