owner-update.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { execSync } from 'child_process';
  2. const handler = async (m, { conn, text }) => {
  3. try {
  4. const stdout = execSync('git pull' + (m.fromMe && text ? ' ' + text : ''));
  5. let messager = stdout.toString()
  6. if (messager.includes('Already up to date.')) messager = `⚠️ 𝙔𝘼 𝙀𝙎𝙏𝘼 𝘼𝘾𝙏𝙐𝘼𝙇𝙄𝙕𝘼𝘿𝙊 𝘼 𝙇𝘼 𝙑𝙀𝙍𝙎𝙄𝙊́𝙉 𝙍𝙀𝘾𝙄𝙀𝙉𝙏𝙀.`
  7. if (messager.includes('Updating')) messager = `*[ UPDATE ]*\n\n` + stdout.toString()
  8. conn.reply(m.chat, messager, m);
  9. } catch {
  10. try {
  11. const status = execSync('git status --porcelain');
  12. if (status.length > 0) {
  13. const conflictedFiles = status
  14. .toString()
  15. .split('\n')
  16. .filter(line => line.trim() !== '')
  17. .map(line => {
  18. if (line.includes('.npm/') || line.includes('.cache/') || line.includes('tmp/') || line.includes('BotSession/') || line.includes('npm-debug.log')) {
  19. return null;
  20. }
  21. return '*→ ' + line.slice(3) + '*'})
  22. .filter(Boolean);
  23. if (conflictedFiles.length > 0) {
  24. const errorMessage = `⚠️ Error\n> *Se han encontrado cambios locales en los archivos del bot que entran en conficto con las nuevas actualizaciones del repositorio. para actualizar, reinstalar el bot o realizar las actualizaciones manualmente.*\n\n*\`ARCHIVO EN CONFLICTO :\`*\n\n${conflictedFiles.join('\n')}.*`
  25. await conn.reply(m.chat, errorMessage, m);
  26. }}
  27. } catch (error) {
  28. console.error(error);
  29. if (error.message) {
  30. const errorMessage2 = `\n${fg}` + error.message;
  31. }
  32. await m.reply(`${fg}`)
  33. }}};
  34. handler.help = ['update']
  35. handler.tags = ['owner']
  36. handler.command = /^(update|actualizar|gitpull)$/i;
  37. handler.rowner = true;
  38. export default handler;