Documentation for this module may be created at Module:VHVersion/doc
local p = {}
local http = require('socket.http')
local json = require('dkjson')
function p.getVersion(frame)
local url = 'https://api.vaulthunters.gg/patch-notes?limit=1'
-- Fetch the data
local body, status = http.request(url)
if status ~= 200 then
return 'Error fetching version data'
end
-- Parse JSON
local data, pos, err = json.decode(body)
if err then
return 'Error parsing JSON: ' .. err
end
-- Extract version from first item
if data and data[1] and data[1].version then
local version = data[1].version
-- Transform "18.3.0" to "3.18.3"
-- Remove the patch version (everything after the last dot)
local majorMinor = version:match("^(.+)%.")
if majorMinor then
return "3." .. majorMinor
else
return "3." .. version
end
else
return 'Version not found in response'
end
end
return p