Spaces:
Paused
Paused
𝗗𝗔𝗥𝗥𝗘𝗟𝗟 𝗠𝗨𝗖𝗛𝗘𝗥𝗜 ⚡
commited on
Update update.js
Browse files- plugins/update.js +19 -18
plugins/update.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
const config = require('../config');
|
| 6 |
-
let fs = require('fs');
|
| 7 |
const { exec } = require('child_process');
|
| 8 |
-
const { cmd } = require('../command');
|
| 9 |
|
| 10 |
cmd({
|
| 11 |
pattern: "update",
|
|
@@ -16,34 +11,40 @@ cmd({
|
|
| 16 |
filename: __filename
|
| 17 |
}, async (conn, mek, m, { from, reply }) => {
|
| 18 |
try {
|
| 19 |
-
const repoUrl = 'https://github.com/mrfrank-ofc/SUBZERO-MD.git'; //
|
| 20 |
-
const targetFolder = 'plugins'; //
|
| 21 |
|
| 22 |
-
//
|
| 23 |
if (!fs.existsSync(targetFolder)) {
|
| 24 |
-
fs.mkdirSync(targetFolder); //
|
| 25 |
}
|
| 26 |
|
| 27 |
-
//
|
| 28 |
const gitCommand = fs.existsSync(`${targetFolder}/.git`)
|
| 29 |
? `git -C ${targetFolder} pull`
|
| 30 |
: `git clone ${repoUrl} ${targetFolder}`;
|
| 31 |
|
| 32 |
-
//
|
| 33 |
-
await new Promise((resolve, reject) => {
|
| 34 |
exec(gitCommand, (err, stdout, stderr) => {
|
| 35 |
if (err) {
|
| 36 |
-
reject(`Git command failed: ${stderr}`);
|
| 37 |
} else {
|
| 38 |
resolve(stdout);
|
| 39 |
}
|
| 40 |
});
|
| 41 |
});
|
| 42 |
|
| 43 |
-
//
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
} catch (error) {
|
| 46 |
-
console.error(error);
|
| 47 |
reply(`*Error during update:* ${error.message}`);
|
| 48 |
}
|
| 49 |
});
|
|
|
|
| 1 |
+
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
const { exec } = require('child_process');
|
| 3 |
+
const { cmd } = require('../command'); // Ensure `cmd` is defined properly in your project
|
| 4 |
|
| 5 |
cmd({
|
| 6 |
pattern: "update",
|
|
|
|
| 11 |
filename: __filename
|
| 12 |
}, async (conn, mek, m, { from, reply }) => {
|
| 13 |
try {
|
| 14 |
+
const repoUrl = 'https://github.com/mrfrank-ofc/SUBZERO-MD.git'; // GitHub repository link
|
| 15 |
+
const targetFolder = 'plugins'; // Folder to be updated
|
| 16 |
|
| 17 |
+
// Check if the target folder exists
|
| 18 |
if (!fs.existsSync(targetFolder)) {
|
| 19 |
+
fs.mkdirSync(targetFolder, { recursive: true }); // Create the folder if it doesn't exist
|
| 20 |
}
|
| 21 |
|
| 22 |
+
// Determine the appropriate git command
|
| 23 |
const gitCommand = fs.existsSync(`${targetFolder}/.git`)
|
| 24 |
? `git -C ${targetFolder} pull`
|
| 25 |
: `git clone ${repoUrl} ${targetFolder}`;
|
| 26 |
|
| 27 |
+
// Execute the git command
|
| 28 |
+
const output = await new Promise((resolve, reject) => {
|
| 29 |
exec(gitCommand, (err, stdout, stderr) => {
|
| 30 |
if (err) {
|
| 31 |
+
reject(new Error(`Git command failed: ${stderr}`));
|
| 32 |
} else {
|
| 33 |
resolve(stdout);
|
| 34 |
}
|
| 35 |
});
|
| 36 |
});
|
| 37 |
|
| 38 |
+
console.log(output); // Log output for debugging
|
| 39 |
+
|
| 40 |
+
// Send success message
|
| 41 |
+
await conn.sendMessage(
|
| 42 |
+
from,
|
| 43 |
+
{ text: '*✅ SubZero Updated successfully!*' },
|
| 44 |
+
{ quoted: mek }
|
| 45 |
+
);
|
| 46 |
} catch (error) {
|
| 47 |
+
console.error(error); // Log error for debugging
|
| 48 |
reply(`*Error during update:* ${error.message}`);
|
| 49 |
}
|
| 50 |
});
|