Asked for: alliances ("Consilium Elyseum") with their own view, a member-list tab with the allied legions and their
members, an own raid area, a calendar that shows them only alliance entries, and live map sessions the legion can
share with them - watching only, or drawing only with an extra permission. There is one Discord role "Consilium
Elyseum" for all allies, so which legion each ally belongs to is stored on the website.
- Permissions consilium.view / consilium.draw / consilium.manage. An account with consilium.view but without
dashboard.view is a guest of the Consilium (consilium_only(), sql_is_consilium_only()) and sees only the alliance
area; raids, calendar and map stay restricted even with extra rights like raids.view or map.view.
- includes/consilium.php; consilium.php is the allies' start page instead of the dashboard (next raids and entries,
legions, running shared map sessions); admin/consilium.php: setup hints, allied legions, member assignment.
users.consilium_legion_id, table consilium_legions (schema 69); allies pick their legion under Mein Profil.
- Members: new tab "Consilium Elyseum" (legions with their members), the only tab allies see. Legion-only lists
(dues, Lumipunkte, member pickers, raid and activity points) leave allies out.
- Raids: two areas, legion and Consilium, told apart by the Discord channel ("Consilium-Raids" under Verwaltung ->
Discord-Bot, settings.consilium_raid_channel; the bot API returns channel_id). Allies only see and sign up for
Consilium raids, which give no Lumipunkte; raids created in the Consilium area are posted to its channel.
- Calendar: audience "Consilium Elyseum". Allies see only those entries and the Consilium raids (also in their iCal
subscription), their own entries are always Consilium entries; the public calendar shows no Consilium raids; the
legion sees them marked with 🤝.
- Map: whoever may edit a public tactic shares its running live session with the Consilium (consilium_share, logged).
The share lives in the bot's live relay and only for that session: it ends with "Freigabe beenden" or 60 s after
the last legion member left; making the tactic private or deleting it ends it as well. Allies see only running
shared sessions under Karte (and on their start page), join and watch; with consilium.draw they add strokes,
areas, points and text - no figures, nothing moved, erased or undone, no tactics, steps, copies or history.
Enforced in tactics_api.php (guest branch: shared tactics only, only live_token and shape_create) and in the relay
(guest tickets, event whitelist, guests are disconnected when the share ends). Needs the bot update (api.py,
database/db.py, live_tactics.py).
- Navigation, privacy page, patch note, README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
5.7 KiB
PHP
128 lines
5.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/events_api.php';
|
|
require_once __DIR__ . '/raid_attendance.php';
|
|
|
|
/**
|
|
* Verwaltung -> Discord-Bot (admin/bot.php): was frueher die Slash-Befehle der Legionsleitung im Bot
|
|
* erledigt haben. Seit dem Umbau (09/2026) wird im Discord nichts mehr erstellt oder verwaltet - der Bot
|
|
* zeigt an, erinnert und nimmt Raid-Anmeldungen und Meldungen entgegen. Hier legt die Leitung fest,
|
|
* wohin er postet: Raid-, Log- und Melde-Kanal, die Premade-Uebersicht und das Melde-Panel.
|
|
*/
|
|
|
|
// Die Kanaele, die der Bot kennt: Schluessel in /api/settings => [Bezeichnung, Erklaerung]
|
|
const DISCORD_BOT_CHANNELS = [
|
|
'raid_channel' => ['Raid-Kanal', 'Hier postet der Bot neue Raids von der Website - mit Anmeldung.'],
|
|
'consilium_raid_channel' => ['Consilium-Raids', 'Raids des Consilium Elyseum mit den verbündeten Legionen - auf der Website ein eigener Bereich. Den Raid-Kanal der Legion für die Rolle „Consilium Elyseum“ unsichtbar machen, sonst können sie sich im Discord auch dort anmelden.'],
|
|
'log_channel' => ['Log-Kanal', 'Verwaltungsaktionen der Website und Meldungen des Bots (z.B. wer die Erinnerung zur Anwesenheit bekommen hat).'],
|
|
'report_channel' => ['Melde-Kanal', 'Hier landen Meldungen über „Mitglied melden“ - ohne eigenen Kanal im Log-Kanal. Nur für die Leitung sichtbar machen!'],
|
|
];
|
|
|
|
// Nachrichten, die der Bot auf Wunsch postet und sich merkt: Art => [Bezeichnung, Pfad der Bot-API, Erklaerung]
|
|
const DISCORD_BOT_PANELS = [
|
|
'premades' => ['Premade-Übersicht', '/premades/panel', 'Alle Premade-Gruppen mit Lead, Kader und Reserve - aktualisiert sich bei jeder Änderung selbst.'],
|
|
'reports' => ['Melde-Panel', '/reports/panel', 'Der Knopf „Mitglied melden“ mit den Regeln: Punkte je Meldung, Mute-Schwelle, Stille Treppe. Ändert ihr Schwelle oder Punkte unter Reports, passt der Bot das Panel selbst an.'],
|
|
];
|
|
|
|
/**
|
|
* @param array<string, mixed>|null $jsonBody
|
|
* @return array<string, mixed>
|
|
* @throws RuntimeException
|
|
*/
|
|
function discord_bot_request(string $method, string $path, ?array $jsonBody = null): array
|
|
{
|
|
// Die Bot-API liegt eine Ebene ueber /api/raids
|
|
$base = preg_replace('#/raids$#', '', raids_api_config()['url']);
|
|
return bot_api_request($method, $base . $path, [], $jsonBody, 'Bot-API');
|
|
}
|
|
|
|
/**
|
|
* Kanaele, wo Premade-Uebersicht und Melde-Panel stehen, und die Rollen des Melde-Panels (IDs als Strings,
|
|
* '' = nicht festgelegt).
|
|
*
|
|
* @return array<string, string>
|
|
* @throws RuntimeException
|
|
*/
|
|
function discord_bot_settings(): array
|
|
{
|
|
$data = discord_bot_request('GET', '/settings/' . events_guild_id());
|
|
$settings = [];
|
|
$keys = ['premade_panel_channel', 'report_panel_channel', 'report_panel_ping_role', 'report_panel_lead_role'];
|
|
foreach (array_merge(array_keys(DISCORD_BOT_CHANNELS), $keys) as $key) {
|
|
$settings[$key] = !empty($data[$key]) ? (string) $data[$key] : '';
|
|
}
|
|
discord_bot_remember_consilium_channel($settings['consilium_raid_channel']);
|
|
return $settings;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, int> $channels Schluessel aus DISCORD_BOT_CHANNELS => Kanal-ID
|
|
* @throws RuntimeException
|
|
*/
|
|
function discord_bot_save_channels(array $channels): void
|
|
{
|
|
$data = discord_bot_request('PATCH', '/settings/' . events_guild_id(), $channels);
|
|
if (array_key_exists('consilium_raid_channel', $data)) {
|
|
discord_bot_remember_consilium_channel(!empty($data['consilium_raid_channel']) ? (string) $data['consilium_raid_channel'] : '');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Den Kanal der Consilium-Raids merkt sich auch die Website (settings.consilium_raid_channel) - daran trennt sie
|
|
* Legions- und Consilium-Raids (raid_area() in includes/raids_api.php), ohne fuer jede Seite den Bot zu fragen.
|
|
*/
|
|
function discord_bot_remember_consilium_channel(string $channelId): void
|
|
{
|
|
if ($channelId !== setting_get('consilium_raid_channel')) {
|
|
try {
|
|
setting_set('consilium_raid_channel', $channelId);
|
|
} catch (PDOException $e) {
|
|
// ohne settings-Tabelle eben nicht
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Postet die Premade-Uebersicht bzw. das Melde-Panel; eine bisherige Nachricht davon loescht der Bot.
|
|
* Beim Melde-Panel kommen die Rollen mit: ping_role_id (wird beim Posten gepingt) und lead_role_id (die
|
|
* Leitung, im Text genannt) - jeweils null = keine.
|
|
*
|
|
* @param array<string, int|null> $roles
|
|
* @throws RuntimeException
|
|
*/
|
|
function discord_bot_post_panel(string $kind, int $channelId, array $roles = []): void
|
|
{
|
|
discord_bot_request('POST', DISCORD_BOT_PANELS[$kind][1], ['channel_id' => $channelId] + $roles);
|
|
}
|
|
|
|
/**
|
|
* Alle aktiven Raid-Nachrichten abgleichen: aktualisieren, fehlende neu posten. Neu gepostete Raids haben
|
|
* eine neue ID - Einstellungen, Anwesenheit und Lumipunkte ziehen hier mit um (raid_rename_id).
|
|
*
|
|
* @return array{updated: int, reposted: array<int, array<string, mixed>>, failed: array<int, array<string, mixed>>}
|
|
* @throws RuntimeException
|
|
*/
|
|
function discord_bot_resync_raids(): array
|
|
{
|
|
$data = discord_bot_request('POST', '/raids/resync');
|
|
foreach ((array) ($data['reposted'] ?? []) as $moved) {
|
|
raid_rename_id((int) ($moved['old'] ?? 0), (int) ($moved['new'] ?? 0));
|
|
}
|
|
return [
|
|
'updated' => (int) ($data['updated'] ?? 0),
|
|
'reposted' => (array) ($data['reposted'] ?? []),
|
|
'failed' => (array) ($data['failed'] ?? []),
|
|
];
|
|
}
|
|
|
|
/** "#raids (Kategorie)" fuer eine Kanal-ID aus der Kanalliste - sonst die ID. */
|
|
function discord_bot_channel_label(string $channelId, array $channels): string
|
|
{
|
|
foreach ($channels as $channel) {
|
|
if ((string) ($channel['channel_id'] ?? '') === $channelId) {
|
|
return '#' . (string) ($channel['name'] ?? '') . (!empty($channel['category']) ? ' (' . $channel['category'] . ')' : '');
|
|
}
|
|
}
|
|
return 'Kanal ' . $channelId;
|
|
}
|