The bot (Aion2_RaidPlaner, deployed 2026-09-25) has no slash commands any more. Raids,
premades, events, activity checks and reports are created and managed only here; in Discord
members sign up for raids, answer invitations and activity checks and report players.
- Raid signup works the same in Discord and here: the bot assigns the group (perform_signup),
the website only sends the wish (raid_signup(..., $wish)) and shows the reason when it did
not fit (locked, role full, raid full). raid_wish_is_sensible() and the role constants are
gone. Declining ("Abmelden") now keeps the player under "Abgemeldet" (raid_decline, new bot
endpoint .../decline) like in Discord; the raid card shows "Du hast dich abgemeldet" with
"Doch anmelden". Class input is checked against AION_CLASSES.
- The Discord message shows the raid lead and the Lumipunkte: raid_create_action/raid_edit_action
send lead_id/lead_name/points_text, raid_sync_extras() on raids.php pushes them for raids
where the bot is missing them (at most 3 per page view, follows changed raid IDs).
- bot_api.php?action=member: main class (profile choice) and whether the person has an
(active) account - the bot preselects the class and hints that Lumipunkte need an account.
- New page Verwaltung -> Discord-Bot (admin/bot.php, includes/discord_bot.php, permission
bot.manage, on update granted to groups with raids.manage; schema 53): raid, log and report
channel, post the premade overview (updates itself) and the report panel (the bot replaces
the previous one), resync all raid messages (reposted raids move their settings via
raid_rename_id). Audit area "Discord-Bot", sidebar entry with a new bot icon.
- Reports: after picking a player in the filter, delete all of their reports at once
(DELETE /api/reports/user/{id}), which also lifts the auto-mute.
- Calendar and raid logs no longer count declined players as signed up / on the bench.
- Texts that mentioned bot commands (events, activity check, config example, README) updated;
privacy policy mentions the main-class lookup and that declines stay visible. Patch notes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
4.7 KiB
PHP
110 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* Rueckkanal fuer den Discord-Bot. Header: X-Bot-Key: <config.php bot_callback.key>
|
|
*
|
|
* Anwesenheit (cogs/attendance.py im Bot): Wenn die Uhrzeit eines Raids erreicht ist, fragt der Bot
|
|
* hier nach, wer eine Erinnerung zur Anwesenheitsliste bekommen soll: der Raid-Lead (hat den Raid auf der
|
|
* Website angelegt) - auch wenn er selbst nicht angemeldet ist. Hat der Raid keinen (z.B. aeltere Raids),
|
|
* alle Angemeldeten mit einem aktiven Website-Konto und der Berechtigung raids.manage. Die PN schickt der Bot.
|
|
* GET /bot_api.php?action=attendance_recipients&raid_id=...&discord_ids=1,2,3
|
|
*
|
|
* Raid-Anmeldung im Discord (cogs/teamplaner.py, website.py im Bot): Main-Klasse eines Spielers (im Profil
|
|
* waehlbar) und ob er ein (freigeschaltetes) Konto hat - ohne gibt es keine Lumipunkte.
|
|
* GET /bot_api.php?action=member&discord_id=...
|
|
*/
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
require_once __DIR__ . '/includes/raid_attendance.php';
|
|
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
|
|
function bot_api_reply(int $status, array $data): void
|
|
{
|
|
http_response_code($status);
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
$expectedKey = bot_callback_key();
|
|
if ($expectedKey === null) {
|
|
bot_api_reply(503, ['status' => 'error', 'message' => 'bot_callback.key ist in config.php nicht eingetragen.']);
|
|
}
|
|
$givenKey = (string) ($_SERVER['HTTP_X_BOT_KEY'] ?? '');
|
|
if (!hash_equals($expectedKey, $givenKey)) {
|
|
bot_api_reply(403, ['status' => 'error', 'message' => 'Ungültiger Schlüssel.']);
|
|
}
|
|
|
|
$action = (string) ($_GET['action'] ?? '');
|
|
if ($action === 'member') {
|
|
$discordId = (string) ($_GET['discord_id'] ?? '');
|
|
if (!ctype_digit($discordId)) {
|
|
bot_api_reply(400, ['status' => 'error', 'message' => 'discord_id fehlt.']);
|
|
}
|
|
$stmt = db()->prepare('SELECT status, class_name, classes FROM users WHERE discord_id = ? LIMIT 1');
|
|
$stmt->execute([$discordId]);
|
|
$member = $stmt->fetch();
|
|
bot_api_reply(200, [
|
|
'status' => 'success',
|
|
'account' => $member !== false,
|
|
'active' => $member !== false && $member['status'] === 'active',
|
|
'main_class' => $member !== false && in_array((string) $member['class_name'], AION_CLASSES, true) ? (string) $member['class_name'] : null,
|
|
'classes' => $member !== false ? classes_from_list($member['classes']) : [],
|
|
]);
|
|
}
|
|
if ($action !== 'attendance_recipients') {
|
|
bot_api_reply(400, ['status' => 'error', 'message' => 'Unbekannte Aktion.']);
|
|
}
|
|
|
|
$raidId = (string) ($_GET['raid_id'] ?? '');
|
|
if (!ctype_digit($raidId)) {
|
|
bot_api_reply(400, ['status' => 'error', 'message' => 'raid_id fehlt.']);
|
|
}
|
|
|
|
$discordIds = array_values(array_filter(
|
|
array_map('trim', explode(',', (string) ($_GET['discord_ids'] ?? ''))),
|
|
static fn (string $id): bool => $id !== '' && ctype_digit($id)
|
|
));
|
|
|
|
// Der Raid-Lead ist fuer die Anwesenheit zustaendig
|
|
$leadStmt = db()->prepare(
|
|
"SELECT u.discord_id FROM raid_settings s JOIN users u ON u.id = s.lead_user_id
|
|
WHERE s.raid_id = ? AND u.status = 'active' AND u.discord_id IS NOT NULL"
|
|
);
|
|
$leadStmt->execute([$raidId]);
|
|
$leadDiscordId = $leadStmt->fetchColumn();
|
|
|
|
$recipients = [];
|
|
if ($leadDiscordId !== false && $leadDiscordId !== null) {
|
|
$recipients = [(string) $leadDiscordId];
|
|
} elseif (!empty($discordIds)) {
|
|
$placeholders = implode(',', array_fill(0, count($discordIds), '?'));
|
|
$stmt = db()->prepare(
|
|
"SELECT DISTINCT u.discord_id FROM users u
|
|
WHERE u.status = 'active' AND u.discord_id IN ($placeholders)
|
|
AND (u.is_admin = 1 OR EXISTS (
|
|
SELECT 1 FROM user_roles ur
|
|
JOIN role_permissions rp ON rp.role_id = ur.role_id
|
|
JOIN permissions p ON p.id = rp.permission_id
|
|
WHERE ur.user_id = u.id AND p.`key` = 'raids.manage'
|
|
) OR EXISTS (
|
|
SELECT 1 FROM user_permissions up
|
|
JOIN permissions p ON p.id = up.permission_id
|
|
WHERE up.user_id = u.id AND p.`key` = 'raids.manage'
|
|
))"
|
|
);
|
|
$stmt->execute($discordIds);
|
|
$recipients = array_map('strval', $stmt->fetchAll(PDO::FETCH_COLUMN));
|
|
}
|
|
|
|
// Raidbeginn: Einstellungen (fester Punkt) auch fuer im Discord erstellte Raids anlegen.
|
|
raid_settings_ensure_defaults([(int) $raidId]);
|
|
$settings = raid_settings_get((int) $raidId);
|
|
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
|
$host = (string) ($_SERVER['HTTP_HOST'] ?? '');
|
|
|
|
bot_api_reply(200, [
|
|
'status' => 'success',
|
|
'recipients' => $recipients,
|
|
// Schon kontrolliert (z.B. vor Raidbeginn)? Dann braucht es keine Erinnerung mehr.
|
|
'checked' => $settings['attendance_checked_at'] !== null,
|
|
'url' => $scheme . '://' . $host . '/raid_attendance.php?raid=' . $raidId,
|
|
]);
|