Skip to content

Commit

Permalink
[ Jessi-md 4.8.4 ⏱️ ]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaweeshachamodx authored Jan 28, 2024
1 parent 3f84e69 commit 86e28c3
Showing 1 changed file with 57 additions and 21 deletions.
78 changes: 57 additions & 21 deletions plugins/_update.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
let { execSync } = require('child_process')
let handler = async (m, { conn, text }) => {
if (global.conn.user.jid == conn.user.jid) {
let stdout = execSync('git pull' + (m.fromMe && text ? ' ' + text : ''))
require('fs').readdirSync('plugins').map(v=>global.reload('', v))
conn.reply(m.chat, stdout.toString(), m)
}
}
handler.help = ['update']
handler.tags = ['host']
handler.command = /^update$/i
handler.owner = true
handler.mods = false
handler.premium = false
handler.group = false
handler.private = false
import { exec } from 'child_process';

let handler = async (m, { conn, usedPrefix, command, isOwner }) => {

try {
const repoOwner = 'whiteshadowofficial'; // https://github.com/whiteshadowofficial/Jessi-md
const repoName = 'Jessi-md';
const branch = 'master'; //masterdefault

m.reply('Checking for updates...');

exec(`git ls-remote https://github.com/${repoOwner}/${repoName}.git ${branch}`, async (error, stdout, stderr) => {
if (error) {
console.error('Update check error:', error);
console.error('Update check stderr:', stderr);
await conn.reply(m.chat, 'Update check failed.', m);
return;
}

const remoteCommit = stdout.trim();
const localCommit = require('child_process').execSync('git rev-parse HEAD').toString().trim();

if (remoteCommit === localCommit) {
await conn.reply(m.chat, '> Jessi-MD is up to date. No updates found.', m);
} else {
await conn.reply(m.chat, 'New updates found! Updating bot...', m);

handler.admin = false
handler.botAdmin = false
exec('git pull origin main', async (updateError, updateStdout, updateStderr) => {
if (updateError) {
console.error('> Jessi-MD update error:', updateError);
console.error('> Jessi-MD update stderr:', updateStderr);
await conn.reply(m.chat, '> Jessi-MD update failed.', m);
return;
}

await conn.reply(m.chat, '> Jessi-MD updated successfully. Restarting...', m);


setTimeout(() => {
conn.send('> Jessi-MD is restarting...');
process.exit(0);
}, 1000);
});
}
});
} catch (err) {
console.error('Update check error:', err);
await conn.reply(m.chat, 'Update check failed.', m);
}
};

handler.help = ['update];
handler.tags = ['misc'];
handler.command = /^(update)$/i;

handler.owner = true
handler.botAdmin = true

handler.fail = null
handler.exp = 0

module.exports = handler

export default handler;

0 comments on commit 86e28c3

Please sign in to comment.