// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs-extra"); const execSync = require("child_process").execSync; const dirBootLogTemp = `${__dirname}/tmp/rebootUpdated.txt`; module.exports = { config: { name: "update", version: "2.0.0", author: "Mᴜɴᴛᴀsɪʀ Aѕɪғ", role: 2, description: { en: "Premium chatbot update manager." }, category: "owner", guide: { en: "{pn}" } }, langs: { en: { noUpdates: `╭━━━〔 ✨ 𝗨𝗣𝗗𝗔𝗧𝗘 〕━━━╮ ┃ ┃ ᴠᴇʀsɪᴏɴ: 𝙑%1 ┃ ┃ ✅ 𝗬𝗼𝘂'𝗿𝗲 𝗨𝗽 𝘁𝗼 𝗗𝗮𝘁𝗲! ┃ ┃ 💎 Your bot is already ┃ running the latest version. ┃ ╰━━━━━━━━━━━━━━━━━━╯`, updatePrompt: `╭━━━〔 🚀 𝗕𝗢𝗧 𝗨𝗣𝗗𝗔𝗧𝗘 〕━━━╮ ┃ ┃ 💻 𝗖𝘂𝗿𝗿𝗲𝗻𝘁 : 𝙑%1 ┃ ✨ 𝗟𝗮𝘁𝗲𝘀𝘁 : 𝙑%2 ┃ ┃ 📦 𝗙𝗶𝗹𝗲𝘀 𝘁𝗼 𝗨𝗽𝗱𝗮𝘁𝗲: %3 %4 ┃ ┃ 🔗 𝗖𝗵𝗮𝗻𝗴𝗲𝗹𝗼𝗴: ┃ github.com/ntkhang03/Goat-Bot-V2 ┃ ╰━━━━━━━━━━━━━━━━━━╯ 💡 𝗥𝗲𝗮𝗰𝘁 𝘁𝗼 𝘁𝗵𝗶𝘀 𝗺𝗲𝘀𝘀𝗮𝗴𝗲 𝘁𝗼 𝗰𝗼𝗻𝗳𝗶𝗿𝗺.`, fileWillDelete: `┃ ┃ 🗑️ 𝗙𝗶𝗹𝗲𝘀 𝘁𝗼 𝗗𝗲𝗹𝗲𝘁𝗲: %1`, andMore: "┃ ...and %1 more files", updateConfirmed: `╭━━━〔 ⚡ 𝗨𝗣𝗗𝗔𝗧𝗜𝗡𝗚 〕━━━╮ ┃ ┃ 🚀 𝗖𝗼𝗻𝗳𝗶𝗿𝗺𝗲𝗱! ┃ ┃ 📥 Downloading latest files... ┃ ⚙️ Installing updates... ┃ 💎 Please wait... ╰━━━━━━━━━━━━━━━━━━╯`, updateComplete: `╭━━━〔 ✅ 𝗨𝗣𝗗𝗔𝗧𝗘 𝗗𝗢𝗡𝗘 〕━━━╮ ┃ ┃ 🎉 𝗨𝗽𝗱𝗮𝘁𝗲 𝗖𝗼𝗺𝗽𝗹𝗲𝘁𝗲! ┃ ┃ 🔄 Restart the chatbot now? ┃ ┃ 💬 Reply with: ┃ • 𝘆𝗲𝘀 ┃ • 𝘆 ┃ ╰━━━━━━━━━━━━━━━━━━╯`, updateTooFast: `╭━━━〔 ⏳ 𝗣𝗟𝗘𝗔𝗦𝗘 𝗪𝗔𝗜𝗧 〕━━━╮ ┃ ┃ ⚠️ The latest update was ┃ released only %1m %2s ago. ┃ ┃ 🔒 Update temporarily locked. ┃ ┃ ⏰ Try again after: ┃ %3m %4s ┃ ╰━━━━━━━━━━━━━━━━━━╯`, botWillRestart: `╭━━━〔 🔄 𝗥𝗘𝗦𝗧𝗔𝗥𝗧𝗜𝗡𝗚 〕━━━╮ ┃ ┃ ⚡ 𝗕𝗼𝘁 𝗥𝗲𝘀𝘁𝗮𝗿𝘁 𝗜𝗻𝗶𝘁𝗶𝗮𝘁𝗲𝗱 ┃ ┃ 💎 Please wait... ┃ 🚀 See you after restart! ╰━━━━━━━━━━━━━━━━━━╯` } }, onLoad: async function ({ api }) { if (fs.existsSync(dirBootLogTemp)) { const threadID = fs.readFileSync( dirBootLogTemp, "utf-8" ); fs.removeSync(dirBootLogTemp); api.sendMessage( `╭━━━〔 ✅ 𝗕𝗢𝗧 𝗢𝗡𝗟𝗜𝗡𝗘 〕━━━╮ ┃ ┃ 🔄 Restart completed successfully. ┃ ┃ 🚀 𝗦𝘆𝘀𝘁𝗲𝗺: Online ┃ 💎 𝗦𝘁𝗮𝘁𝘂𝘀: Ready ╰━━━━━━━━━━━━━━━━━━╯`, threadID ); } }, onStart: async function ({ message, getLang, commandName, event }) { try { const { data: { version } } = await axios.get( "https://raw.githubusercontent.com/ntkhang03/Goat-Bot-V2/main/package.json" ); const { data: versions } = await axios.get( "https://raw.githubusercontent.com/ntkhang03/Goat-Bot-V2/main/versions.json" ); const currentVersion = require("../../package.json").version; if (compareVersion(version, currentVersion) < 1) { return message.reply( getLang("noUpdates", currentVersion) ); } const currentIndex = versions.findIndex( v => v.version == currentVersion ); const newVersions = versions.slice(currentIndex + 1); let fileWillUpdate = [ ...new Set( newVersions .map(v => Object.keys(v.files || {})) .flat() ) ] .sort() .filter(f => f?.length); const totalUpdate = fileWillUpdate.length; fileWillUpdate = fileWillUpdate .slice(0, 10) .map(file => `┃ 📄 ${file}`) .join("\n"); let fileWillDelete = [ ...new Set( newVersions .map(v => Object.keys(v.deleteFiles || {})) .flat() ) ] .sort() .filter(f => f?.length); const totalDelete = fileWillDelete.length; fileWillDelete = fileWillDelete .slice(0, 10) .map(file => `┃ 🗑️ ${file}`) .join("\n"); message.reply( getLang( "updatePrompt", currentVersion, version, fileWillUpdate + (totalUpdate > 10 ? "\n" + getLang( "andMore", totalUpdate - 10 ) : ""), totalDelete > 0 ? getLang( "fileWillDelete", fileWillDelete + (totalDelete > 10 ? "\n" + getLang( "andMore", totalDelete - 10 ) : "") ) : "" ), (err, info) => { if (err) return console.error(err); global.GoatBot.onReaction.set( info.messageID, { messageID: info.messageID, threadID: info.threadID, authorID: event.senderID, commandName } ); } ); } catch (error) { console.error("Update check error:", error); return message.reply( `╭━━━〔 ❌ 𝗨𝗣𝗗𝗔𝗧𝗘 𝗘𝗥𝗥𝗢𝗥 〕━━━╮ ┃ ┃ Unable to check for updates. ┃ ┃ 🌐 Please check your internet ┃ connection and try again. ╰━━━━━━━━━━━━━━━━━━━━╯` ); } }, onReaction: async function ({ message, getLang, Reaction, event }) { const { userID } = event; if (userID != Reaction.authorID) return; try { const { data: lastCommit } = await axios.get( "https://api.github.com/repos/ntkhang03/Goat-Bot-V2/commits/main" ); const lastCommitDate = new Date( lastCommit.commit.committer.date ); const elapsed = Date.now() - lastCommitDate.getTime(); if (elapsed < 5 * 60 * 1000) { const minutes = Math.floor(elapsed / 1000 / 60); const seconds = Math.floor( (elapsed / 1000) % 60 ); const remaining = 5 * 60 * 1000 - elapsed; const minutesCooldown = Math.floor( remaining / 1000 / 60 ); const secondsCooldown = Math.floor( (remaining / 1000) % 60 ); return message.reply( getLang( "updateTooFast", minutes, seconds, minutesCooldown, secondsCooldown ) ); } await message.reply( getLang("updateConfirmed") ); execSync("node update", { stdio: "inherit" }); fs.ensureDirSync( pathDir(dirBootLogTemp) ); fs.writeFileSync( dirBootLogTemp, event.threadID ); message.reply( getLang("updateComplete"), (err, info) => { if (err) return console.error(err); global.GoatBot.onReply.set( info.messageID, { messageID: info.messageID, threadID: info.threadID, authorID: event.senderID, commandName: "update" } ); } ); } catch (error) { console.error("Update error:", error); message.reply( `╭━━━〔 ❌ 𝗨𝗣𝗗𝗔𝗧𝗘 𝗙𝗔𝗜𝗟𝗘𝗗 〕━━━╮ ┃ ┃ Something went wrong while ┃ updating the chatbot. ┃ ┃ 🔧 Check the console for details. ╰━━━━━━━━━━━━━━━━━━━━╯` ); } }, onReply: async function ({ message, getLang, event }) { if ( ["yes", "y"].includes( event.body?.toLowerCase() ) ) { await message.reply( getLang("botWillRestart") ); process.exit(2); } } }; function pathDir(filePath) { return require("path").dirname(filePath); } function compareVersion(version1, version2) { const v1 = version1.split("."); const v2 = version2.split("."); for (let i = 0; i < 3; i++) { const a = parseInt(v1[i]) || 0; const b = parseInt(v2[i]) || 0; if (a > b) return 1; if (a < b) return -1; } return 0; }