forked from noureddineouafy/bobizaa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a919c8
commit 1e6c25d
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |