Show real Discord names in Premades instead of raw user IDs

Members without a linked website account showed as "Discord-Nutzer
<id>" since the site had no way to resolve their name. The bot API's
GET /api/premades now resolves display names via its own Discord
cache (owner_name per premade, name per member) - premade_name_for()
prefers that API-provided name, falling back to the linked website
account and finally the raw ID only if both are unavailable (e.g.
bot offline at request time).

Requires the matching api.py update (Aion2_RaidPlaner, not part of
this repo) to be deployed and the bot restarted, otherwise the API
just omits the new fields and the existing fallbacks apply.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-19 14:06:52 +02:00
parent f8d4d21fed
commit 40acaa7d8b

View file

@ -37,8 +37,14 @@ if (!empty($allDiscordIds)) {
}
}
function premade_name_for(int $discordId, array $namesByDiscordId): string
// Bevorzugt den von der Bot-API aufgeloesten Discord-Anzeigenamen (die API kennt Discord direkt,
// die Website nicht); faellt auf den verknuepften Website-Account und zuletzt auf die rohe
// Discord-ID zurueck, falls beides fehlt (z.B. Bot offline beim API-Aufruf).
function premade_name_for(int $discordId, array $namesByDiscordId, ?string $apiName = null): string
{
if ($apiName !== null && $apiName !== '') {
return $apiName;
}
return $namesByDiscordId[$discordId] ?? ('Discord-Nutzer ' . $discordId);
}
@ -85,7 +91,7 @@ include __DIR__ . '/includes/header.php';
<div class="premade-invite-row">
<div>
Einladung zu <strong><?= e((string) ($invite['name'] ?? '')) ?></strong>
von <?= e(premade_name_for((int) ($invite['owner_id'] ?? 0), $namesByDiscordId)) ?>
von <?= e(premade_name_for((int) ($invite['owner_id'] ?? 0), $namesByDiscordId, $invite['owner_name'] ?? null)) ?>
</div>
<div class="actions">
<form method="post" action="/premade_action.php" class="inline-form">
@ -141,7 +147,7 @@ include __DIR__ . '/includes/header.php';
<div class="raid-header">
<h2>⚔️ <?= e($premadeName) ?></h2>
<div class="badge-group">
<span class="badge">👑 <?= e(premade_name_for($ownerId, $namesByDiscordId)) ?></span>
<span class="badge">👑 <?= e(premade_name_for($ownerId, $namesByDiscordId, $premade['owner_name'] ?? null)) ?></span>
<span class="badge"><?= count($accepted) + 1 ?> Mitglieder</span>
</div>
</div>
@ -149,7 +155,7 @@ include __DIR__ . '/includes/header.php';
<ul class="premade-member-list">
<?php foreach ($accepted as $member): ?>
<li>
<span><?= e(premade_name_for((int) ($member['user_id'] ?? 0), $namesByDiscordId)) ?></span>
<span><?= e(premade_name_for((int) ($member['user_id'] ?? 0), $namesByDiscordId, $member['name'] ?? null)) ?></span>
<?php if ($canManageThis): ?>
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
@ -163,7 +169,7 @@ include __DIR__ . '/includes/header.php';
<?php endforeach; ?>
<?php foreach ($pending as $member): ?>
<li class="premade-member-pending">
<span>⏳ <?= e(premade_name_for((int) ($member['user_id'] ?? 0), $namesByDiscordId)) ?> <span class="text-muted">(Einladung offen)</span></span>
<span>⏳ <?= e(premade_name_for((int) ($member['user_id'] ?? 0), $namesByDiscordId, $member['name'] ?? null)) ?> <span class="text-muted">(Einladung offen)</span></span>
<?php if ($canManageThis): ?>
<form method="post" action="/premade_action.php" class="inline-form">
<?= csrf_field() ?>
@ -214,7 +220,7 @@ include __DIR__ . '/includes/header.php';
<select name="new_owner_id">
<?php foreach ($accepted as $candidate): ?>
<option value="<?= (int) ($candidate['user_id'] ?? 0) ?>">
<?= e(premade_name_for((int) ($candidate['user_id'] ?? 0), $namesByDiscordId)) ?>
<?= e(premade_name_for((int) ($candidate['user_id'] ?? 0), $namesByDiscordId, $candidate['name'] ?? null)) ?>
</option>
<?php endforeach; ?>
</select>