Moderation mit AutoMod-Regeln, automatischen Aktionen, eingeschränkten Kanälen, Audit-Log, Befehlsübersicht und Fallliste. Ticket-Transkripte sind über einen geheimen Link lesbar (/transkript/...). Zugänge bekommen einen optionalen Namen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
161 lines
9 KiB
JavaScript
161 lines
9 KiB
JavaScript
/* Seite "Moderation": Reiter, Regeln, automatische Aktionen, eingeschraenkte Kanaele. */
|
||
(function () {
|
||
'use strict';
|
||
|
||
const raw = document.getElementById('mod-data');
|
||
if (!raw) return;
|
||
const { data, channels } = JSON.parse(raw.textContent);
|
||
const form = document.getElementById('mod-form');
|
||
|
||
function el(tag, attrs, ...children) {
|
||
const n = document.createElement(tag);
|
||
for (const [k, v] of Object.entries(attrs || {})) {
|
||
if (k === 'text') n.textContent = v;
|
||
else if (k.startsWith('on')) n.addEventListener(k.slice(2), v);
|
||
else if (v === true) n.setAttribute(k, '');
|
||
else if (v !== false && v != null) n.setAttribute(k, v);
|
||
}
|
||
for (const c of children) if (c != null) n.append(c);
|
||
return n;
|
||
}
|
||
|
||
// --- Reiter
|
||
const tabs = document.querySelectorAll('#mod-tabs a');
|
||
function show(name) {
|
||
if (!document.querySelector('[data-pane="' + name + '"]')) name = 'automod';
|
||
for (const t of tabs) t.classList.toggle('active', t.dataset.tab === name);
|
||
for (const p of document.querySelectorAll('.tab-pane')) p.hidden = p.dataset.pane !== name;
|
||
document.getElementById('mod-tab').value = name;
|
||
}
|
||
for (const t of tabs) t.addEventListener('click', (e) => { e.preventDefault(); show(t.dataset.tab); history.replaceState(null, '', '#' + t.dataset.tab); });
|
||
show(location.hash.slice(1) || 'automod');
|
||
|
||
// --- Schalter und Farben
|
||
const enabled = document.getElementById('mod-enabled');
|
||
const body = document.querySelector('[data-for="mod-enabled"]');
|
||
const upd = () => body.classList.toggle('is-off', !enabled.checked);
|
||
enabled.addEventListener('change', upd);
|
||
upd();
|
||
document.querySelectorAll('.role-dot').forEach((d) => { if (d.dataset.color) d.style.background = d.dataset.color; });
|
||
for (const card of document.querySelectorAll('.rule-card')) {
|
||
const sel = card.querySelector('.rule-action');
|
||
const paint = () => card.classList.toggle('rule-on', sel.value !== 'off');
|
||
sel.addEventListener('change', paint);
|
||
paint();
|
||
card.querySelector('.rule-gear').addEventListener('click', () => {
|
||
const s = card.querySelector('.rule-settings');
|
||
s.hidden = !s.hidden;
|
||
card.classList.toggle('open', !s.hidden);
|
||
});
|
||
}
|
||
|
||
// --- Zeitangaben
|
||
const UNITS = [['60', 'Minuten'], ['3600', 'Stunden'], ['86400', 'Tage']];
|
||
function timeInput(seconds, onChange) {
|
||
let unit = seconds % 86400 === 0 ? 86400 : seconds % 3600 === 0 ? 3600 : 60;
|
||
const num = el('input', { type: 'number', min: '1', max: '999', class: 'input-sm' });
|
||
num.value = Math.max(1, Math.round(seconds / unit));
|
||
const sel = el('select', { class: 'select-sm' });
|
||
for (const [v, l] of UNITS) sel.append(el('option', { value: v, text: l }));
|
||
sel.value = String(unit);
|
||
const fire = () => onChange(Math.max(1, Number(num.value) || 1) * Number(sel.value));
|
||
num.addEventListener('input', fire);
|
||
sel.addEventListener('change', fire);
|
||
return el('span', { class: 'time-input' }, num, sel);
|
||
}
|
||
|
||
// --- Automatische Aktionen
|
||
const PUN = [['timeout', 'temporär stumm schalten'], ['kick', 'kicken'], ['ban', 'bannen'], ['tempban', 'temporär bannen']];
|
||
const pun = (data.punishments || []).map((p) => Object.assign({}, p));
|
||
const punList = document.getElementById('pun-list');
|
||
function paintPun() {
|
||
punList.textContent = '';
|
||
pun.forEach((p, idx) => {
|
||
const action = el('select', {});
|
||
for (const [v, l] of PUN) action.append(el('option', { value: v, text: l }));
|
||
action.value = p.action;
|
||
action.addEventListener('change', () => { p.action = action.value; if (!p.duration) p.duration = 3600; paintPun(); });
|
||
const count = el('input', { type: 'number', min: '1', max: '100', class: 'input-sm' });
|
||
count.value = p.count;
|
||
count.addEventListener('input', () => { p.count = Number(count.value) || 1; });
|
||
const parts = [action];
|
||
if (p.action === 'timeout' || p.action === 'tempban') {
|
||
parts.push(el('span', { class: 'muted', text: 'für' }), timeInput(p.duration || 300, (s) => { p.duration = s; }));
|
||
}
|
||
parts.push(el('span', { class: 'muted', text: 'wenn jemand' }), count, el('span', { class: 'muted', text: 'Verstöße oder mehr in den letzten' }),
|
||
timeInput(p.window || 1800, (s) => { p.window = s; }));
|
||
punList.append(el('div', { class: 'pun-row' },
|
||
el('div', { class: 'pun-main' }, ...parts),
|
||
el('div', { class: 'rr-item-actions' },
|
||
el('button', { type: 'button', class: 'icon-btn', text: '↑', title: 'Nach oben', disabled: idx === 0, onclick: () => { pun.splice(idx - 1, 0, pun.splice(idx, 1)[0]); paintPun(); markDirty(); } }),
|
||
el('button', { type: 'button', class: 'icon-btn danger', text: '✕', title: 'Entfernen', onclick: () => { pun.splice(idx, 1); paintPun(); markDirty(); } }))));
|
||
});
|
||
if (!pun.length) punList.append(el('p', { class: 'muted', text: 'Keine automatischen Aktionen – Verwarnungen werden nur gezählt.' }));
|
||
document.getElementById('pun-add').hidden = pun.length >= 10;
|
||
}
|
||
document.getElementById('pun-add').addEventListener('click', () => { pun.push({ action: 'timeout', duration: 600, count: 3, window: 3600 }); paintPun(); markDirty(); });
|
||
paintPun();
|
||
|
||
// --- Eingeschraenkte Kanaele
|
||
const res = (data.restricted || []).map((r) => Object.assign({}, r));
|
||
const resList = document.getElementById('res-list');
|
||
function paintRes() {
|
||
resList.textContent = '';
|
||
res.forEach((r, idx) => {
|
||
const sel = el('select', {});
|
||
sel.append(el('option', { value: '', text: '– Kanal wählen –' }));
|
||
for (const c of channels) sel.append(el('option', { value: c.id, text: '# ' + c.name }));
|
||
sel.value = r.channel || '';
|
||
sel.addEventListener('change', () => { r.channel = sel.value || null; });
|
||
const toggle = (key, label) => {
|
||
const cb = el('input', { type: 'checkbox' });
|
||
cb.checked = !!r[key];
|
||
cb.addEventListener('change', () => { r[key] = cb.checked; });
|
||
return el('label', { class: 'check' }, cb, ' ' + label);
|
||
};
|
||
resList.append(el('div', { class: 'res-row' }, sel, toggle('commands', 'Befehle'), toggle('images', 'Bilder'), toggle('videos', 'Videos'),
|
||
el('button', { type: 'button', class: 'icon-btn danger', text: '✕', title: 'Entfernen', onclick: () => { res.splice(idx, 1); paintRes(); markDirty(); } })));
|
||
});
|
||
if (!res.length) resList.append(el('p', { class: 'muted', text: 'Noch kein eingeschränkter Kanal.' }));
|
||
}
|
||
document.getElementById('res-add').addEventListener('click', () => { res.push({ channel: null, commands: false, images: true, videos: false }); paintRes(); markDirty(); });
|
||
paintRes();
|
||
|
||
// --- Speichern
|
||
let dirty = false;
|
||
const note = document.getElementById('dirty-note');
|
||
function markDirty() { dirty = true; note.textContent = 'Ungespeicherte Änderungen'; }
|
||
form.addEventListener('input', markDirty);
|
||
form.addEventListener('change', markDirty);
|
||
window.addEventListener('beforeunload', (ev) => { if (dirty) { ev.preventDefault(); ev.returnValue = ''; } });
|
||
|
||
const lines = (t) => t.split(/[\n,]/).map((s) => s.trim()).filter(Boolean);
|
||
form.addEventListener('submit', () => {
|
||
const rules = {};
|
||
for (const card of document.querySelectorAll('.rule-card')) {
|
||
const r = { action: card.querySelector('.rule-action').value, ignore_channels: Array.from(card.querySelectorAll('.ignore-ch:checked')).map((i) => i.value) };
|
||
for (const inp of card.querySelectorAll('[data-opt]')) {
|
||
const key = inp.dataset.opt;
|
||
r[key] = inp.tagName === 'TEXTAREA' ? lines(inp.value) : Number(inp.value);
|
||
}
|
||
rules[card.dataset.rule] = r;
|
||
}
|
||
const audit = { channel: form.elements.audit_channel.value || null };
|
||
for (const cb of document.querySelectorAll('#audit-events input')) audit[cb.dataset.event] = cb.checked;
|
||
document.getElementById('mod-payload').value = JSON.stringify({
|
||
enabled: enabled.checked,
|
||
ignore_bots: document.getElementById('mod-ignore-bots').checked,
|
||
exempt_mods: document.getElementById('mod-exempt-mods').checked,
|
||
warn_dm: document.getElementById('mod-warn-dm').checked,
|
||
exempt_roles: Array.from(document.querySelectorAll('#mod-exempt-roles input:checked')).map((i) => i.value),
|
||
log_channel: form.elements.mod_log.value || null,
|
||
rules,
|
||
punishments: pun,
|
||
restricted: res.filter((r) => r.channel),
|
||
restricted_dm: document.getElementById('res-dm').checked,
|
||
restricted_reply: document.getElementById('res-reply').checked,
|
||
audit,
|
||
});
|
||
dirty = false;
|
||
});
|
||
})();
|