Temporäre Sprachkanäle: Auslösekanäle einrichten und offene Kanäle sehen/schließen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7bbe283051
commit
2dc7407f5f
7 changed files with 201 additions and 2 deletions
57
app.py
57
app.py
|
|
@ -1249,6 +1249,63 @@ async def invites_save(request: Request):
|
||||||
return RedirectResponse("/einladungen", status_code=303)
|
return RedirectResponse("/einladungen", status_code=303)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Temporäre Sprachkanäle
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@app.get("/sprachkanaele", response_class=HTMLResponse)
|
||||||
|
async def tempvoice_page(request: Request):
|
||||||
|
user = current_user(request)
|
||||||
|
require_area(user, "tempvoice")
|
||||||
|
try:
|
||||||
|
data = await siel._request("GET", "/api/tempvoice")
|
||||||
|
guild = await siel.guild()
|
||||||
|
error = None
|
||||||
|
except siel.SielError as exc:
|
||||||
|
data, guild, error = {"settings": {"generators": []}, "channels": []}, None, str(exc)
|
||||||
|
draft = DRAFTS.pop((user["id"], "tempvoice"), None)
|
||||||
|
if draft is not None:
|
||||||
|
data["settings"] = draft
|
||||||
|
return render(request, "tempvoice.html", user, data=data, guild=guild, error=error, now=int(time.time()))
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/sprachkanaele")
|
||||||
|
async def tempvoice_save(request: Request):
|
||||||
|
user = current_user(request)
|
||||||
|
require_area(user, "tempvoice")
|
||||||
|
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 Eingaben kamen nicht richtig an. Bitte lade die Seite neu.", "error")
|
||||||
|
return RedirectResponse("/sprachkanaele", status_code=303)
|
||||||
|
try:
|
||||||
|
saved = await siel.put_module("tempvoice", payload, user["name"])
|
||||||
|
panel_db.log(user["id"], user["name"], "Temporäre Sprachkanäle gespeichert",
|
||||||
|
f"{len(saved['generators'])} Auslösekanäle")
|
||||||
|
flash(request, "Gespeichert.")
|
||||||
|
except siel.SielError as exc:
|
||||||
|
DRAFTS[(user["id"], "tempvoice")] = payload
|
||||||
|
flash(request, str(exc), "error")
|
||||||
|
return RedirectResponse("/sprachkanaele", status_code=303)
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/sprachkanaele/{channel_id}/schliessen")
|
||||||
|
async def tempvoice_close(request: Request, channel_id: int):
|
||||||
|
user = current_user(request)
|
||||||
|
require_area(user, "tempvoice")
|
||||||
|
await form_with_csrf(request)
|
||||||
|
try:
|
||||||
|
await siel.delete(f"/api/tempvoice/channels/{channel_id}")
|
||||||
|
panel_db.log(user["id"], user["name"], "Temporären Sprachkanal geschlossen", str(channel_id))
|
||||||
|
flash(request, "Der Kanal ist geschlossen.")
|
||||||
|
except siel.SielError as exc:
|
||||||
|
flash(request, str(exc), "error")
|
||||||
|
return RedirectResponse("/sprachkanaele#offen", status_code=303)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ AREAS = {
|
||||||
"polls": "Abstimmungen",
|
"polls": "Abstimmungen",
|
||||||
"questionnaires": "Fragebögen",
|
"questionnaires": "Fragebögen",
|
||||||
"invites": "Einladungen",
|
"invites": "Einladungen",
|
||||||
|
"tempvoice": "Sprachkanäle",
|
||||||
"alliance": "Allianz",
|
"alliance": "Allianz",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -429,3 +429,11 @@ input[type=number]:focus { outline: none; border-color: var(--gold); }
|
||||||
.qn-option > :nth-child(3), .qn-option > :nth-child(4) { grid-column: 1 / -1; }
|
.qn-option > :nth-child(3), .qn-option > :nth-child(4) { grid-column: 1 / -1; }
|
||||||
.qn-dl { grid-template-columns: minmax(0, 1fr); }
|
.qn-dl { grid-template-columns: minmax(0, 1fr); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------- Temporäre Sprachkanäle ---------- */
|
||||||
|
.tv-list { display: flex; flex-direction: column; gap: 0.6rem; margin: 0.75rem 0; }
|
||||||
|
.tv-row { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.9rem 0.7rem; }
|
||||||
|
.tv-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) 110px; gap: 0 0.9rem; }
|
||||||
|
.tv-grid .field { max-width: none; margin-bottom: 0.4rem; }
|
||||||
|
.tv-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
|
||||||
|
@media (max-width: 860px) { .tv-grid { grid-template-columns: minmax(0, 1fr); } }
|
||||||
|
|
|
||||||
70
static/js/tempvoice.js
Normal file
70
static/js/tempvoice.js
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
/* Temporaere Sprachkanaele: Liste der Ausloesekanaele bearbeiten. */
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const raw = document.getElementById('tv-data');
|
||||||
|
if (!raw) return;
|
||||||
|
const { generators, channels } = JSON.parse(raw.textContent);
|
||||||
|
const { el } = SielEditor;
|
||||||
|
const form = document.getElementById('tv-form');
|
||||||
|
const list = document.getElementById('tv-list');
|
||||||
|
const gens = (generators || []).map((g) => Object.assign({}, g));
|
||||||
|
const voice = channels.filter((c) => c.type === 'voice');
|
||||||
|
const cats = channels.filter((c) => c.type === 'category');
|
||||||
|
const catName = (id) => (cats.find((c) => c.id === id) || {}).name;
|
||||||
|
|
||||||
|
function select(items, value, empty, onChange, label) {
|
||||||
|
const s = el('select', {});
|
||||||
|
s.append(el('option', { value: '', text: empty }));
|
||||||
|
for (const c of items) s.append(el('option', { value: c.id, text: label(c) }));
|
||||||
|
s.value = value || '';
|
||||||
|
s.addEventListener('change', () => onChange(s.value || null));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function paint() {
|
||||||
|
list.textContent = '';
|
||||||
|
gens.forEach((g, idx) => {
|
||||||
|
const name = el('input', { type: 'text', maxlength: '90', placeholder: '🔊 Raum von {user}' });
|
||||||
|
name.value = g.name || '';
|
||||||
|
name.addEventListener('input', () => { g.name = name.value; });
|
||||||
|
const limit = el('input', { type: 'number', min: '0', max: '99', class: 'input-sm' });
|
||||||
|
limit.value = g.limit || 0;
|
||||||
|
limit.addEventListener('input', () => { g.limit = Number(limit.value) || 0; });
|
||||||
|
const manage = el('input', { type: 'checkbox' });
|
||||||
|
manage.checked = !!g.owner_manage;
|
||||||
|
manage.addEventListener('change', () => { g.owner_manage = manage.checked; });
|
||||||
|
list.append(el('div', { class: 'tv-row' },
|
||||||
|
el('div', { class: 'tv-grid' },
|
||||||
|
el('label', { class: 'field' }, el('span', { text: 'Auslösekanal' }),
|
||||||
|
select(voice, g.trigger, '– Sprachkanal wählen –', (v) => { g.trigger = v; },
|
||||||
|
(c) => '🔊 ' + c.name + (c.category_id && catName(c.category_id) ? ' (' + catName(c.category_id) + ')' : ''))),
|
||||||
|
el('label', { class: 'field' }, el('span', { text: 'Neue Kanäle in Kategorie' }),
|
||||||
|
select(cats, g.category, '– wie der Auslösekanal –', (v) => { g.category = v; }, (c) => c.name)),
|
||||||
|
el('label', { class: 'field' }, el('span', { text: 'Name' }), name),
|
||||||
|
el('label', { class: 'field' }, el('span', { text: 'Limit (0 = keins)' }), limit)),
|
||||||
|
el('div', { class: 'tv-foot' },
|
||||||
|
el('label', { class: 'check' }, manage, ' Ersteller darf seinen Kanal in Discord selbst verwalten (Name, Limit, Leute verschieben/stummschalten)'),
|
||||||
|
el('button', { type: 'button', class: 'btn-link danger', text: 'Entfernen', onclick: () => { gens.splice(idx, 1); paint(); mark(); } }))));
|
||||||
|
});
|
||||||
|
if (!gens.length) list.append(el('p', { class: 'muted', text: 'Noch kein Auslösekanal.' }));
|
||||||
|
document.getElementById('tv-add').hidden = gens.length >= 10;
|
||||||
|
}
|
||||||
|
document.getElementById('tv-add').addEventListener('click', () => {
|
||||||
|
gens.push({ trigger: null, category: null, name: '🔊 Raum von {user}', limit: 0, owner_manage: true });
|
||||||
|
paint();
|
||||||
|
mark();
|
||||||
|
});
|
||||||
|
paint();
|
||||||
|
|
||||||
|
let dirty = false;
|
||||||
|
const note = document.getElementById('dirty-note');
|
||||||
|
function mark() { dirty = true; note.textContent = 'Ungespeicherte Änderungen'; }
|
||||||
|
form.addEventListener('input', mark);
|
||||||
|
form.addEventListener('change', mark);
|
||||||
|
window.addEventListener('beforeunload', (ev) => { if (dirty) { ev.preventDefault(); ev.returnValue = ''; } });
|
||||||
|
form.addEventListener('submit', () => {
|
||||||
|
document.getElementById('tv-payload').value = JSON.stringify({ generators: gens });
|
||||||
|
dirty = false;
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<title>{% block title %}Siel{% endblock %} · Elyos Allianz</title>
|
<title>{% block title %}Siel{% endblock %} · Elyos Allianz</title>
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="/static/img/favicon-32.png">
|
<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="apple-touch-icon" href="/static/img/favicon-180.png">
|
||||||
<link rel="stylesheet" href="/static/css/panel.css?v=13">
|
<link rel="stylesheet" href="/static/css/panel.css?v=14">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% if user %}
|
{% if user %}
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<div class="nav-heading">Funktionen</div>
|
<div class="nav-heading">Funktionen</div>
|
||||||
{% for area, label, href, ic in [("welcome", "Begrüßung", "/begruessung", "welcome"), ("reactionroles", "Reaktionsrollen", "/reaktionsrollen", "smile"), ("moderation", "Moderation", "/moderation", "shield"), ("tickets", "Tickets", "/tickets", "ticket"), ("polls", "Abstimmungen", "/abstimmungen", "chart"), ("questionnaires", "Fragebögen", "/fragebogen", "clipboard"), ("invites", "Einladungen", "/einladungen", "mail"), ("alliance", "Allianz", "/allianz", "users")] %}
|
{% for area, label, href, ic in [("welcome", "Begrüßung", "/begruessung", "welcome"), ("reactionroles", "Reaktionsrollen", "/reaktionsrollen", "smile"), ("moderation", "Moderation", "/moderation", "shield"), ("tickets", "Tickets", "/tickets", "ticket"), ("polls", "Abstimmungen", "/abstimmungen", "chart"), ("questionnaires", "Fragebögen", "/fragebogen", "clipboard"), ("invites", "Einladungen", "/einladungen", "mail"), ("tempvoice", "Sprachkanäle", "/sprachkanaele", "mic"), ("alliance", "Allianz", "/allianz", "users")] %}
|
||||||
{% if area in user.areas %}
|
{% if area in user.areas %}
|
||||||
{% if href %}
|
{% if href %}
|
||||||
<a href="{{ href }}" class="nav-link{% if path == href or path.startswith(href ~ "/") %} active{% endif %}">{{ icon(ic) }}<span>{{ label }}</span></a>
|
<a href="{{ href }}" class="nav-link{% if path == href or path.startswith(href ~ "/") %} active{% endif %}">{{ icon(ic) }}<span>{{ label }}</span></a>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
"chart": '<line x1="18" y1="20" x2="18" y2="10"/><line x1="12" y1="20" x2="12" y2="4"/><line x1="6" y1="20" x2="6" y2="14"/>',
|
"chart": '<line x1="18" y1="20" x2="18" y2="10"/><line x1="12" y1="20" x2="12" y2="4"/><line x1="6" y1="20" x2="6" y2="14"/>',
|
||||||
"clipboard": '<rect x="6" y="4" width="12" height="17" rx="2"/><path d="M9 4V3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1"/><line x1="9" y1="10" x2="15" y2="10"/><line x1="9" y1="14" x2="15" y2="14"/><line x1="9" y1="18" x2="13" y2="18"/>',
|
"clipboard": '<rect x="6" y="4" width="12" height="17" rx="2"/><path d="M9 4V3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1"/><line x1="9" y1="10" x2="15" y2="10"/><line x1="9" y1="14" x2="15" y2="14"/><line x1="9" y1="18" x2="13" y2="18"/>',
|
||||||
"mail": '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/>',
|
"mail": '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/>',
|
||||||
|
"mic": '<rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5 11a7 7 0 0 0 14 0"/><line x1="12" y1="18" x2="12" y2="21"/>',
|
||||||
"key": '<circle cx="7.5" cy="15.5" r="4.5"/><path d="m10.7 12.3 9.8-9.8"/><path d="m17 6 3 3"/><path d="m14.5 8.5 2 2"/>',
|
"key": '<circle cx="7.5" cy="15.5" r="4.5"/><path d="m10.7 12.3 9.8-9.8"/><path d="m17 6 3 3"/><path d="m14.5 8.5 2 2"/>',
|
||||||
"list": '<line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4.5" cy="6" r="1"/><circle cx="4.5" cy="12" r="1"/><circle cx="4.5" cy="18" r="1"/>',
|
"list": '<line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4.5" cy="6" r="1"/><circle cx="4.5" cy="12" r="1"/><circle cx="4.5" cy="18" r="1"/>',
|
||||||
"log-out": '<path d="M9 20H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h3"/><path d="m14 16 4-4-4-4"/><path d="M18 12H9"/>',
|
"log-out": '<path d="M9 20H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h3"/><path d="m14 16 4-4-4-4"/><path d="M18 12H9"/>',
|
||||||
|
|
|
||||||
62
templates/tempvoice.html
Normal file
62
templates/tempvoice.html
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Sprachkanäle{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="page-head">
|
||||||
|
<h1>Temporäre Sprachkanäle</h1>
|
||||||
|
<p class="muted">Wer einen Auslösekanal betritt, bekommt einen eigenen Sprachkanal – ist er leer, verschwindet er wieder. Im Raum stellt der Ersteller mit <code>/raum</code> Name, Limit und Zugang ein.</p>
|
||||||
|
</div>
|
||||||
|
{% if error %}<div class="flash flash-error">{{ error }}</div>{% endif %}
|
||||||
|
|
||||||
|
<section class="panel" id="offen">
|
||||||
|
<div class="panel-head">
|
||||||
|
<h2>Gerade offen <span class="muted">({{ data.channels | length }})</span></h2>
|
||||||
|
<a href="/sprachkanaele#offen" class="btn btn-sm btn-secondary">Aktualisieren</a>
|
||||||
|
</div>
|
||||||
|
{% if data.channels %}
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="table">
|
||||||
|
<thead><tr><th>Kanal</th><th>Leitung</th><th>Drin</th><th>Offen seit</th><th>Über</th><th></th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{% for c in data.channels %}
|
||||||
|
<tr>
|
||||||
|
<td><strong>{{ c.name }}</strong>{% if c.locked %} <span class="tag">🔒 gesperrt</span>{% endif %}
|
||||||
|
<div class="muted small">{{ c.category or "ohne Kategorie" }}{% if c.limit %} · Limit {{ c.limit }}{% endif %}</div></td>
|
||||||
|
<td>{{ c.owner_name }}</td>
|
||||||
|
<td>{{ c.members | length }}{% if c.members %}<div class="muted small">{{ c.members | join(", ") }}</div>{% endif %}</td>
|
||||||
|
<td class="small nowrap">{{ c.created_at | datetime }}</td>
|
||||||
|
<td class="small">{{ c.trigger or "–" }}</td>
|
||||||
|
<td>
|
||||||
|
<form method="post" action="/sprachkanaele/{{ c.channel_id }}/schliessen" data-confirm="„{{ c.name }}“ schließen? Alle darin fliegen aus dem Sprachkanal.">
|
||||||
|
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||||
|
<button type="submit" class="btn btn-sm btn-danger">Schließen</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p class="muted">Gerade ist kein temporärer Sprachkanal offen.</p>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{% if guild %}
|
||||||
|
<script type="application/json" id="tv-data">{{ {"generators": data.settings.generators, "channels": guild.channels} | tojson }}</script>
|
||||||
|
<form method="post" action="/sprachkanaele" class="panel" id="tv-form">
|
||||||
|
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||||
|
<input type="hidden" name="payload" id="tv-payload">
|
||||||
|
<h2>Auslösekanäle</h2>
|
||||||
|
<p class="muted small">Leg dafür in Discord einen normalen Sprachkanal an, z. B. „➕ Raum erstellen“, und wähle ihn hier aus. Im Namen ersetzt Siel <code>{user}</code> durch den Namen und <code>{nummer}</code> durch eine laufende Nummer.</p>
|
||||||
|
<div id="tv-list" class="tv-list"></div>
|
||||||
|
<button type="button" class="btn btn-sm btn-ghost" id="tv-add">+ Auslösekanal hinzufügen</button>
|
||||||
|
<div class="savebar">
|
||||||
|
<span class="muted small" id="dirty-note"></span>
|
||||||
|
<button type="submit" class="btn">Speichern</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<script src="/static/js/embed-editor.js?v=2"></script>
|
||||||
|
<script src="/static/js/tempvoice.js?v=1"></script>
|
||||||
|
{% endif %}
|
||||||
|
<script src="/static/js/confirm.js?v=1"></script>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in a new issue