game-rt.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function getRandomColor() {
  2. const random = Math.random() * 100;
  3. if (random < 47.5) return 'red';
  4. if (random < 95) return 'black';
  5. return 'green';
  6. }
  7. function formatExp(amount) {
  8. if (amount >= 1000) return `${(amount / 1000).toFixed(1)}k (${amount.toLocaleString()})`;
  9. return amount.toLocaleString();
  10. }
  11. async function handler(m, { conn, args, command, usedPrefix }) {
  12. let user = global.db.data.users[m.sender];
  13. if (args.length < 2) return conn.reply(m.chat, `⚠️ Formato incorrecto. Usa: ${usedPrefix + command} <color> <cantidad>\n\nEjemplo: ${usedPrefix + command} black 100`, m);
  14. const color = args[0].toLowerCase();
  15. const betAmount = parseInt(args[1]);
  16. if (!['red', 'black', 'green'].includes(color)) return conn.reply(m.chat, 'Color no válido. Usa "red", "black" o "green".', m);
  17. if (isNaN(betAmount) || betAmount <= 0) return conn.reply(m.chat, 'Cantidad no válida. Debe ser un número positivo.', m);
  18. if (!user || user.exp < betAmount) return conn.reply(m.chat, 'No tienes suficiente exp para apostar.', m);
  19. const resultColor = getRandomColor();
  20. const isWin = resultColor === color;
  21. let winAmount = 0;
  22. if (isWin) {
  23. if (color === 'green') {
  24. winAmount = betAmount * 14;
  25. } else {
  26. winAmount = betAmount;
  27. }}
  28. user.exp = (user.exp || 0) - betAmount + winAmount;
  29. conn.reply(m.chat, `😱 La ruleta cayó en *${resultColor}* y ${isWin ? 'ganaste' : 'perdiste'} *${formatExp(isWin ? winAmount : betAmount)}* exp.`, m);
  30. }
  31. handler.help = ['rt <color> <cantidad>'];
  32. handler.tags = ['game'];
  33. handler.command = ['rt'];
  34. handler.register = true;
  35. export default handler;