-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
3f84e69
commit 86e28c3
Showing
1 changed file
with
57 additions
and
21 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 |
---|---|---|
@@ -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; |