reduce chat filters
This commit is contained in:
parent
f7b3c562d7
commit
c8f6a16d98
|
@ -1,7 +1,6 @@
|
||||||
import { h, thunk } from 'snabbdom'
|
import { h, thunk } from 'snabbdom'
|
||||||
import { VNode, VNodeData } from 'snabbdom/vnode'
|
import { VNode, VNodeData } from 'snabbdom/vnode'
|
||||||
import { Ctrl, Line } from './interfaces'
|
import { Ctrl, Line } from './interfaces'
|
||||||
import * as spam from './spam'
|
|
||||||
import enhance from './enhance';
|
import enhance from './enhance';
|
||||||
import { presetView } from './preset';
|
import { presetView } from './preset';
|
||||||
import { lineAction } from './moderation';
|
import { lineAction } from './moderation';
|
||||||
|
@ -70,8 +69,7 @@ function renderInput(ctrl: Ctrl): VNode | undefined {
|
||||||
if (e.which == 10 || e.which == 13) {
|
if (e.which == 10 || e.which == 13) {
|
||||||
if (txt === '') $('.keyboard-move input').focus();
|
if (txt === '') $('.keyboard-move input').focus();
|
||||||
else {
|
else {
|
||||||
spam.report(txt);
|
if (pub && hasTeamUrl(txt)) alert("Please don't advertise teams in the chat.");
|
||||||
if (pub && spam.hasTeamUrl(txt)) alert("Please don't advertise teams in the chat.");
|
|
||||||
else ctrl.post(txt);
|
else ctrl.post(txt);
|
||||||
el.value = '';
|
el.value = '';
|
||||||
if (!pub) el.classList.remove('whisper');
|
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) {
|
function sameLines(l1: Line, l2: Line) {
|
||||||
return l1.d && l2.d && l1.u === l2.u;
|
return l1.d && l2.d && l1.u === l2.u;
|
||||||
}
|
}
|
||||||
|
@ -94,8 +97,7 @@ function selectLines(ctrl: Ctrl): Array<Line> {
|
||||||
ctrl.data.lines.forEach(line => {
|
ctrl.data.lines.forEach(line => {
|
||||||
if (!line.d &&
|
if (!line.d &&
|
||||||
(!prev || !sameLines(prev, line)) &&
|
(!prev || !sameLines(prev, line)) &&
|
||||||
(!line.r || ctrl.opts.kobold) &&
|
(!line.r || ctrl.opts.kobold)
|
||||||
!spam.skip(line.t)
|
|
||||||
) ls.push(line);
|
) ls.push(line);
|
||||||
prev = line;
|
prev = line;
|
||||||
});
|
});
|
||||||
|
|
|
@ -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\//
|
|
Loading…
Reference in a new issue