LuminaWebsite/admin/bot.php
Maaxxs b96bbd1780 Consilium: own Discord server - its roles decide who sees the Consilium; rights for Consilium raids and entries
Asked for: the alliances move to their own Discord server with the roles Force Commander, Legion Lead, Legion
Officer and Legionär. Decided: everyone with a role there sees the Consilium (our members too), no role per legion
(assignment stays on the website), new accounts are approved by our admins, rights per role as planned, a
permission for Consilium calendar entries that is assigned later. Server ID 1553882046793777283.

- Two Discord servers: settings.consilium_guild_id (seeded, Verwaltung -> Discord-Bot with a check whether the bot
  is there); a group's role lies on one of them (roles.discord_guild_id, NULL = legion, schema 71). Login and the
  periodic sync read both memberships (discord_fetch_memberships/discord_apply_memberships) and sync groups per
  server; name, avatar, joined date and classes come from the legion server, for allies from the Consilium server.
- Leaving: whoever leaves a server loses its groups; an account is deactivated only when it is on neither
  (discord_member_left_guild; bot_api.php takes in_guilds from the bot, the sync checks all servers, older bot
  versions cannot deactivate Consilium members). Logout text no longer names a server.
- Group form lists the roles of both servers, the group list marks Consilium roles; Consilium-Raids channel is
  chosen from the Consilium server's channels.
- Rights per area: consilium.raids / consilium.raids.manage for Consilium raids (create, manage, restore, delete),
  raids.create / raids.manage only for legion raids (raid_area_can_create, raid_area_can_manage_all,
  raid_can_manage asks the raid's area). consilium.calendar: only with it Consilium calendar entries (allies without
  it cannot add entries; legion members with it get "Für wen?" with legion/Consilium).
- Consilium member list: everyone with a role on the Consilium server - our legion as its own section, allied legions,
  without legion - with the Consilium ranks as tags; legion list and profiles leave the Consilium groups out for
  those who do not see the Consilium. Allies pick their class in the profile.
- Consilium admin page: setup checklist for the new structure with the groups of the Consilium server and their
  rights (setup only for roles.manage). Privacy page, README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 02:55:59 +02:00

203 lines
10 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Verwaltung -> Discord-Bot: Kanaele, Premade-Uebersicht und Melde-Panel, Raid-Nachrichten abgleichen
* (includes/discord_bot.php). Ersetzt die Slash-Befehle, die es im Bot seit dem Umbau (09/2026) nicht mehr gibt.
*/
require_once __DIR__ . '/../includes/bootstrap.php';
require_once __DIR__ . '/../includes/discord_bot.php';
require_once __DIR__ . '/../includes/consilium.php';
require_permission('bot.manage');
$settings = [];
$channels = [];
$guildRoles = [];
$apiError = null;
try {
$settings = discord_bot_settings();
$channels = fetch_guild_channels();
$guildRoles = fetch_guild_roles();
} catch (Throwable $e) {
$apiError = $e->getMessage();
}
// Server des Consilium Elyseum (verbuendete Legionen): Die Consilium-Raids stehen in einem Kanal dort
$consiliumGuild = consilium_guild_id();
$consiliumChannels = [];
$consiliumError = null;
if ($apiError === null && $consiliumGuild !== '') {
try {
$consiliumChannels = fetch_guild_channels($consiliumGuild);
} catch (Throwable $e) {
$consiliumError = $e->getMessage();
}
}
/**
* Auswahl eines Textkanals. Kanaele, in denen der Bot nicht posten darf, sind ausgegraut.
*
* @param array<int, array<string, mixed>> $channels
*/
function bot_channel_select(string $name, string $id, array $channels, string $selected, string $placeholder): void
{
?>
<select name="<?= e($name) ?>" id="<?= e($id) ?>">
<option value=""<?= $selected === '' ? ' selected' : '' ?>><?= e($placeholder) ?></option>
<?php foreach ($channels as $channel): ?>
<?php $cid = (string) ($channel['channel_id'] ?? ''); ?>
<option value="<?= e($cid) ?>"<?= $cid === $selected ? ' selected' : '' ?><?= empty($channel['can_post']) && $cid !== $selected ? ' disabled' : '' ?>>
#<?= e((string) ($channel['name'] ?? '')) ?><?php if (!empty($channel['category'])): ?> (<?= e((string) $channel['category']) ?>)<?php endif; ?><?= empty($channel['can_post']) ? ' – Bot darf hier nicht posten' : '' ?>
</option>
<?php endforeach; ?>
</select>
<?php
}
/**
* Auswahl einer Rolle des Servers (fuer das Melde-Panel).
*
* @param array<int, array<string, mixed>> $roles
*/
function bot_role_select(string $name, string $id, array $roles, string $selected, string $placeholder): void
{
?>
<select name="<?= e($name) ?>" id="<?= e($id) ?>">
<option value=""<?= $selected === '' ? ' selected' : '' ?>><?= e($placeholder) ?></option>
<?php foreach ($roles as $role): ?>
<?php $rid = (string) ($role['role_id'] ?? ''); ?>
<option value="<?= e($rid) ?>"<?= $rid === $selected ? ' selected' : '' ?>>@<?= e((string) ($role['name'] ?? '')) ?></option>
<?php endforeach; ?>
</select>
<?php
}
$pageTitle = 'Discord-Bot';
include __DIR__ . '/../includes/header.php';
?>
<div class="panel">
<h1>Discord-Bot</h1>
<p class="text-muted">
Im Discord wird nichts mehr erstellt oder verwaltet – Raids, Premades, Events, Aktivitätschecks und
Reports laufen über die Website. Der Bot zeigt an, erinnert und nimmt Raid-Anmeldungen und Meldungen
entgegen. Hier legst du fest, wohin er postet.
</p>
</div>
<?php if ($apiError !== null): ?>
<div class="panel">
<div class="flash flash-error">Der Bot ist gerade nicht erreichbar: <?= e($apiError) ?></div>
</div>
<?php else: ?>
<div class="panel">
<h2>Kanäle</h2>
<form method="post" action="/admin/bot_action.php" class="bot-admin-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="channels">
<?php foreach (DISCORD_BOT_CHANNELS as $key => [$label, $hint]): ?>
<?php // Consilium-Raids: Kanal auf dem Server des Consiliums, sobald einer eingetragen ist ?>
<?php $onConsilium = $key === 'consilium_raid_channel' && $consiliumGuild !== ''; ?>
<div>
<label for="bot-<?= e($key) ?>"><?= e($label) ?><?= $onConsilium ? ' <span class="text-muted">(Server des Consiliums)</span>' : '' ?></label>
<?php bot_channel_select($key, 'bot-' . $key, $onConsilium ? $consiliumChannels : $channels, $settings[$key] ?? '', '– nicht festgelegt –'); ?>
<div class="field-hint"><?= e($hint) ?></div>
<?php if ($onConsilium && $consiliumError !== null): ?>
<div class="field-hint">⚠️ Die Kanäle des Servers des Consiliums lassen sich nicht laden – ist der Bot dort Mitglied? (<?= e($consiliumError) ?>)</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<div class="actions">
<button type="submit">Kanäle speichern</button>
</div>
</form>
</div>
<div class="panel">
<h2>Discord-Server des <?= e(CONSILIUM_NAME) ?></h2>
<p class="text-muted">
Der Server der verbündeten Legionen. Wer dort eine Rolle hat, kann sich auf der Website anmelden und sieht das
<?= e(CONSILIUM_NAME) ?> – welche Gruppe zu welcher Rolle gehört, legst du unter
<a href="/admin/roles.php">Berechtigungsgruppen</a> fest. Der Bot muss auf dem Server sein (für die
Consilium-Raids und um zu bemerken, wer den Server verlässt).
</p>
<form method="post" action="/admin/bot_action.php" class="bot-admin-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="consilium_guild">
<div>
<label for="bot-consilium-guild">Server-ID</label>
<input type="text" id="bot-consilium-guild" name="consilium_guild_id" inputmode="numeric" maxlength="20" value="<?= e($consiliumGuild) ?>" placeholder="z.B. 123456789012345678">
<div class="field-hint">
<?php if ($consiliumGuild === ''): ?>
Kein Server eingetragen – dann gibt es auf der Website nur den Server der Legion.
<?php elseif ($consiliumError === null): ?>
✅ Der Bot ist auf diesem Server.
<?php else: ?>
⚠️ Der Bot ist nicht auf diesem Server oder nicht erreichbar – bitte einladen.
<?php endif; ?>
In Discord: Rechtsklick auf den Server → „Server-ID kopieren“ (Entwicklermodus nötig). Leer lassen, um ihn zu entfernen.
</div>
</div>
<div class="actions">
<button type="submit">Server speichern</button>
</div>
</form>
</div>
<div class="panel">
<h2>Übersichten im Discord</h2>
<p class="text-muted">
Der Bot merkt sich, wo sie stehen. Postest du sie neu, löscht er die bisherige. Was früher per
Befehl im Discord gepostet wurde, kennt er nicht – das nach dem Neu-Posten dort von Hand löschen.
</p>
<div class="bot-panels">
<?php foreach (DISCORD_BOT_PANELS as $kind => [$label, $path, $hint]): ?>
<?php $current = $settings[$kind === 'premades' ? 'premade_panel_channel' : 'report_panel_channel'] ?? ''; ?>
<form method="post" action="/admin/bot_action.php" class="bot-admin-form bot-panel">
<?= csrf_field() ?>
<input type="hidden" name="action" value="panel">
<input type="hidden" name="kind" value="<?= e($kind) ?>">
<h3><?= e($label) ?></h3>
<p class="text-muted"><?= e($hint) ?></p>
<p>
<?php if ($current !== ''): ?>
Steht in <strong><?= e(discord_bot_channel_label($current, $channels)) ?></strong>.
<?php else: ?>
<span class="text-muted">Noch nicht über die Website gepostet.</span>
<?php endif; ?>
</p>
<div>
<label for="bot-panel-<?= e($kind) ?>">Kanal</label>
<?php bot_channel_select('channel_id', 'bot-panel-' . $kind, $channels, $current, '– Kanal wählen –'); ?>
</div>
<?php if ($kind === 'reports'): ?>
<div>
<label for="bot-report-ping">Ping beim Posten</label>
<?php bot_role_select('ping_role_id', 'bot-report-ping', $guildRoles, $settings['report_panel_ping_role'] ?? '', '– niemand –'); ?>
<div class="field-hint">Über dem Panel steht „Arieluma @Rolle!“ – das pingt die Rolle einmal beim Posten, z.B. alle Mitglieder. Jedes Neu-Posten pingt wieder.</div>
</div>
<div>
<label for="bot-report-lead">Leitung im Text</label>
<?php bot_role_select('lead_role_id', 'bot-report-lead', $guildRoles, $settings['report_panel_lead_role'] ?? '', '– keine Rolle („die Legionsleitung“) –'); ?>
<div class="field-hint">Wird im Panel erwähnt, ohne Ping – z.B. „die @Sedes Luminis kümmern sich zeitnah um dein Anliegen“.</div>
</div>
<?php endif; ?>
<div class="actions">
<button type="submit" class="button-secondary"><?= $current !== '' ? 'Neu posten' : 'Posten' ?></button>
</div>
</form>
<?php endforeach; ?>
</div>
</div>
<div class="panel">
<h2>Raid-Nachrichten abgleichen</h2>
<p class="text-muted">
Bringt die Nachrichten aller aktiven Raids im Discord auf den Stand der Website und postet fehlende
neu – etwa wenn jemand eine Raid-Nachricht gelöscht hat.
</p>
<form method="post" action="/admin/bot_action.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="resync">
<button type="submit" class="button-secondary"><?= icon('restore') ?> Jetzt abgleichen</button>
</form>
</div>
<?php endif; ?>
<?php include __DIR__ . '/../includes/footer.php'; ?>