feat: /mijn command — DM-only stats/PIN
Voegt /mijn command toe dat in DM: - Player stats toont (matches gewonnen/verloren) - Totale uren toont - PIN, niveau, positie toont - Link naar profielpagina /beschikbaar blijft redirect naar web.
This commit is contained in:
@@ -197,14 +197,75 @@ bot.onText(/\/start(@padel_nl_bot)?/, async (msg) => {
|
|||||||
sendMsg(chatId, 'Hallo ' + name + '! 🏓\n\nWat is je volledige naam?');
|
sendMsg(chatId, 'Hallo ' + name + '! 🏓\n\nWat is je volledige naam?');
|
||||||
});
|
});
|
||||||
|
|
||||||
// /beschikbaar, /mijn — redirect naar web
|
// /beschikbaar — redirect naar web
|
||||||
bot.onText(/\/beschikbaar(@padel_nl_bot)?|\/mijn(@padel_nl_bot)?/, async (msg) => {
|
bot.onText(/\/beschikbaar(@padel_nl_bot)?/, async (msg) => {
|
||||||
const chatId = msg.chat.id;
|
const chatId = msg.chat.id;
|
||||||
sendMsg(chatId, '🌐 **Ga naar de webpagina** voor beschikbaarheid en profiel:\nhttps://padel.iamdoingthings.com\n\nLog in met je PIN (die je kreeg bij registratie).',
|
sendMsg(chatId, '🌐 **Ga naar de webpagina** voor beschikbaarheid:\nhttps://padel.iamdoingthings.com',
|
||||||
{ parse_mode: 'Markdown', disable_web_page_preview: true }
|
{ parse_mode: 'Markdown', disable_web_page_preview: true }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// /mijn — DM-only stats + PIN
|
||||||
|
bot.onText(/\/mijn(@padel_nl_bot)?/, async (msg) => {
|
||||||
|
const chatId = msg.chat.id;
|
||||||
|
if (!isDM(msg)) {
|
||||||
|
return sendMsg(chatId, '📊 **Jouw stats** zijn alleen in DM zichtbaar.\n\nStuur /mijn naar [@padel_nl_bot](https://t.me/padel_nl_bot)',
|
||||||
|
{ parse_mode: 'Markdown' }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const players = await api('/players');
|
||||||
|
if (!Array.isArray(players)) throw new Error('Invalid players response');
|
||||||
|
const player = players.find(p => p.telegram_id == chatId);
|
||||||
|
if (!player) return sendMsg(chatId, 'Je bent niet geregistreerd. Stuur /start om te beginnen.');
|
||||||
|
|
||||||
|
const matches = await api('/matches');
|
||||||
|
if (!Array.isArray(matches)) throw new Error('Invalid matches response');
|
||||||
|
|
||||||
|
const playerMatches = matches.filter(m =>
|
||||||
|
m.players && m.players.some(pid => pid == player.id) &&
|
||||||
|
(m.status === 'completed' || m.status === 'confirmed')
|
||||||
|
);
|
||||||
|
|
||||||
|
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;
|
||||||
|
const played = playerMatches.length;
|
||||||
|
const lost = played - won;
|
||||||
|
|
||||||
|
const sessions = await api('/sessions') || [];
|
||||||
|
const playerSessions = (sessions || []).filter(s =>
|
||||||
|
s.players && s.players.some(pid => pid == player.id || pid === player.id)
|
||||||
|
);
|
||||||
|
const totalHours = playerSessions.reduce((sum, s) => {
|
||||||
|
const start = s.start || (s.data || {}).start || "00:00";
|
||||||
|
const end = s.end || (s.data || {}).end || "00:00";
|
||||||
|
const [sh, sm] = start.split(":").map(Number);
|
||||||
|
const [eh, em] = end.split(":").map(Number);
|
||||||
|
return sum + ((eh + em / 60) - (sh + sm / 60));
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
const level = player.level || 'onbekend';
|
||||||
|
const position = player.position || 'onbekend';
|
||||||
|
|
||||||
|
let msg = '📊 **Jouw Statistieken**\n\n';
|
||||||
|
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 += '⏱️ Totaal uren: ' + Math.round(totalHours * 10) / 10 + 'h\n';
|
||||||
|
msg += '\n[Wijzig profiel](https://padel.iamdoingthings.com) — je PIN is je inlogcode.';
|
||||||
|
|
||||||
|
sendMsg(chatId, msg, { parse_mode: 'Markdown' });
|
||||||
|
} catch (e) {
|
||||||
|
logError('/mijn error:', e.message);
|
||||||
|
sendMsg(chatId, '❌ Kon stats niet laden. Probeer later opnieuw.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// /matches — openstaande matches
|
// /matches — openstaande matches
|
||||||
bot.onText(/\/matches(@padel_nl_bot)?/, async (msg) => {
|
bot.onText(/\/matches(@padel_nl_bot)?/, async (msg) => {
|
||||||
const chatId = msg.chat.id;
|
const chatId = msg.chat.id;
|
||||||
|
|||||||
Reference in New Issue
Block a user