2025-02-17 12:14:12 -05:00
Version = Version or {}
2025-01-10 16:36:20 -05:00
2025-03-04 17:50:47 -05:00
---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")
---@param repoPath string
---@param tebex boolean | nil
---@return nil
function Version . VersionChecker ( repoPath , tebex )
2025-01-10 16:36:20 -05:00
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
PerformHttpRequest (( 'https://api.github.com/repos/%s/%s/releases/latest' ): format ( username , reponame ), function ( status , response )
2025-04-12 02:32:55 -04:00
if status ~= 200 then return end
2025-01-10 16:36:20 -05:00
response = json.decode ( response )
local latest = response.tag_name : match ( '%d+%.%d+%.%d+' )
2025-04-12 02:32:55 -04:00
if not latest then return end
2025-01-10 16:36:20 -05:00
2025-02-20 15:10:42 -05:00
if latest == version then return end
2025-01-10 16:36:20 -05:00
local currentVersion , latestVersion = version : gsub ( '%D' , '' ), latest : gsub ( '%D' , '' )
if currentVersion < latestVersion then
2025-04-12 02:32:55 -04:00
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
2025-01-10 16:36:20 -05:00
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
end , 'GET' )
end
AddEventHandler ( 'onResourceStart' , function ( resourceName )
if GetCurrentResourceName () ~= resourceName then return end
2025-02-17 12:14:12 -05:00
Version.VersionChecker ( "The-Order-Of-The-Sacred-Framework/community_bridge" )
2025-01-10 16:36:20 -05:00
end )