From c0662e10690c99f9bdcf7cf970d824ad8cbf0c71 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Fri, 9 May 2025 01:59:36 -0400 Subject: [PATCH] version checker tweak --- modules/version/server/VersionChecker.lua | 40 +++++++++-------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/modules/version/server/VersionChecker.lua b/modules/version/server/VersionChecker.lua index acf583c..6d5fe2a 100644 --- a/modules/version/server/VersionChecker.lua +++ b/modules/version/server/VersionChecker.lua @@ -1,40 +1,30 @@ Version = Version or {} ---Pass a github username and repo name to check for the latest version of the resource. +--- ---Tebex is a optional boolean to determine if the message should be for a escrowed resource or not. ----Example Version.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge") +--- +---Example Version.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge", false) ---@param repoPath string ---@param tebex boolean | nil ---@return nil function Version.VersionChecker(repoPath, tebex) - local resource = repoPath:match("([^/]+)$") - if not resource then return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') end - - local version = GetResourceMetadata(resource, "version", 0) - if not version then return Prints.Error(('^1Unable to determine current resource version for %s ^0'):format(resource)) end - - version = version:match('%d+%.%d+%.%d+') - if not version then return Prints.Error(('^1Invalid version format for %s ^0'):format(resource)) end - local username, reponame = repoPath:match("([^/]+)/([^/]+)") - if not username or not reponame then return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') end + local resource = reponame and repoPath:match("([^/]+)$") + if not username or not reponame or not resource then + return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') + end + + local version = GetResourceMetadata(resource, "version", 0):match('%d+%.%d+%.%d+') + if not version then return end + PerformHttpRequest(('https://api.github.com/repos/%s/%s/releases/latest'):format(username, reponame), function(status, response) - if status ~= 200 then return end - response = json.decode(response) + local latest = json.decode(response).tag_name:match('%d+%.%d+%.%d+') + if not latest or latest == version or version:gsub('%D', '') >= latest:gsub('%D', '') then return end - local latest = response.tag_name:match('%d+%.%d+%.%d+') - if not latest then return end - - if latest == version then return end - local currentVersion, latestVersion = version:gsub('%D', ''), latest:gsub('%D', '') - - if currentVersion < latestVersion then - if tebex then - return print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from the portal/keymaster.^7\r\n%s'):format(resource, version, "https://portal.cfx.re/assets/granted-assets")) - end - return print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from the GitHub release page.^7\r\n%s'):format(resource, version, response.html_url)) - end + local url = tebex and "https://portal.cfx.re/assets/granted-assets" or json.decode(response).html_url + print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from %s^7'):format(resource, version, url)) end, 'GET') end