fun-adivinar.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import fs from 'fs';
  2. import fetch from 'node-fetch';
  3. import similarity from 'similarity';
  4. import axios from 'axios';
  5. let timeout = 30000; //30s
  6. let timeout2 = 10000; //10s
  7. let poin = 500;
  8. const threshold = 0.72;
  9. let juegos = {};
  10. let handler = async (m, { conn, command, usedPrefix }) => {
  11. let id = m.chat;
  12. if (juegos[id]) return conn.reply(m.chat, '⚠️ ¡Ya hay un juego en curso en este chat! Responde primero.', m);
  13. try {
  14. // ---------- Adivina acertijos ----------
  15. if (/^(acertijo|acert|adivinanza|tekateki)$/i.test(command)) {
  16. let acertijos = JSON.parse(fs.readFileSync(`./src/game/acertijo.json`));
  17. let pregunta = acertijos[Math.floor(Math.random() * acertijos.length)];
  18. let caption = `${pregunta.question}
  19. *• Tiempo:* ${(timeout / 1000)}s
  20. *• Premio:* +${poin} XP`
  21. let enviado = await conn.sendMessage(m.chat, { text: caption, contextInfo:{forwardingScore: 9999999, isForwarded: true, "externalAdReply": {"showAdAttribution": true, "containsAutoReply": true, "body": `• 𝐀𝐂𝐄𝐍𝐓𝐈𝐉𝐎 •`, "previewType": "PHOTO", thumbnail: imagen1, sourceUrl: md}}}, { quoted: m, ephemeralExpiration: 24*60*100, disappearingMessagesInChat: 24*60*100})
  22. juegos[id] = { tipo: 'acertijo',
  23. pregunta,
  24. caption: enviado,
  25. puntos: poin,
  26. timeout: setTimeout(() => {
  27. if (juegos[id]) {
  28. conn.reply(m.chat, `*👾 Perdiste*\n\nSe acabó el tiempo!`, enviado);
  29. delete juegos[id];
  30. }}, timeout)
  31. }}
  32. // ---------- Adivina la Película ----------
  33. if (/^(advpe|adv|peliculas|pelicula)$/i.test(command)) {
  34. let tekateki = JSON.parse(fs.readFileSync(`./src/game/peliculas.json`));
  35. let json = tekateki[Math.floor(Math.random() * tekateki.length)];
  36. let clue = json.response.replace(/[A-Za-z]/g, '_');
  37. let caption = `
  38. ${json.question}
  39. *• Tiempo:* ${(timeout / 1000)}s
  40. *• Bono:* +${poin} XP`
  41. let enviado = await conn.sendMessage(m.chat, { text: caption, contextInfo:{forwardingScore: 9999999, isForwarded: true, "externalAdReply": {"showAdAttribution": true, "containsAutoReply": true, "title": "🎬 ADIVINAN", "body": `LA PELÍCULA CON EMOJIS •`, "previewType": "PHOTO", thumbnail: imagen1, sourceUrl: md}}}, { quoted: m, ephemeralExpiration: 24*60*100, disappearingMessagesInChat: 24*60*100})
  42. juegos[id] = { tipo: 'pelicula',
  43. pregunta: json,
  44. caption: enviado,
  45. puntos: poin,
  46. timeout: setTimeout(() => {
  47. if (juegos[id]) {
  48. conn.reply(m.chat, `⏳ ¡Tiempo agotado! La respuesta era: *${json.response}*`, enviado);
  49. delete juegos[id];
  50. }}, timeout)
  51. }}
  52. // ---------- Adivina trivia ----------
  53. if (/^(trivia|triviador)$/i.test(command)) {
  54. let tekateki = JSON.parse(fs.readFileSync(`./src/game/trivia.json`));
  55. let json = tekateki[Math.floor(Math.random() * tekateki.length)];
  56. let clue = json.response.replace(/[A-Za-z]/g, '_');
  57. let caption = `
  58. ${json.question}
  59. *• Tiempo:* ${(timeout2 / 1000)}s
  60. *• Bono:* +${poin} XP`
  61. let enviado = await conn.sendMessage(m.chat, { text: caption, contextInfo:{forwardingScore: 9999999, isForwarded: true, "externalAdReply": {"showAdAttribution": true, "containsAutoReply": true, "body": `• 𝐓𝐑𝐈𝐕𝐈𝐀 •`, "previewType": "PHOTO", thumbnail: imagen1, sourceUrl: md}}}, { quoted: m, ephemeralExpiration: 24*60*100, disappearingMessagesInChat: 24*60*100})
  62. juegos[id] = { tipo: 'trivia',
  63. pregunta: json,
  64. caption: enviado,
  65. puntos: poin,
  66. timeout2: setTimeout(() => {
  67. if (juegos[id]) {
  68. conn.reply(m.chat, `*👾 Perdiste*\n\nSe acabó el tiempo!`, enviado);
  69. delete juegos[id];
  70. }}, timeout2)
  71. }}
  72. } catch (e) {
  73. console.log(e);
  74. }};
  75. handler.before = async (m) => {
  76. let id = m.chat;
  77. if (!juegos[id] || !m.quoted || !m.quoted.fromMe || !m.quoted.id) return;
  78. let juego = juegos[id];
  79. if (m.quoted.id !== juego.caption.key.id) return;
  80. if (juego.tipo === 'acertijo') {
  81. let respuestaCorrecta = juego.pregunta.response.toLowerCase().trim();
  82. let respuestaUsuario = m.text.toLowerCase().trim();
  83. if (respuestaUsuario === respuestaCorrecta) {
  84. global.db.data.users[m.sender].exp += juego.puntos;
  85. m.reply(`✅ *¡Correcto!*\nGanaste +${juego.puntos} XP`);
  86. m.react("✅")
  87. clearTimeout(juego.timeout);
  88. delete juegos[id];
  89. } else if (similarity(respuestaUsuario, respuestaCorrecta) >= threshold) {
  90. m.reply(`🔥 *Casi!* La respuesta es muy parecida.`);
  91. } else {
  92. m.react("❌")
  93. m.reply(`❌ *Incorrecto!* Intenta de nuevo.`);
  94. }}
  95. if (juego.tipo === 'cancion') {
  96. let respuestaCorrecta = juego.pregunta.jawaban.toLowerCase().trim();
  97. let respuestaUsuario = m.text.toLowerCase().trim();
  98. if (respuestaUsuario === respuestaCorrecta) {
  99. global.db.data.users[m.sender].exp += juego.puntos;
  100. m.reply(`✅ *¡Correcto!*\nGanaste +${juego.puntos} XP`);
  101. m.react("✅️")
  102. clearTimeout(juego.timeout);
  103. delete juegos[id];
  104. } else if (similarity(respuestaUsuario, respuestaCorrecta) >= threshold) {
  105. m.reply(`🎶 *Casi!* Intenta de nuevo.`);
  106. } else {
  107. m.reply(`❌ *Incorrecto!*`);
  108. m.react("❌")
  109. }}
  110. if (juego.tipo === 'pelicula') {
  111. let respuestaCorrecta = juego.pregunta.response.toLowerCase().trim();
  112. let respuestaUsuario = m.text.toLowerCase().trim();
  113. if (respuestaUsuario === respuestaCorrecta) {
  114. global.db.data.users[m.sender].exp += juego.puntos;
  115. m.reply(`🎬 ✅ *¡Correcto!*\nGanaste +${juego.puntos} XP`);
  116. m.react("✅️")
  117. clearTimeout(juego.timeout);
  118. delete juegos[id];
  119. } else if (similarity(respuestaUsuario, respuestaCorrecta) >= threshold) {
  120. m.reply(`🎥 *Casi!* La respuesta es muy parecida.`);
  121. } else {
  122. m.reply(`❌ *Incorrecto!*`);
  123. m.react("❌")
  124. }}
  125. if (juego.tipo === 'trivia') {
  126. let respuestaCorrecta = juego.pregunta.response.toLowerCase().trim();
  127. let respuestaUsuario = m.text.toLowerCase().trim();
  128. if (respuestaUsuario === respuestaCorrecta) {
  129. global.db.data.users[m.sender].exp += juego.puntos;
  130. m.reply(`🎉 ✅ *¡Correcto!*\nGanaste +${juego.puntos} XP`);
  131. m.react("✅️")
  132. clearTimeout(juego.timeout);
  133. delete juegos[id];
  134. } else if (similarity(respuestaUsuario, respuestaCorrecta) >= threshold) {
  135. //m.reply(`💡 *Casi!* Intenta de nuevo.`);
  136. m.react("🤏")
  137. } else {
  138. m.react("❌")
  139. }}
  140. };
  141. handler.help = ['acertijo', 'cancion', 'advpe', 'adv', 'peliculas', 'pelicula', 'trivia', 'triviador'];
  142. handler.tags = ['game'];
  143. handler.command = /^(acertijo|acert|adivinanza|tekateki|cancion|canción|advpe|adv|peliculas|pelicula|trivia|triviador)$/i;
  144. handler.register = true;
  145. export default handler;
  146. async function fetchJson(url, options) {
  147. try {
  148. options ? options : {};
  149. const res = await axios({method: 'GET', url: url, headers: {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'}, ...options});
  150. return res.data;
  151. } catch (err) {
  152. return err;
  153. }
  154. }