fix: correct win/loss stats in /mijn

- Filter alleen completed matches (confirmed = nog niet gespeeld)
- Win obv team1 (winnend team) / team2 (verliezend team)
- Draw ondersteuning (gelijke sets, 1-1)
- Geen afhankelijkheid van score.winner veld (bestaat niet in API)
This commit is contained in:
Nova Coder
2026-05-25 08:00:32 +00:00
parent 91c5403fcb
commit 208fbe08a5
+15 -9
View File
@@ -222,19 +222,25 @@ bot.onText(/\/mijn(@padel_nl_bot)?/, async (msg) => {
const matches = await api('/matches');
if (!Array.isArray(matches)) throw new Error('Invalid matches response');
// Alleen completed matches tellen (confirmed = nog niet gespeeld)
const playerMatches = matches.filter(m =>
m.players && m.players.some(pid => pid == player.id) &&
(m.status === 'completed' || m.status === 'confirmed')
m.status === 'completed'
);
const won = playerMatches.filter(m => {
if (!m.score || !m.score.winner) return false;
return m.score.winner === 1 ?
(m.score.team1 || []).some(pid => pid == player.id) :
(m.score.team2 || []).some(pid => pid == player.id);
}).length;
// Win/loss/draw obv sets: score heeft team1 (winnaar) en team2 (verliezer),
// of bij gelijk aantal sets (1-1) is het een draw
let won = 0, lost = 0, draw = 0;
for (const m of playerMatches) {
if (!m.score || !m.score.team1 || !m.score.team2) continue;
const inTeam1 = (m.score.team1 || []).some(pid => pid == player.id);
const inTeam2 = (m.score.team2 || []).some(pid => pid == player.id);
// team1 = winnende team, team2 = verliezende team (zie submitScore logic)
if (inTeam1) won++;
else if (inTeam2) lost++;
else draw++; // speler zit niet in winning/losing team (unlikely)
}
const played = playerMatches.length;
const lost = played - won;
const sessions = await api('/sessions') || [];
const playerSessions = (sessions || []).filter(s =>
@@ -255,7 +261,7 @@ bot.onText(/\/mijn(@padel_nl_bot)?/, async (msg) => {
msg += '👤 ' + player.name + '\n';
msg += '🎯 Niveau: ' + level + ' | Positie: ' + position + '\n';
msg += '🔑 PIN: `' + player.pin + '`\n\n';
msg += '🎾 Wedstrijden: ' + played + ' (' + won + '⚡ win / ' + lost + '❌ verlies)\n';
msg += '🎾 Wedstrijden: ' + played + ' (' + won + '⚡ win / ' + lost + '❌ verlies' + (draw > 0 ? ' / ' + draw + '🤝 draw' : '') + ')\n';
msg += '⏱️ Totaal uren: ' + Math.round(totalHours * 10) / 10 + 'h\n';
msg += '\n[Wijzig profiel](https://padel.iamdoingthings.com) — je PIN is je inlogcode.';