𝗗𝗔𝗥𝗥𝗘𝗟𝗟 𝗠𝗨𝗖𝗛𝗘𝗥𝗜 ⚡ commited on
Commit
7e5a36b
·
unverified ·
1 Parent(s): a9ce139

Update update.js

Browse files
Files changed (1) hide show
  1. plugins/update.js +19 -18
plugins/update.js CHANGED
@@ -1,11 +1,6 @@
1
- // SUBZERO PROPERTY
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
- await conn.sendMessage(from, { text: '*✅ SubZero Updated successfully!*' }, { quoted: mek });
 
 
 
 
 
 
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
  });