Moderation, Transkript-Links und Namen bei Zugängen
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>
This commit is contained in:
parent
32e9bb3612
commit
a3b85dfa80
8 changed files with 545 additions and 10 deletions
102
app.py
102
app.py
|
|
@ -333,9 +333,10 @@ async def access_add(request: Request):
|
|||
except siel.SielError as exc:
|
||||
flash(request, str(exc), "error")
|
||||
return RedirectResponse("/zugaenge", status_code=303)
|
||||
panel_db.add_user(discord_id, name, areas, user["id"])
|
||||
label = str(form.get("label", "")).strip()[:60]
|
||||
panel_db.add_user(discord_id, name, areas, user["id"], label)
|
||||
panel_db.log(user["id"], user["name"], "Zugang angelegt",
|
||||
f"{name} ({discord_id}): " + (", ".join(config.AREAS[a] for a in areas) or "keine Bereiche"))
|
||||
f"{label + ' / ' if label else ''}{name} ({discord_id}): " + (", ".join(config.AREAS[a] for a in areas) or "keine Bereiche"))
|
||||
flash(request, f"{name} hat jetzt Zugang.")
|
||||
return RedirectResponse("/zugaenge", status_code=303)
|
||||
|
||||
|
|
@ -350,6 +351,8 @@ async def access_areas(request: Request, discord_id: str):
|
|||
raise HTTPException(status_code=404, detail="Diesen Zugang gibt es nicht.")
|
||||
areas = [a for a in form.getlist("areas") if a in config.AREAS]
|
||||
panel_db.set_areas(discord_id, areas)
|
||||
if "label" in form:
|
||||
panel_db.set_label(discord_id, str(form.get("label", "")).strip()[:60])
|
||||
panel_db.log(user["id"], user["name"], "Rechte geändert",
|
||||
f"{target['name']}: " + (", ".join(config.AREAS[a] for a in areas) or "keine Bereiche"))
|
||||
flash(request, f"Rechte von {target['name']} gespeichert.")
|
||||
|
|
@ -720,6 +723,23 @@ async def tk_transcript(request: Request, filename: str):
|
|||
})
|
||||
|
||||
|
||||
@app.get("/transkript/{token}")
|
||||
async def transcript_public(token: str):
|
||||
"""Transkript ueber den Link aus Discord - ohne Login, der lange geheime Schluessel ist der Zugang."""
|
||||
if not 20 <= len(token) <= 64 or not all(c.isalnum() or c in "-_" for c in token):
|
||||
raise HTTPException(status_code=404, detail="Dieses Transkript gibt es nicht (mehr).")
|
||||
try:
|
||||
body, _ = await siel.raw("GET", f"/api/tickets/transcript-link/{token}")
|
||||
except siel.SielError:
|
||||
raise HTTPException(status_code=404, detail="Dieses Transkript gibt es nicht (mehr).")
|
||||
return Response(body, media_type="text/html; charset=utf-8", headers={
|
||||
"Content-Security-Policy": "default-src 'none'; img-src https: data:; style-src 'unsafe-inline'; "
|
||||
"sandbox allow-popups allow-popups-to-escape-sandbox; frame-ancestors 'none'",
|
||||
"X-Robots-Tag": "noindex, nofollow",
|
||||
"Cache-Control": "no-store",
|
||||
})
|
||||
|
||||
|
||||
@app.get("/tickets/{panel_id}", response_class=HTMLResponse)
|
||||
async def tk_edit(request: Request, panel_id: str):
|
||||
user = current_user(request)
|
||||
|
|
@ -841,6 +861,84 @@ async def tk_retention(request: Request):
|
|||
return RedirectResponse("/tickets#transkripte", status_code=303)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Moderation
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@app.get("/moderation", response_class=HTMLResponse)
|
||||
async def mod_page(request: Request):
|
||||
user = current_user(request)
|
||||
require_area(user, "moderation")
|
||||
try:
|
||||
data = await siel.get_module("moderation")
|
||||
meta = await siel._request("GET", "/api/moderation/meta")
|
||||
guild = await siel.guild()
|
||||
error = None
|
||||
except siel.SielError as exc:
|
||||
data, meta, guild, error = None, None, None, str(exc)
|
||||
draft = DRAFTS.pop((user["id"], "moderation"), None)
|
||||
if data is not None and draft is not None:
|
||||
data = draft
|
||||
return render(request, "moderation.html", user, data=data, meta=meta, guild=guild, error=error)
|
||||
|
||||
|
||||
@app.post("/moderation")
|
||||
async def mod_save(request: Request):
|
||||
user = current_user(request)
|
||||
require_area(user, "moderation")
|
||||
form = await form_with_csrf(request)
|
||||
try:
|
||||
payload = json.loads(str(form.get("payload", "")))
|
||||
if not isinstance(payload, dict):
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
flash(request, "Die Einstellungen kamen nicht richtig an. Bitte lade die Seite neu.", "error")
|
||||
return RedirectResponse("/moderation", status_code=303)
|
||||
try:
|
||||
saved = await siel.put_module("moderation", payload, user["name"])
|
||||
active = [k for k, r in saved["rules"].items() if r["action"] != "off"]
|
||||
panel_db.log(user["id"], user["name"], "Moderation gespeichert",
|
||||
("AutoMod an" if saved["enabled"] else "AutoMod aus") + f", {len(active)} Regeln aktiv")
|
||||
flash(request, "Gespeichert.")
|
||||
except siel.SielError as exc:
|
||||
DRAFTS[(user["id"], "moderation")] = payload
|
||||
flash(request, str(exc), "error")
|
||||
tab = str(form.get("tab") or "")
|
||||
return RedirectResponse("/moderation" + (f"#{tab}" if tab.isalpha() else ""), status_code=303)
|
||||
|
||||
|
||||
@app.get("/moderation/faelle", response_class=HTMLResponse)
|
||||
async def mod_cases(request: Request, nutzer: str = ""):
|
||||
user = current_user(request)
|
||||
require_area(user, "moderation")
|
||||
nutzer = nutzer.strip()
|
||||
try:
|
||||
path = "/api/moderation/cases" + (f"?user_id={nutzer}" if nutzer.isdigit() else "")
|
||||
cases = (await siel._request("GET", path))["cases"]
|
||||
meta = await siel._request("GET", "/api/moderation/meta")
|
||||
error = None
|
||||
except siel.SielError as exc:
|
||||
cases, meta, error = [], {"case_labels": {}, "rules": {}}, str(exc)
|
||||
return render(request, "mod_cases.html", user, cases=cases, meta=meta, error=error, nutzer=nutzer)
|
||||
|
||||
|
||||
@app.post("/moderation/faelle/{case_id}/aufheben")
|
||||
async def mod_case_revoke(request: Request, case_id: int):
|
||||
user = current_user(request)
|
||||
require_area(user, "moderation")
|
||||
await form_with_csrf(request)
|
||||
try:
|
||||
await siel.delete(f"/api/moderation/cases/{case_id}")
|
||||
panel_db.log(user["id"], user["name"], "Moderationsfall aufgehoben", f"#{case_id}")
|
||||
flash(request, f"Fall #{case_id} zählt nicht mehr als Verstoß.")
|
||||
except siel.SielError as exc:
|
||||
flash(request, str(exc), "error")
|
||||
back = request.headers.get("referer") or ""
|
||||
if not back.startswith(config.PANEL_URL + "/moderation/faelle"):
|
||||
back = "/moderation/faelle"
|
||||
return RedirectResponse(back, status_code=303)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
|
|
|
|||
18
panel_db.py
18
panel_db.py
|
|
@ -48,6 +48,10 @@ def init_db() -> None:
|
|||
)"""
|
||||
)
|
||||
c.execute("CREATE INDEX IF NOT EXISTS audit_at ON audit_log(at)")
|
||||
cols = [r[1] for r in c.execute("PRAGMA table_info(panel_users)").fetchall()]
|
||||
if "label" not in cols:
|
||||
# Freie Notiz, wem die ID gehoert (z. B. Spielname)
|
||||
c.execute("ALTER TABLE panel_users ADD COLUMN label TEXT")
|
||||
|
||||
|
||||
def _user(row: sqlite3.Row | None) -> dict | None:
|
||||
|
|
@ -68,18 +72,24 @@ def get_user(discord_id: str) -> dict | None:
|
|||
|
||||
def list_users() -> list[dict]:
|
||||
with conn() as c:
|
||||
rows = c.execute("SELECT * FROM panel_users ORDER BY name COLLATE NOCASE").fetchall()
|
||||
rows = c.execute("SELECT * FROM panel_users ORDER BY COALESCE(label, name) COLLATE NOCASE").fetchall()
|
||||
return [_user(r) for r in rows]
|
||||
|
||||
|
||||
def add_user(discord_id: str, name: str, areas: list[str], added_by: str) -> None:
|
||||
def add_user(discord_id: str, name: str, areas: list[str], added_by: str, label: str | None = None) -> None:
|
||||
with conn() as c:
|
||||
c.execute(
|
||||
"INSERT OR IGNORE INTO panel_users (discord_id, name, areas, added_by, added_at) VALUES (?, ?, ?, ?, ?)",
|
||||
(discord_id, name, json.dumps(areas), added_by, int(time.time())),
|
||||
"INSERT OR IGNORE INTO panel_users (discord_id, name, areas, added_by, added_at, label) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?)",
|
||||
(discord_id, name, json.dumps(areas), added_by, int(time.time()), label or None),
|
||||
)
|
||||
|
||||
|
||||
def set_label(discord_id: str, label: str | None) -> None:
|
||||
with conn() as c:
|
||||
c.execute("UPDATE panel_users SET label = ? WHERE discord_id = ?", (label or None, discord_id))
|
||||
|
||||
|
||||
def set_areas(discord_id: str, areas: list[str]) -> None:
|
||||
with conn() as c:
|
||||
c.execute("UPDATE panel_users SET areas = ? WHERE discord_id = ?", (json.dumps(areas), discord_id))
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ input, select, textarea, button { font: inherit; }
|
|||
.brand img { display: block; width: 100%; max-width: 210px; margin: 0 auto; }
|
||||
.brand-sub { text-align: center; color: var(--text-muted); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; margin: 0.35rem 0 1.25rem; }
|
||||
|
||||
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
|
||||
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
|
||||
.nav-heading { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); margin: 1.1rem 0.6rem 0.35rem; }
|
||||
.nav-link { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0.7rem; border-radius: 6px; color: var(--text); }
|
||||
.nav-link:hover { background: var(--bg-panel-alt); color: var(--text); text-decoration: none; }
|
||||
|
|
@ -352,3 +352,39 @@ input[type=number]:focus { outline: none; border-color: var(--gold); }
|
|||
@media (max-width: 860px) {
|
||||
.tk-type-row { grid-template-columns: minmax(0, 1fr); }
|
||||
}
|
||||
|
||||
/* ---------- Moderation ---------- */
|
||||
.tabs { display: flex; flex-direction: row; flex: none; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
|
||||
.tabs a { padding: 0.55rem 0.9rem; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
|
||||
.tabs a:hover { color: var(--text); text-decoration: none; }
|
||||
.tabs a.active { color: var(--gold); border-bottom-color: var(--gold); }
|
||||
.rule-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.75rem; margin-top: 0.75rem; align-items: start; }
|
||||
.rule-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.65rem 0.75rem; }
|
||||
.rule-card.rule-on { border-color: rgba(47, 191, 90, 0.45); }
|
||||
.rule-card.open { grid-column: 1 / -1; }
|
||||
.rule-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.45rem; font-size: 0.9rem; color: var(--text-muted); }
|
||||
.rule-card.rule-on .rule-head span { color: var(--text); }
|
||||
.rule-head .icon-btn { min-height: 28px; padding: 0 0.45rem; }
|
||||
.rule-settings { margin-top: 0.6rem; border-top: 1px solid var(--border); padding-top: 0.3rem; }
|
||||
.rule-settings .field { max-width: none; }
|
||||
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.2rem 0.75rem; max-height: 180px; overflow-y: auto; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 6px; padding: 0.45rem 0.6rem; }
|
||||
.pun-list, .res-list { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.75rem 0; }
|
||||
.pun-row { display: flex; gap: 0.6rem; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.55rem 0.7rem; }
|
||||
.pun-main { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem 0.6rem; flex: 1; }
|
||||
.pun-main select { width: auto; }
|
||||
.time-input { display: inline-flex; gap: 0.3rem; }
|
||||
.select-sm { width: auto !important; padding: 0.45rem 0.5rem !important; }
|
||||
.res-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto auto; gap: 0.9rem; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.7rem; }
|
||||
.audit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.4rem 1rem; margin-top: 0.5rem; }
|
||||
.mt { margin-top: 1.25rem; }
|
||||
.input-id { width: 13rem; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.45rem 0.6rem; }
|
||||
.row-off td { opacity: 0.5; }
|
||||
.tag-case-warn, .tag-case-automod { background: rgba(230, 126, 34, 0.15); color: #f0a35a; border-color: rgba(230, 126, 34, 0.4); }
|
||||
.tag-case-timeout { background: rgba(52, 152, 219, 0.15); color: #7cc0ef; border-color: rgba(52, 152, 219, 0.4); }
|
||||
.tag-case-kick, .tag-case-ban, .tag-case-tempban { background: rgba(217, 83, 79, 0.15); color: #ef8a87; border-color: rgba(217, 83, 79, 0.45); }
|
||||
.tag-case-unban, .tag-case-untimeout { background: rgba(47, 191, 90, 0.14); color: #6fdc8c; border-color: rgba(47, 191, 90, 0.4); }
|
||||
@media (max-width: 860px) {
|
||||
.res-row { grid-template-columns: minmax(0, 1fr) auto; }
|
||||
.pun-row { align-items: flex-start; }
|
||||
}
|
||||
.input-label { width: 11rem; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.35rem 0.55rem; }
|
||||
|
|
|
|||
161
static/js/moderation.js
Normal file
161
static/js/moderation.js
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
/* 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;
|
||||
});
|
||||
})();
|
||||
|
|
@ -23,12 +23,13 @@
|
|||
<td>
|
||||
<div class="person">
|
||||
{% if u.avatar %}<img src="{{ u.avatar }}" alt="" class="avatar avatar-sm">{% endif %}
|
||||
<div>{{ u.name or "?" }}<div class="muted small">{{ u.discord_id }}</div></div>
|
||||
<div>{% if u.label %}<strong>{{ u.label }}</strong> <span class="muted">· {{ u.name or "?" }}</span>{% else %}{{ u.name or "?" }}{% endif %}<div class="muted small">{{ u.discord_id }}</div></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<form method="post" action="/zugaenge/{{ u.discord_id }}/rechte" class="areas-form">
|
||||
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||
<input type="text" name="label" value="{{ u.label or '' }}" maxlength="60" placeholder="Name (optional)" class="input-label">
|
||||
{% for key, label in areas.items() %}
|
||||
<label class="check"><input type="checkbox" name="areas" value="{{ key }}"{% if key in u.areas %} checked{% endif %}> {{ label }}</label>
|
||||
{% endfor %}
|
||||
|
|
@ -60,6 +61,10 @@
|
|||
<input type="text" name="discord_id" inputmode="numeric" pattern="[0-9]{15,20}" required placeholder="z. B. 688312663247290389">
|
||||
<small class="muted">In Discord: Rechtsklick auf die Person → „Nutzer-ID kopieren“ (Entwicklermodus muss an sein).</small>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Name (optional) – damit ihr wisst, wem die ID gehört, z. B. der Spielname</span>
|
||||
<input type="text" name="label" maxlength="60" placeholder="z. B. Damaskar">
|
||||
</label>
|
||||
<div class="field">
|
||||
<span>Bereiche</span>
|
||||
<div class="checks">
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<title>{% block title %}Siel{% endblock %} · Elyos Allianz</title>
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/static/img/favicon-32.png">
|
||||
<link rel="apple-touch-icon" href="/static/img/favicon-180.png">
|
||||
<link rel="stylesheet" href="/static/css/panel.css?v=6">
|
||||
<link rel="stylesheet" href="/static/css/panel.css?v=9">
|
||||
</head>
|
||||
<body>
|
||||
{% if user %}
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
{% endif %}
|
||||
{% endfor %}
|
||||
<div class="nav-heading">Funktionen</div>
|
||||
{% for area, label, href in [("welcome", "Begrüßung", "/begruessung"), ("reactionroles", "Reaktionsrollen", "/reaktionsrollen"), ("moderation", "Moderation", None), ("tickets", "Tickets", "/tickets"), ("alliance", "Allianz", None)] %}
|
||||
{% for area, label, href in [("welcome", "Begrüßung", "/begruessung"), ("reactionroles", "Reaktionsrollen", "/reaktionsrollen"), ("moderation", "Moderation", "/moderation"), ("tickets", "Tickets", "/tickets"), ("alliance", "Allianz", None)] %}
|
||||
{% if area in user.areas %}
|
||||
{% if href %}
|
||||
<a href="{{ href }}" class="nav-link{% if path == href or path.startswith(href ~ "/") %} active{% endif %}">{{ label }}</a>
|
||||
|
|
|
|||
51
templates/mod_cases.html
Normal file
51
templates/mod_cases.html
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Fälle{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<a href="/moderation" class="back-link">← Moderation</a>
|
||||
<h1>Verwarnungen und Fälle</h1>
|
||||
<p class="muted">Alles, was Moderatoren und AutoMod getan haben. „Aufheben“ nimmt eine Verwarnung aus der Zählung für die automatischen Aktionen.</p>
|
||||
</div>
|
||||
{% if error %}<div class="flash flash-error">{{ error }}</div>{% endif %}
|
||||
|
||||
<form method="get" action="/moderation/faelle" class="panel inline-form">
|
||||
<label class="small muted">Nur eine Person (Discord-ID)
|
||||
<input type="text" name="nutzer" value="{{ nutzer }}" inputmode="numeric" pattern="[0-9]*" class="input-id">
|
||||
</label>
|
||||
<button type="submit" class="btn btn-sm btn-secondary">Filtern</button>
|
||||
{% if nutzer %}<a href="/moderation/faelle" class="small">Alle zeigen</a>{% endif %}
|
||||
</form>
|
||||
|
||||
<section class="panel">
|
||||
{% if cases %}
|
||||
<div class="table-wrap">
|
||||
<table class="table">
|
||||
<thead><tr><th>#</th><th>Art</th><th>Mitglied</th><th>Von</th><th>Grund</th><th>Wann</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{% for c in cases %}
|
||||
<tr class="{{ '' if c.active else 'row-off' }}">
|
||||
<td>{{ c.id }}</td>
|
||||
<td><span class="tag tag-case-{{ c.type }}">{{ meta.case_labels.get(c.type, c.type) }}</span></td>
|
||||
<td><a href="/moderation/faelle?nutzer={{ c.user_id }}">{{ c.user_name }}</a><div class="muted small">{{ c.user_id }}</div></td>
|
||||
<td>{{ c.mod_name or "AutoMod" }}</td>
|
||||
<td class="small">{{ c.reason or "" }}
|
||||
{% if c.expires_at and c.type in ("timeout", "tempban") %}<div class="muted">bis {{ c.expires_at | datetime }}</div>{% endif %}</td>
|
||||
<td class="small nowrap">{{ c.created_at | datetime }}</td>
|
||||
<td>
|
||||
{% if c.active and c.type in ("warn", "automod") %}
|
||||
<form method="post" action="/moderation/faelle/{{ c.id }}/aufheben">
|
||||
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||
<button type="submit" class="btn btn-sm btn-secondary">Aufheben</button>
|
||||
</form>
|
||||
{% elif not c.active %}<span class="muted small">aufgehoben</span>{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="muted">Keine Einträge.</p>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
174
templates/moderation.html
Normal file
174
templates/moderation.html
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
{% extends "base.html" %}
|
||||
{% from "macros.html" import channel_select, switch %}
|
||||
{% block title %}Moderation{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>Moderation</h1>
|
||||
<p class="muted">Schütze den Server der Elyos Allianz mit automatischer Moderation und gib deinen Moderatoren Werkzeuge an die Hand.
|
||||
<a href="/moderation/faelle">Alle Verwarnungen und Fälle →</a></p>
|
||||
</div>
|
||||
{% if error %}
|
||||
<div class="flash flash-error">{{ error }}</div>
|
||||
{% else %}
|
||||
{% set text_channels = guild.channels | selectattr("type", "in", ["text", "news", "forum"]) | list %}
|
||||
<script type="application/json" id="mod-data">{{ {"data": data, "channels": text_channels} | tojson }}</script>
|
||||
|
||||
<nav class="tabs" id="mod-tabs">
|
||||
<a href="#automod" data-tab="automod">AutoMod</a>
|
||||
<a href="#aktionen" data-tab="aktionen">Automatische Aktionen</a>
|
||||
<a href="#kanaele" data-tab="kanaele">Eingeschränkte Kanäle</a>
|
||||
<a href="#audit" data-tab="audit">Audit-Log</a>
|
||||
<a href="#befehle" data-tab="befehle">Befehle</a>
|
||||
</nav>
|
||||
|
||||
<form method="post" action="/moderation" id="mod-form">
|
||||
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||
<input type="hidden" name="payload" id="mod-payload">
|
||||
<input type="hidden" name="tab" id="mod-tab">
|
||||
|
||||
{# ------------------------------------------------------------ AutoMod #}
|
||||
<div class="tab-pane" data-pane="automod">
|
||||
<section class="panel">
|
||||
<div class="panel-head">
|
||||
<div>
|
||||
<h2>AutoMod</h2>
|
||||
<p class="muted small">Siel prüft jede Nachricht gegen die Regeln unten. Für jede Regel legst du fest, was passiert – ein Klick auf ⚙ öffnet ihre Einstellungen.</p>
|
||||
</div>
|
||||
{{ switch("mod-enabled", data.enabled) }}
|
||||
</div>
|
||||
<div class="panel-body" data-for="mod-enabled">
|
||||
<div class="rule-grid">
|
||||
{% for key, label in meta.rules.items() %}
|
||||
{% set r = data.rules[key] %}
|
||||
<div class="rule-card" data-rule="{{ key }}">
|
||||
<div class="rule-head">
|
||||
<span>{{ label }}</span>
|
||||
<button type="button" class="icon-btn rule-gear" title="Einstellungen">⚙</button>
|
||||
</div>
|
||||
<select class="rule-action">
|
||||
{% for a, al in meta.actions.items() %}<option value="{{ a }}"{% if r.action == a %} selected{% endif %}>{{ al }}</option>{% endfor %}
|
||||
</select>
|
||||
<div class="rule-settings" hidden>
|
||||
{% if key == "badwords" %}
|
||||
<label class="field"><span>Wörter – eins pro Zeile. Ganze Wörter; mit Leerzeichen wird die Wortgruppe überall gefunden.</span>
|
||||
<textarea rows="6" data-opt="words">{{ r.words | join("\n") }}</textarea></label>
|
||||
{% elif key == "links" %}
|
||||
<label class="field"><span>Erlaubte Seiten – eine pro Zeile (Unterseiten zählen mit). Discord selbst ist immer erlaubt.</span>
|
||||
<textarea rows="6" data-opt="allowed">{{ r.allowed | join("\n") }}</textarea></label>
|
||||
{% elif key in ("repeated", "spam") %}
|
||||
<div class="field-row">
|
||||
<label class="field"><span>{{ "Gleiche Nachricht" if key == "repeated" else "Nachrichten" }} (Anzahl)</span><input type="number" min="2" max="50" data-opt="count" value="{{ r.count }}"></label>
|
||||
<label class="field"><span>innerhalb von (Sekunden)</span><input type="number" min="1" max="3600" data-opt="seconds" value="{{ r.seconds }}"></label>
|
||||
</div>
|
||||
{% elif key == "caps" %}
|
||||
<div class="field-row">
|
||||
<label class="field"><span>Ab Anteil Großbuchstaben (%)</span><input type="number" min="30" max="100" data-opt="percent" value="{{ r.percent }}"></label>
|
||||
<label class="field"><span>Nur Nachrichten ab (Buchstaben)</span><input type="number" min="3" max="200" data-opt="min_length" value="{{ r.min_length }}"></label>
|
||||
</div>
|
||||
{% elif key in ("emojis", "spoilers", "mentions") %}
|
||||
<label class="field"><span>Mehr als … pro Nachricht</span><input type="number" min="1" max="100" data-opt="max" value="{{ r.max }}"></label>
|
||||
{% elif key == "invites" %}
|
||||
<p class="muted small">Einladungen zum eigenen Server bleiben erlaubt.</p>
|
||||
{% elif key == "zalgo" %}
|
||||
<p class="muted small">Text mit übereinander gestapelten Zeichen (Z̷̢a̶l̸g̵o̴).</p>
|
||||
{% endif %}
|
||||
<div class="field"><span>In diesen Kanälen nicht prüfen</span>
|
||||
<div class="check-list">
|
||||
{% for ch in text_channels %}
|
||||
<label class="check"><input type="checkbox" class="ignore-ch" value="{{ ch.id }}"{% if ch.id in r.ignore_channels %} checked{% endif %}> #{{ ch.name }}</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2>Ausnahmen und Meldungen</h2>
|
||||
<label class="check"><input type="checkbox" id="mod-ignore-bots"{% if data.ignore_bots %} checked{% endif %}> AutoMod ignoriert andere Bots</label><br>
|
||||
<label class="check"><input type="checkbox" id="mod-exempt-mods"{% if data.exempt_mods %} checked{% endif %}> Moderatoren (Recht „Nachrichten verwalten“) sind ausgenommen</label><br>
|
||||
<label class="check"><input type="checkbox" id="mod-warn-dm"{% if data.warn_dm %} checked{% endif %}> Verwarnte bekommen zusätzlich eine private Nachricht</label>
|
||||
<div class="field"><span>Diese Rollen sind vom AutoMod ausgenommen</span>
|
||||
<div class="role-list" id="mod-exempt-roles">
|
||||
{% for r in guild.roles if not r.managed %}
|
||||
<label class="role-item"><input type="checkbox" value="{{ r.id }}"{% if r.id in data.exempt_roles %} checked{% endif %}><span class="role-dot" data-color="{{ r.color or '' }}"></span>{{ r.name }}</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<label class="field"><span>Mod-Log – hier meldet Siel Verwarnungen, Timeouts, Kicks und Banns</span>
|
||||
{{ channel_select("mod_log", guild.channels, data.log_channel, empty="– kein Mod-Log –") }}
|
||||
</label>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{# ------------------------------------------------------------ Aktionen #}
|
||||
<div class="tab-pane" data-pane="aktionen" hidden>
|
||||
<section class="panel">
|
||||
<h2>Automatische Aktionen</h2>
|
||||
<p class="muted small">Jede Verwarnung – durch AutoMod oder <code>/warn</code> – zählt als Verstoß. Erreicht jemand eine Schwelle, führt Siel die schärfste passende Aktion aus. Aufgehobene Fälle zählen nicht mehr.</p>
|
||||
<div id="pun-list" class="pun-list"></div>
|
||||
<button type="button" class="btn btn-sm btn-ghost" id="pun-add">+ Automatische Aktion hinzufügen</button>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{# ------------------------------------------------------------ Kanaele #}
|
||||
<div class="tab-pane" data-pane="kanaele" hidden>
|
||||
<section class="panel">
|
||||
<h2>Eingeschränkte Kanäle</h2>
|
||||
<p class="muted small">Kanäle, in denen nur Bilder, nur Videos oder nur Befehle erlaubt sind. Siel löscht alles andere – auch wenn AutoMod aus ist. Moderatoren sind ausgenommen.</p>
|
||||
<div id="res-list" class="res-list"></div>
|
||||
<button type="button" class="btn btn-sm btn-ghost" id="res-add">+ Kanal hinzufügen</button>
|
||||
<h3 class="mt">Zusätzliche Einstellungen</h3>
|
||||
<label class="check"><input type="checkbox" id="res-dm"{% if data.restricted_dm %} checked{% endif %}> Dem Autor eine Nachricht über die Löschung schicken</label><br>
|
||||
<label class="check"><input type="checkbox" id="res-reply"{% if data.restricted_reply %} checked{% endif %}> Kurzer Hinweis im Kanal beim Löschen</label>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{# ------------------------------------------------------------ Audit #}
|
||||
<div class="tab-pane" data-pane="audit" hidden>
|
||||
<section class="panel">
|
||||
<h2>Audit-Log</h2>
|
||||
<p class="muted small">Siel protokolliert, was auf dem Server passiert – zum Beispiel in #bot-log.</p>
|
||||
<label class="field"><span>Kanal</span>
|
||||
{{ channel_select("audit_channel", guild.channels, data.audit.channel, empty="– Audit-Log aus –") }}
|
||||
</label>
|
||||
<div class="audit-grid" id="audit-events">
|
||||
{% for key, label in [("message_delete", "Gelöschte Nachrichten"), ("message_edit", "Bearbeitete Nachrichten"), ("member_join", "Beitritte"), ("member_leave", "Austritte"), ("member_roles", "Rollenänderungen"), ("member_nick", "Spitznamen"), ("bans", "Banns und Entbannungen"), ("timeouts", "Timeouts")] %}
|
||||
<label class="check"><input type="checkbox" data-event="{{ key }}"{% if data.audit[key] %} checked{% endif %}> {{ label }}</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{# ------------------------------------------------------------ Befehle #}
|
||||
<div class="tab-pane" data-pane="befehle" hidden>
|
||||
<section class="panel">
|
||||
<h2>Befehle für Moderatoren</h2>
|
||||
<p class="muted small">Wer welchen Befehl sieht, richtet sich nach den Discord-Rechten. Anpassen lässt sich das in Discord unter Servereinstellungen → Integrationen → Siel.</p>
|
||||
<table class="table">
|
||||
<thead><tr><th>Befehl</th><th>Was er tut</th><th>Braucht das Recht</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td><code>/warn</code></td><td>Verwarnen – zählt für die automatischen Aktionen</td><td>Mitglieder moderieren</td></tr>
|
||||
<tr><td><code>/verwarnungen</code></td><td>Die Fälle eines Mitglieds anzeigen</td><td>Mitglieder moderieren</td></tr>
|
||||
<tr><td><code>/timeout</code></td><td>Vorübergehend stumm schalten (bis 28 Tage)</td><td>Mitglieder moderieren</td></tr>
|
||||
<tr><td><code>/timeout-aufheben</code></td><td>Timeout beenden</td><td>Mitglieder moderieren</td></tr>
|
||||
<tr><td><code>/kick</code></td><td>Vom Server werfen</td><td>Mitglieder kicken</td></tr>
|
||||
<tr><td><code>/ban</code></td><td>Bannen – dauerhaft oder für eine Zeit</td><td>Mitglieder bannen</td></tr>
|
||||
<tr><td><code>/unban</code></td><td>Bann aufheben (per Discord-ID)</td><td>Mitglieder bannen</td></tr>
|
||||
<tr><td><code>/clear</code></td><td>Bis zu 100 Nachrichten löschen, auf Wunsch nur von einer Person</td><td>Nachrichten verwalten</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div class="savebar">
|
||||
<span class="muted small" id="dirty-note"></span>
|
||||
<button type="submit" class="btn">Speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
<script src="/static/js/moderation.js?v=1"></script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Loading…
Reference in a new issue