remove ui/chat spam traps

pull/3375/head
Thibault Duplessis 2017-07-29 00:33:49 +02:00
parent ee55e9f275
commit ed2c432f83
2 changed files with 7 additions and 43 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';
@ -72,8 +71,7 @@ function renderInput(ctrl: Ctrl): VNode | undefined {
const kbm = document.querySelector('.keyboard-move input') as HTMLElement;
if (kbm) kbm.focus();
} else {
spam.report(txt);
if (ctrl.opts.public && spam.hasTeamUrl(txt)) alert("Please don't advertise teams in the chat.");
if (ctrl.opts.public && hasTeamUrl(txt)) alert("Please don't advertise teams in the chat.");
else ctrl.post(txt);
el.value = '';
el.classList.remove('whisper');
@ -92,8 +90,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;
});
@ -139,3 +136,8 @@ function renderLine(ctrl: Ctrl, line: Line) {
textNode
] : [userNode, textNode]);
}
const teamUrlRegex = /lichess\.org\/team\//
function hasTeamUrl(txt: string) {
return !!txt.match(teamUrlRegex);
}

View File

@ -1,38 +0,0 @@
export function skip(txt: string) {
return analyse(txt) && isSpammer.get() != '1';
}
export function hasTeamUrl(txt: string) {
return !!txt.match(teamUrlRegex);
}
export function report(txt: string) {
if (analyse(txt)) {
$.post('/jslog/____________?n=spam');
isSpammer.set('1');
}
}
const isSpammer = window.lichess.storage.make('spammer');
const spamRegex = new RegExp([
'xcamweb.com',
'chess-bot',
'coolteenbitch',
'goo.gl/',
'letcafa.webcam',
'tinyurl.com/',
'wooga.info/',
'bit.ly/',
'wbt.link/',
'eb.by/',
'001.rs/',
'shr.name/',
'u.to/',
].map(url => {
return url.replace(/\./g, '\\.').replace(/\//g, '\\/');
}).join('|'));
function analyse(txt: string) {
return !!txt.match(spamRegex);
}
const teamUrlRegex = /lichess\.org\/team\//