Einladungen: wer wen eingeladen hat, Bestenliste, Log-Kanal
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cc7120193a
commit
7bbe283051
5 changed files with 134 additions and 1 deletions
37
app.py
37
app.py
|
|
@ -1212,6 +1212,43 @@ async def qn_answer_delete(request: Request, response_id: int):
|
||||||
return RedirectResponse(f"/fragebogen/{qid}/antworten" if qid.isalnum() else "/fragebogen", status_code=303)
|
return RedirectResponse(f"/fragebogen/{qid}/antworten" if qid.isalnum() else "/fragebogen", status_code=303)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Einladungen
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
INVITE_SOURCES = {"invite": "Einladungslink", "vanity": "Server-Adresse", "bot": "Bot", "unknown": "unbekannt"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/einladungen", response_class=HTMLResponse)
|
||||||
|
async def invites_page(request: Request, nutzer: str = ""):
|
||||||
|
user = current_user(request)
|
||||||
|
require_area(user, "invites")
|
||||||
|
nutzer = nutzer.strip()
|
||||||
|
try:
|
||||||
|
data = await siel._request("GET", "/api/invites" + (f"?user_id={nutzer}" if nutzer.isdigit() else ""))
|
||||||
|
guild = await siel.guild()
|
||||||
|
error = None
|
||||||
|
except siel.SielError as exc:
|
||||||
|
data, guild, error = {"settings": {}, "leaderboard": [], "recent": [], "links": []}, None, str(exc)
|
||||||
|
return render(request, "invites.html", user, data=data, guild=guild, error=error, nutzer=nutzer,
|
||||||
|
sources=INVITE_SOURCES)
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/einladungen")
|
||||||
|
async def invites_save(request: Request):
|
||||||
|
user = current_user(request)
|
||||||
|
require_area(user, "invites")
|
||||||
|
form = await form_with_csrf(request)
|
||||||
|
try:
|
||||||
|
await siel.put_module("invites", {"enabled": form.get("enabled") == "1",
|
||||||
|
"log_channel": form.get("log_channel") or None}, user["name"])
|
||||||
|
panel_db.log(user["id"], user["name"], "Einladungen: Einstellungen gespeichert")
|
||||||
|
flash(request, "Gespeichert.")
|
||||||
|
except siel.SielError as exc:
|
||||||
|
flash(request, str(exc), "error")
|
||||||
|
return RedirectResponse("/einladungen", status_code=303)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ AREAS = {
|
||||||
"tickets": "Tickets",
|
"tickets": "Tickets",
|
||||||
"polls": "Abstimmungen",
|
"polls": "Abstimmungen",
|
||||||
"questionnaires": "Fragebögen",
|
"questionnaires": "Fragebögen",
|
||||||
|
"invites": "Einladungen",
|
||||||
"alliance": "Allianz",
|
"alliance": "Allianz",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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"), ("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"), ("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>
|
||||||
|
|
|
||||||
94
templates/invites.html
Normal file
94
templates/invites.html
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% from "macros.html" import channel_select %}
|
||||||
|
{% block title %}Einladungen{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="page-head">
|
||||||
|
<h1>Einladungen</h1>
|
||||||
|
<p class="muted">Wer hat wen auf den Server der Elyos Allianz eingeladen. Im Discord zeigt <code>/einladungen</code> die eigenen Zahlen.</p>
|
||||||
|
</div>
|
||||||
|
{% if error %}<div class="flash flash-error">{{ error }}</div>{% endif %}
|
||||||
|
|
||||||
|
{% if guild %}
|
||||||
|
<form method="post" action="/einladungen" class="panel">
|
||||||
|
<input type="hidden" name="csrf" value="{{ csrf }}">
|
||||||
|
<h2>Einstellungen</h2>
|
||||||
|
<label class="check"><input type="checkbox" name="enabled" value="1"{% if data.settings.enabled %} checked{% endif %}> Einladungen verfolgen</label>
|
||||||
|
<label class="field"><span>Log-Kanal – hier meldet Siel jeden Beitritt mit dem Einladenden (und Austritte)</span>
|
||||||
|
{{ channel_select("log_channel", guild.channels, data.settings.log_channel, empty="– kein Log –") }}
|
||||||
|
</label>
|
||||||
|
<button type="submit" class="btn">Speichern</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<section class="panel">
|
||||||
|
<h2>Bestenliste</h2>
|
||||||
|
{% if data.leaderboard %}
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="table">
|
||||||
|
<thead><tr><th>#</th><th>Mitglied</th><th>Eingeladen</th><th>Noch da</th><th>Wieder gegangen</th><th></th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{% for r in data.leaderboard %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ loop.index }}</td>
|
||||||
|
<td><strong>{{ r.inviter_name or "?" }}</strong> <span class="muted small">{{ r.inviter_id }}</span></td>
|
||||||
|
<td>{{ r.total }}</td><td>{{ r.stayed }}</td><td>{{ r.left_count }}</td>
|
||||||
|
<td><a href="/einladungen?nutzer={{ r.inviter_id }}" class="small">Details</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p class="muted">Noch keine Einladungen erfasst. Siel zählt ab jetzt jeden Beitritt mit.</p>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="panel" id="beitritte">
|
||||||
|
<div class="panel-head">
|
||||||
|
<h2>{{ "Beitritte zu " ~ nutzer if nutzer else "Letzte Beitritte" }}</h2>
|
||||||
|
<form method="get" action="/einladungen#beitritte" class="inline-form">
|
||||||
|
<input type="text" name="nutzer" value="{{ nutzer }}" inputmode="numeric" pattern="[0-9]*" placeholder="Discord-ID" class="input-id">
|
||||||
|
<button type="submit" class="btn btn-sm btn-secondary">Suchen</button>
|
||||||
|
{% if nutzer %}<a href="/einladungen" class="small">Alle</a>{% endif %}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% if data.recent %}
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="table">
|
||||||
|
<thead><tr><th>Mitglied</th><th>Eingeladen von</th><th>Über</th><th>Beigetreten</th><th>Status</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{% for r in data.recent %}
|
||||||
|
<tr class="{{ 'row-off' if r.left_at else '' }}">
|
||||||
|
<td>{{ r.user_name }} <span class="muted small">{{ r.user_id }}</span></td>
|
||||||
|
<td>{% if r.inviter_id %}<a href="/einladungen?nutzer={{ r.inviter_id }}">{{ r.inviter_name or r.inviter_id }}</a>{% else %}<span class="muted">–</span>{% endif %}</td>
|
||||||
|
<td class="small">{{ sources.get(r.source, r.source) }}{% if r.code %} · <code>{{ r.code }}</code>{% endif %}</td>
|
||||||
|
<td class="small nowrap">{{ r.joined_at | datetime }}</td>
|
||||||
|
<td class="small">{{ "gegangen " ~ (r.left_at | datetime) if r.left_at else "noch da" }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p class="muted">Keine Einträge.</p>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="panel">
|
||||||
|
<h2>Aktive Einladungslinks</h2>
|
||||||
|
{% if data.links %}
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="table">
|
||||||
|
<thead><tr><th>Link</th><th>Erstellt von</th><th>Benutzt</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
{% for l in data.links %}
|
||||||
|
<tr><td><code>{{ l.code }}</code></td><td>{{ l.inviter_name or "–" }}</td><td>{{ l.uses }}×</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p class="muted">Keine aktiven Links (oder Siel konnte sie noch nicht lesen).</p>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
"users": '<path d="M16 19v-1.5a3.5 3.5 0 0 0-3.5-3.5h-5A3.5 3.5 0 0 0 4 17.5V19"/><circle cx="9" cy="8" r="3"/><path d="M20 19v-1.5a3.5 3.5 0 0 0-2.5-3.36"/><path d="M14.5 4.6a3 3 0 0 1 0 5.8"/>',
|
"users": '<path d="M16 19v-1.5a3.5 3.5 0 0 0-3.5-3.5h-5A3.5 3.5 0 0 0 4 17.5V19"/><circle cx="9" cy="8" r="3"/><path d="M20 19v-1.5a3.5 3.5 0 0 0-2.5-3.36"/><path d="M14.5 4.6a3 3 0 0 1 0 5.8"/>',
|
||||||
"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"/>',
|
||||||
"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"/>',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue