Skip to content

Commit

Permalink
Create up.js
Browse files Browse the repository at this point in the history
  • Loading branch information
noureddineouafy authored Feb 26, 2024
1 parent 1a919c8 commit 1e6c25d
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions plugins/up.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { exec } from 'child_process';

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

try {
const repoOwner = 'noureddineouafy'; // https://github.com/noureddineouafy/bobizaa
const repoName = 'bobizaa';
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, '> bobiza is up to date. No updates found.', m);
} else {
await conn.reply(m.chat, 'New updates found! Updating bot...', m);

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

await conn.reply(m.chat, '> bobiza 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 = ['up'];
handler.tags = ['owner'];
handler.command = /^(up)$/i;

handler.owner = true


export default handler;

0 comments on commit 1e6c25d

Please sign in to comment.