diff --git a/bot.js b/bot.js index cac88ec..d88891f 100644 --- a/bot.js +++ b/bot.js @@ -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.';