Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:VHVersion: Difference between revisions

From Vault Hunters Official Wiki
Created page with "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..."
 
No edit summary
 
Line 1: Line 1:
local p = {}
local p = {}
local http = require('socket.http')
local json = require('dkjson')


function p.getVersion(frame)
function p.formatVersion(frame)
     local url = 'https://api.vaulthunters.gg/patch-notes?limit=1'
     local version = frame.args[1] or frame:getParent().args[1] or ""
      
      
     -- Fetch the data
     if version == "" then
    local body, status = http.request(url)
         return "No version provided"
   
    if status ~= 200 then
         return 'Error fetching version data'
     end
     end
      
      
     -- Parse JSON
     -- Remove patch version (everything after the last dot)
     local data, pos, err = json.decode(body)
     local majorMinor = version:match("^(.+)%.")
   
    if err then
        return 'Error parsing JSON: ' .. err
    end
      
      
    -- Extract version from first item
     if majorMinor then
     if data and data[1] and data[1].version then
         return "3." .. majorMinor
         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
     else
         return 'Version not found in response'
         return "3." .. version
     end
     end
end
end


return p
return p

Latest revision as of 18:03, 15 July 2025

Documentation for this module may be created at Module:VHVersion/doc

local p = {}

function p.formatVersion(frame)
    local version = frame.args[1] or frame:getParent().args[1] or ""
    
    if version == "" then
        return "No version provided"
    end
    
    -- Remove patch version (everything after the last dot)
    local majorMinor = version:match("^(.+)%.")
    
    if majorMinor then
        return "3." .. majorMinor
    else
        return "3." .. version
    end
end

return p