diff --git a/dDashboardServer/static/js/chat-filter.js b/dDashboardServer/static/js/chat-filter.js index b85226f2c..5852fb287 100644 --- a/dDashboardServer/static/js/chat-filter.js +++ b/dDashboardServer/static/js/chat-filter.js @@ -8,6 +8,9 @@ var page = document.getElementById('chatFilterPage'); var canChat = !!page.dataset.canChat; var PAGE = 50; + function isPhrase(word) { return String(word).indexOf(' ') !== -1; } + function phraseBadge(word) { return isPhrase(word) ? ' ' + fmt.badge('Phrase', 'secondary') : ''; } + var REASONS = { blocked_here: 'Blocked on the staff list', allowed_here: 'Allowed on the staff list', @@ -26,7 +29,8 @@ function wordAction(w) { if (!w.word) return ''; - if (w.reason === 'blocked_here' || w.reason === 'allowed_here') return ''; + if (w.reason === 'blocked_here' || w.reason === 'allowed_here') return ''; + if (w.phrase) return ''; if (w.reason === 'not_allowed') return ''; return ''; } @@ -48,7 +52,7 @@ }).join(''); document.getElementById('testRows').innerHTML = d.words.map(function (w) { return '' + esc(w.word || '(empty: two spaces in a row)') + '' + (w.stopped ? fmt.badge('Stopped', 'danger') : fmt.badge('OK', 'success')) + '' + - '' + esc(REASONS[w.reason] || w.reason) + '' + wordAction(w) + ''; + '' + esc(REASONS[w.reason] || w.reason) + (w.phrase ? ' (the phrase ' + esc(w.phrase) + ')' : '') + '' + wordAction(w) + ''; }).join(''); document.getElementById('testResult').classList.remove('d-none'); }).catch(function () {}); @@ -83,10 +87,10 @@ var shown = rows.slice(listStart, listStart + PAGE); document.getElementById('listRows').innerHTML = shown.map(function (w) { var other = w.allowed ? 'blocked' : 'allowed'; - return '' + esc(w.word) + '' + (w.allowed ? fmt.badge('Allowed', 'success') : fmt.badge('Blocked', 'danger')) + '' + + return '' + esc(w.word) + phraseBadge(w.word) + '' + (w.allowed ? fmt.badge('Allowed', 'success') : fmt.badge('Blocked', 'danger')) + '' + '' + esc(w.added_by) + '' + esc(fmt.unix(w.added_at)) + '' + ' ' + - ' ' + + (isPhrase(w.word) && !w.allowed ? '' : ' ') + ''; }).join('') || '' + (words.length ? 'No words match.' : 'No words added yet.') + ''; document.getElementById('listRange').textContent = rows.length ? (listStart + 1) + '–' + (listStart + shown.length) + ' of ' + rows.length : ''; @@ -114,8 +118,9 @@ addForm.addEventListener('click', function (e) { var b = e.target.closest('button[data-list]'); if (b) addList = b.dataset.list; }); addForm.addEventListener('submit', function (e) { e.preventDefault(); - var word = addWord.value.trim(); + var word = addWord.value.trim().replace(/\s+/g, ' '); if (!word) return; + if (addList === 'allowed' && isPhrase(word)) { toast('Phrases can only be blocked: normal chat checks each word on its own, so allow the words instead', 'warning'); return; } confirmAdd(word, addList === 'allowed').then(function (done) { if (done) addWord.value = ''; }); }); @@ -129,7 +134,7 @@ var parts = [d.inAllowFile ? 'in chatplus_en_us.txt' : 'not in chatplus_en_us.txt']; if (d.inBlockFile) parts.push('in blocklist.dcf'); parts.push(d.dashboard ? (d.dashboard === 'blocked' ? 'on the Blocked list' : 'on the Allowed list') : 'on neither staff list'); - return '' + esc(d.word) + ' now: ' + esc(parts.join(', ')) + '.'; + return '' + esc(d.word) + '' + phraseBadge(d.word) + ' now: ' + esc(parts.join(', ')) + '.'; } function openConfirm(options) { @@ -186,7 +191,8 @@ function confirmAdd(word, allowed) { var p = openConfirm({ title: (allowed ? 'Allow "' : 'Block "') + word + '"?', - text: allowed ? 'Players may use it in normal chat. Running worlds apply it at once.' : 'It is stopped in all chat, even where a word file allows it. Running worlds apply it at once.', + text: allowed ? 'Players may use it in normal chat. Running worlds apply it at once.' + : (isPhrase(word) ? 'The phrase is stopped in all chat when its words come in a row. Running worlds apply it at once.' : 'It is stopped in all chat, even where a word file allows it. Running worlds apply it at once.'), tone: allowed ? 'success' : 'danger', button: allowed ? 'Allow' : 'Block', run: function () { return api.action('/api/chat_filter/words', { word: word, allowed: allowed }).then(function (d) { toast(d.message, 'success'); }); } @@ -228,8 +234,11 @@ ? esc(d.allowTotal) + ' words normal chat may use (from the client); ' + esc(d.onDashboard) + ' are on a staff list too, which wins.' : 'could not be read. Set client_location.') + '' + '
  • ' + esc(d.blockFile) + ': ' + (d.blockFileFound - ? esc(d.blockTotal) + ' words best friends\' free chat may not use. Stored as hashes, so they can\'t be listed; test a word to see if it is one.' - : 'not found next to the servers, so best friends\' free chat stops everything.') + '
  • '; + ? esc(d.blockTotal) + ' words' + (d.blockMaxWords > 1 ? ' and phrases (up to ' + esc(d.blockMaxWords) + ' words)' : '') + ' best friends\' free chat may not use. Stored as hashes, so they can\'t be listed; test a word or phrase to see if it is one.' + : d.blockFileOld + ? 'in the old format (its hashes depended on the platform), so the servers can\'t read it and best friends\' free chat stops everything.' + : 'not found next to the servers (' + esc(d.blockFileStatus) + '), so best friends\' free chat stops everything.') + + ' To change it, put the words in ' + esc(d.blockText) + ' next to the servers (one word or phrase per line) and start the servers again; they build ' + esc(d.blockFile) + ' from it.'; document.getElementById('fileWords').innerHTML = d.words.map(function (w) { var cls = w.dashboard === 'blocked' ? 'text-bg-danger' : w.dashboard === 'allowed' ? 'text-bg-success' : 'text-bg-secondary'; return ''; diff --git a/dDashboardServer/templates/chat_filter.jinja2 b/dDashboardServer/templates/chat_filter.jinja2 index c281b27ea..7caae932d 100644 --- a/dDashboardServer/templates/chat_filter.jinja2 +++ b/dDashboardServer/templates/chat_filter.jinja2 @@ -54,12 +54,12 @@
    -
    Blocked
    Stopped in all chat, even if a word file allows it.
    -
    Allowed
    Usable in normal chat, like the words in chatplus_en_us.txt.
    +
    Blocked
    Stopped in all chat, even if a word file allows it. A phrase (several words) is stopped when its words come in a row, whatever the spaces and punctuation between them.
    +
    Allowed
    Usable in normal chat, like the words in chatplus_en_us.txt. Single words only: normal chat checks each word on its own, as the client does.
    -
    -
    +
    +
    @@ -74,7 +74,7 @@
    - +
    WordListAdded byAdded
    Word or phraseListAdded byAdded