From e5ee2be1c2a5156bde8d7078baa94a6cc63bf17a Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Wed, 14 Jun 2023 21:31:31 -0400 Subject: [PATCH 1/3] feat: Version Checks --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index 87f21533..293f8793 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,7 @@ const { Client, Collection, GatewayIntentBits } = require("discord.js"); const { token } = require("./config/token.json"); const { QuickDB, MySQLDriver } = require("quick.db"); const jsonc = require("jsonc"); +const { exec } = require("child_process"); process.on("unhandledRejection", (reason, promise, a) => { console.log(reason, promise, a); @@ -38,6 +39,15 @@ process.stdout.write(` Connecting to Discord... `); +exec("git fetch",()=>{ + exec("git show origin/main --format=%h -s", (_,remHash) => { + exec("git show main --format=%h -s", (_, locHash) => { + if(remHash.toString() !== locHash.toString()) + console.log("There is a new update available! Please run \"git pull\" to update the bot!"); + }); + }); +}); + const config = jsonc.parse(fs.readFileSync(path.join(__dirname, "config/config.jsonc"), "utf8")); const client = new Client({ From 1324a5f83efef0ba0c0e27877d162b737ab51bdc Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Fri, 16 Jun 2023 11:57:32 -0400 Subject: [PATCH 2/3] feat: REST-based version check --- index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 293f8793..765096f7 100644 --- a/index.js +++ b/index.js @@ -39,14 +39,19 @@ process.stdout.write(` Connecting to Discord... `); -exec("git fetch",()=>{ - exec("git show origin/main --format=%h -s", (_,remHash) => { - exec("git show main --format=%h -s", (_, locHash) => { - if(remHash.toString() !== locHash.toString()) - console.log("There is a new update available! Please run \"git pull\" to update the bot!"); - }); +fetch("https://api.github.com/repos/Sayrix/Ticket-Bot/tags").then((res)=> { + if(Math.floor(res.status / 100) !== 2) return console.warn("[Version Check] Failed to pull latest version from server"); + res.json().then((json) => { + // Assumign the format stays consistent (i.e. x.x.x) + const latest = json[0].name.split(".").map(k=>parseInt(k)); + const current = require("./package.json").version.split(".").map(k=>parseInt(k)); + if(latest[0] > current[0] || + (latest[0] === current[0] && latest[1] > current[1]) || + (latest[0] === current[0] && latest[1] === current[1] && latest[2] > current[2])) + console.warn(`[Version Check] New version available: ${json[0].name}; Current Version: ${current.join(".")}`); + else console.log("[Version Check] Up to date"); }); -}); +}) const config = jsonc.parse(fs.readFileSync(path.join(__dirname, "config/config.jsonc"), "utf8")); From ca2aa59890621043176b37871df113a81b7efd55 Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Fri, 16 Jun 2023 12:05:41 -0400 Subject: [PATCH 3/3] style: Reformat some stuff --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 765096f7..3d6babc7 100644 --- a/index.js +++ b/index.js @@ -46,12 +46,12 @@ fetch("https://api.github.com/repos/Sayrix/Ticket-Bot/tags").then((res)=> { const latest = json[0].name.split(".").map(k=>parseInt(k)); const current = require("./package.json").version.split(".").map(k=>parseInt(k)); if(latest[0] > current[0] || - (latest[0] === current[0] && latest[1] > current[1]) || - (latest[0] === current[0] && latest[1] === current[1] && latest[2] > current[2])) - console.warn(`[Version Check] New version available: ${json[0].name}; Current Version: ${current.join(".")}`); + (latest[0] === current[0] && latest[1] > current[1]) || + (latest[0] === current[0] && latest[1] === current[1] && latest[2] > current[2])) + console.warn(`[Version Check] New version available: ${json[0].name}; Current Version: ${current.join(".")}`); else console.log("[Version Check] Up to date"); }); -}) +}); const config = jsonc.parse(fs.readFileSync(path.join(__dirname, "config/config.jsonc"), "utf8"));