owner-grupo.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. let handler = async (m, { conn, args, text, command }) => {
  2. let fkontak = { "key": { "participants":"[email protected]", "remoteJid": "status@broadcast", "fromMe": false, "id": "Halo" }, "message": { "contactMessage": { "vcard": `BEGIN:VCARD\nVERSION:3.0\nN:Sy;Bot;;;\nFN:y\nitem1.TEL;waid=${conn.user.jid.split('@')[0]}:${conn.user.jid.split('@')[0]}\nitem1.X-ABLabel:Ponsel\nEND:VCARD` }}, "participant": "[email protected]" }
  3. if (!text) throw `*⚠️ Uso correcto del comando:*\n\n*.setcrxs ID_GRUPO|mensaje*\n\n*📝 Ejemplo:*\n.setcrxs [email protected]|Hola a todos\n\n*💡 Para obtener el ID:*\nUse .inspect dentro del grupo deseado`
  4. // Dividir el texto solo por la primera ocurrencia de '|'
  5. let splitIndex = text.indexOf('|');
  6. if (splitIndex === -1) throw '*⚠️ Formato incorrecto. Use: ID_GRUPO|mensaje*';
  7. let groupId = text.substring(0, splitIndex).trim();
  8. let message = text.substring(splitIndex + 1).trim(); // Toma todo el contenido después del primer '|'
  9. if (!groupId || !message) throw '*⚠️ Formato incorrecto. Use: ID_GRUPO|mensaje*'
  10. try {
  11. let status = await conn.reply(m.chat, '*🚀 Iniciando envío del mensaje...*', m)
  12. let success = false
  13. let error = ''
  14. let methodUsed = ''
  15. // Obtener metadata del grupo
  16. let groupMetadata = await conn.groupMetadata(groupId)
  17. let participants = groupMetadata.participants
  18. // Actualizar estado
  19. await conn.sendMessage(m.chat, { text: '*⚡ Probando diferentes métodos de envío...*', edit: status.key })
  20. // Método 1: SendMessage con menciones
  21. try {
  22. await conn.sendMessage(groupId, {
  23. text: message,
  24. mentions: participants.map(v => v.id)
  25. }, { quoted: fkontak })
  26. success = true
  27. methodUsed = 'Mensaje con menciones'
  28. } catch (e) {
  29. error += '❌ Método 1 falló\n'
  30. // Método 2: Reply directo
  31. try {
  32. await conn.reply(groupId, message, null)
  33. success = true
  34. methodUsed = 'Reply directo'
  35. } catch (e) {
  36. error += '❌ Método 2 falló\n'
  37. // Método 3: SendMessage simple
  38. try {
  39. await conn.sendMessage(groupId, { text: message })
  40. success = true
  41. methodUsed = 'Mensaje simple'
  42. } catch (e) {
  43. error += '❌ Método 3 falló\n'
  44. // Método 4: Legacy send
  45. try {
  46. await conn.sendMessage(groupId, message)
  47. success = true
  48. methodUsed = 'Envío legacy'
  49. } catch (e) {
  50. error += '❌ Método 4 falló\n'
  51. // Méto do 5: Envío en partes
  52. try {
  53. const chunkSize = 4096; // Tamaño máximo del mensaje
  54. for (let i = 0; i < message.length; i += chunkSize) {
  55. const chunk = message.substring(i, i + chunkSize);
  56. await conn.sendMessage(groupId, { text: chunk });
  57. }
  58. success = true;
  59. methodUsed = 'Envío en partes';
  60. } catch (e) {
  61. error += '❌ Método 5 falló\n';
  62. }
  63. }
  64. }
  65. }
  66. }
  67. if (success) {
  68. await conn.sendMessage(m.chat, {
  69. text: `*✅ MENSAJE ENVIADO EXITOSAMENTE*\n\n*📝 Detalles:*\n• *Grupo:* ${groupMetadata.subject}\n• *Miembros:* ${participants.length}\n• *Método:* ${methodUsed}\n\n*📄 Mensaje:*\n${message}`,
  70. edit: status.key
  71. });
  72. } else {
  73. throw `*⚠️ No se pudo enviar el mensaje*\n\n${error}\n\n*Posibles causas:*\n- ID de grupo incorrecto\n- Bot no está en el grupo\n- Bot no tiene permisos\n- Grupo no existe`;
  74. }
  75. } catch (e) {
  76. console.log(e);
  77. await conn.sendMessage(m.chat, {
  78. text: `*❌ ERROR AL ENVIAR*\n\n- Verifique el ID del grupo\n- Confirme que el bot esté en el grupo\n- El bot debe tener permisos\n\n*ID usado:* ${groupId}`,
  79. edit: status.key
  80. });
  81. }
  82. }
  83. handler.help = ['setcrxs <groupid|mensaje>'];
  84. handler.tags = ['owner'];
  85. handler.command = /^(setcrxs)$/i;
  86. handler.owner = true;
  87. handler.fail = null;
  88. export default handler;