grupo-config_time.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Creditos a https://github.com/ALBERTO9883/NyanCatBot-MD */
  2. const handler = async (m, {conn, isAdmin, isOwner, args, usedPrefix, command}) => {
  3. if (!(isAdmin || isOwner)) {
  4. global.dfail('admin', m, conn);
  5. throw false;
  6. }
  7. const isClose = {'open': 'not_announcement',
  8. 'buka': 'not_announcement',
  9. 'on': 'not_announcement',
  10. '1': 'not_announcement',
  11. 'close': 'announcement',
  12. 'tutup': 'announcement',
  13. 'off': 'announcement',
  14. '0': 'announcement',
  15. }[(args[0] || '')];
  16. if (isClose === undefined) {
  17. const caption = `*• Ejemplo:*\n${usedPrefix + command} open 1\n${usedPrefix + command} close 1\n\n*• Ejemplo de uso:* ${usedPrefix + command} close 1\n\n> *_🌿 Para que el grupo este cerrado una hora._*`;
  18. m.reply(caption);
  19. throw false;
  20. }
  21. const timeoutset = 86400000 * args[1] / 24;
  22. await conn.groupSettingUpdate(m.chat, isClose).then(async (_)=> {
  23. m.reply(`⚠️ *_Grupo ${isClose == 'announcement' ? 'cerrado' : 'abierto'} ${args[1] ? `durante *${clockString(timeoutset)}_*` : ''}`)});
  24. if (args[1]) {
  25. setTimeout(async () => {
  26. await conn.groupSettingUpdate(m.chat, `${isClose == 'announcement' ? 'not_announcement' : 'announcement'}`).then(async (_)=>{
  27. conn.reply(m.chat, `${isClose == 'not_announcement' ? '*El grupo ha sido cerrado, ¡ahora solo los administradores pueden enviar mensajes!*' : '*El grupo se ha abierto, ¡ahora todos los miembros pueden enviar mensajes!*'}!`);
  28. })}, timeoutset)}};
  29. handler.help = ['grouptime *<open/close>* *<número>*'];
  30. handler.tags = ['group'];
  31. handler.command = /^(grouptime|gctime)$/i;
  32. handler.register = true
  33. handler.botAdmin = true;
  34. handler.group = true;
  35. export default handler;
  36. function clockString(ms) {
  37. const h = Math.floor(ms / 3600000);
  38. const m = Math.floor(ms / 60000) % 60;
  39. const s = Math.floor(ms / 1000) % 60;
  40. console.log({ms, h, m, s});
  41. return [h, m, s].map((v) => v.toString().padStart(2, 0) ).join(':');
  42. }