Asked for: "bei den Legionsbeiträgen soll der bot auch die leute drauf erinnern dass ihr beitrag fällig ist ...
die nachricht ist frei definierbar über die website (mit markierungen und erwähnungen) ... eine standardnachricht,
welche zur Legion passt" and "es soll wenn man die seite aufruft standardmäßig die von uns definierte reihenfolge
angezeigt werden".
Dues reminders (includes/dues_reminders.php, admin/dues.php "Erinnerungen per Discord"):
- Who: everyone still open in the running cycle with a linked Discord - not who paid, is exempt or sits in a
suspended cycle. Automatic (switch, off by default) at the start of the cycle and/or N days before its end, at
a set hour (settings dues_remind_*); a missed moment is caught up for 24 hours at most, so switching it on in the
middle of a cycle sends nothing. "Jetzt erinnern" for everyone open right now and "Testnachricht an mich" with
the text from the form, saved or not.
- The text is free: Discord formatting, placeholders {name}, {erwähnung}, {betrag}, {zyklus}, {bis}, mentions of
members and channels (channel list from the bot API), toolbar and live preview with the own values
(assets/js/dues-remind.js). The default text greets with "Arieluma" and is stored empty so improvements arrive.
- Flow: the bot (new cogs/dues_reminders.py, already deployed) asks bot_api.php?action=dues_reminders every minute;
the website queues due reminders in dues_reminders (at most once per member, cycle and kind) and hands out the
waiting ones with the finished text, the bot sends them without pings and reports back via
action=dues_reminders_done, then logs to the log channel. The text is dropped after sending, the log stays 90
days. The section lists the runs of the running cycle with delivered and not deliverable (with reason).
- Schema version 64 (table also in sql/schema.sql); privacy policy (what is stored, the bot, retention), data export
section, account deletion, data reset, audit log; patch notes and README.
Premades:
- The page opens in the order the leadership set: own premades are no longer pulled to the top. A chosen sort only
lives in the address (?sort=) - it survives a reload, not a new visit; the former browser entry
lumina_premades_sort is removed (and left the privacy policy). Patch notes of the sort and order entries adjusted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
6.2 KiB
PHP
135 lines
6.2 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=...
|
|
*
|
|
* Legionsbeitraege (cogs/dues_reminders.py im Bot, includes/dues_reminders.php): Der Bot holt jede Minute die
|
|
* Erinnerungen ab, die er per PN verschicken soll (mit fertigem Text), und meldet danach zurueck, was angekommen ist.
|
|
* GET /bot_api.php?action=dues_reminders
|
|
* POST /bot_api.php?action=dues_reminders_done {"results": [{"id": 1, "ok": true}, {"id": 2, "ok": false, "error": "..."}]}
|
|
*/
|
|
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 === 'dues_reminders' || $action === 'dues_reminders_done') {
|
|
require_once __DIR__ . '/includes/raids_api.php';
|
|
require_once __DIR__ . '/includes/dues_reminders.php';
|
|
try {
|
|
if ($action === 'dues_reminders') {
|
|
$guildId = 0;
|
|
try {
|
|
$guildId = reports_guild_id(); // fuer den Log-Kanal
|
|
} catch (Throwable $e) {
|
|
// ohne Log-Kanal geht es auch
|
|
}
|
|
bot_api_reply(200, ['status' => 'success', 'guild_id' => (string) $guildId, 'reminders' => dues_remind_poll()]);
|
|
}
|
|
$body = json_decode((string) file_get_contents('php://input'), true);
|
|
bot_api_reply(200, ['status' => 'success', 'done' => dues_remind_done(is_array($body['results'] ?? null) ? $body['results'] : [])]);
|
|
} catch (PDOException $e) {
|
|
// Tabelle kommt erst mit dem naechsten Schema-Abgleich (beim ersten Seitenaufruf nach dem Hochladen)
|
|
bot_api_reply(503, ['status' => 'error', 'message' => 'Die Erinnerungen an die Legionsbeiträge sind noch nicht eingerichtet.']);
|
|
}
|
|
}
|
|
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,
|
|
]);
|