reduce chat filters

pull/4302/head
Thibault Duplessis 2018-04-23 15:24:26 +02:00
parent f7b3c562d7
commit c8f6a16d98
2 changed files with 7 additions and 26 deletions

View File

@ -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<Line> {
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;
});

View File

@ -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\//