From c8f6a16d986ac60a8f32f0526644e435f8e490f7 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Mon, 23 Apr 2018 15:24:26 +0200 Subject: [PATCH] reduce chat filters --- ui/chat/src/discussion.ts | 12 +++++++----- ui/chat/src/spam.ts | 21 --------------------- 2 files changed, 7 insertions(+), 26 deletions(-) delete mode 100644 ui/chat/src/spam.ts diff --git a/ui/chat/src/discussion.ts b/ui/chat/src/discussion.ts index 4b94c8af18..c72f70a4bd 100644 --- a/ui/chat/src/discussion.ts +++ b/ui/chat/src/discussion.ts @@ -1,7 +1,6 @@ import { h, thunk } from 'snabbdom' import { VNode, VNodeData } from 'snabbdom/vnode' import { Ctrl, Line } from './interfaces' -import * as spam from './spam' import enhance from './enhance'; import { presetView } from './preset'; import { lineAction } from './moderation'; @@ -70,8 +69,7 @@ function renderInput(ctrl: Ctrl): VNode | undefined { if (e.which == 10 || e.which == 13) { if (txt === '') $('.keyboard-move input').focus(); else { - spam.report(txt); - if (pub && spam.hasTeamUrl(txt)) alert("Please don't advertise teams in the chat."); + if (pub && hasTeamUrl(txt)) alert("Please don't advertise teams in the chat."); else ctrl.post(txt); el.value = ''; if (!pub) el.classList.remove('whisper'); @@ -85,6 +83,11 @@ function renderInput(ctrl: Ctrl): VNode | undefined { }); } +function hasTeamUrl(txt: string) { + return !!txt.match(teamUrlRegex); +} +const teamUrlRegex = /lichess\.org\/team\// + function sameLines(l1: Line, l2: Line) { return l1.d && l2.d && l1.u === l2.u; } @@ -94,8 +97,7 @@ function selectLines(ctrl: Ctrl): Array { ctrl.data.lines.forEach(line => { if (!line.d && (!prev || !sameLines(prev, line)) && - (!line.r || ctrl.opts.kobold) && - !spam.skip(line.t) + (!line.r || ctrl.opts.kobold) ) ls.push(line); prev = line; }); diff --git a/ui/chat/src/spam.ts b/ui/chat/src/spam.ts deleted file mode 100644 index 6508b2d700..0000000000 --- a/ui/chat/src/spam.ts +++ /dev/null @@ -1,21 +0,0 @@ -export function skip(txt: string) { - return analyse(txt) && window.lichess.storage.get('chat-spam') != '1'; -} -export function hasTeamUrl(txt: string) { - return !!txt.match(teamUrlRegex); -} -export function report(txt: string) { - if (analyse(txt)) window.lichess.storage.set('chat-spam', '1'); -} - -const spamRegex = new RegExp([ - 'chess-bot' -].map(url => { - return url.replace(/\./g, '\\.').replace(/\//g, '\\/'); -}).join('|')); - -function analyse(txt: string) { - return !!txt.match(spamRegex); -} - -const teamUrlRegex = /lichess\.org\/team\//