LuminaWebsite/raid_signup_action.php
Maaxxs 17ccd3e26f Discord bot as overview: everything is managed on the website, raid signup in one click
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>
2026-09-25 03:15:55 +02:00

68 lines
2.9 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
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/raids_api.php';
require_permission('raids.view');
$input = read_json_body();
verify_csrf_token($input['csrf_token'] ?? '');
$user = current_user();
if (empty($user['discord_id'])) {
json_response(false, 'Bitte verknüpfe zuerst deinen Discord-Account in "Mein Profil".');
}
$raidId = (int) ($input['raid_id'] ?? 0);
$class = trim((string) ($input['class'] ?? ''));
$groupRaw = $input['group'] ?? null; // null/"auto" = automatische Zuteilung, sonst gewuenschte Gruppe (0 = Bank)
if ($raidId <= 0 || !in_array($class, AION_CLASSES, true)) {
json_response(false, 'Bitte eine Klasse auswählen.');
}
try {
$raid = fetch_raid_by_id($raidId);
if (!$raid) {
json_response(false, 'Raid wurde nicht gefunden.');
}
if (!empty($raid['archived'])) {
json_response(false, 'Dieser Raid ist archiviert. Anmeldungen sind geschlossen.');
}
$groupNames = array_values(array_filter(array_map('trim', explode(',', (string) ($raid['groups'] ?? '')))));
$wish = null;
if ($groupRaw !== null && $groupRaw !== '' && $groupRaw !== 'auto') {
$wish = (int) $groupRaw;
if ($wish < 0 || $wish > count($groupNames)) {
json_response(false, 'Ungültige Gruppe ausgewählt.');
}
}
// Derselbe Name wie bei einer Anmeldung im Discord: der Anzeigename auf dem Server (Nickname),
// nicht der Discord-Kontoname. Ob die Wunschgruppe passt, entscheidet der Bot - wie im Discord.
$signupName = trim((string) ($user['display_name'] ?? '')) !== '' ? (string) $user['display_name'] : (string) $user['discord_username'];
$assigned = raid_signup($raidId, (int) $user['discord_id'], $signupName, $class, $wish);
$assignedGroup = (int) ($assigned['group'] ?? 0);
$assignedGroupLabel = $assignedGroup === 0 ? 'Ersatzbank' : ($groupNames[$assignedGroup - 1] ?? ('Gruppe ' . $assignedGroup));
$reasons = [
'locked' => 'Deine Wunschgruppe ist gesperrt',
'full' => 'Deine Wunschgruppe ist für deine Rolle schon voll',
'cap' => 'Der Raid ist schon voll besetzt',
];
$reason = (string) ($assigned['reason'] ?? '');
if (!empty($assigned['matched_wish']) || !isset($reasons[$reason])) {
$message = 'Du bist angemeldet: ' . $class . ' in ' . $assignedGroupLabel . '.';
if ($assignedGroup === 0 && $wish !== 0) {
$message .= ' Alle passenden Plätze sind belegt – du rückst nach, wenn etwas frei wird.';
}
} else {
$message = $reasons[$reason] . ', daher wurdest du automatisch zugeteilt: ' . $assignedGroupLabel
. '. Melde dich gerne beim Raid-Lead, falls du eine Anpassung möchtest.';
}
json_response(true, $message, [
'group' => $assignedGroup,
'matched_wish' => !empty($assigned['matched_wish']),
]);
} catch (Throwable $e) {
json_response(false, 'Anmeldung fehlgeschlagen: ' . $e->getMessage());
}