Module:ProfileInfoboxUpdater: Difference between revisions

From RetroMC
Jump to navigation Jump to search
No edit summary
No edit summary
(47 intermediate revisions by the same user not shown)
Line 1: Line 1:
--local rank = {}
--local rank = {}
local externalData = mw.ext.externalData
--externalData = mw.ext.externalData
--local uuid = {}
--local uuid = {}
local p  =  {}
local p  =  {}
Line 21: Line 21:
end
end


 
-- HIGHLY EXPERIMENTAL STUFF
local function createHTMLTable(data)
    local html = '<table>'
    for key, value in pairs(data) do
        html = html .. '<tr><td>' .. key .. '</td><td>' .. tostring(value) .. '</td></tr>'
    end
    html = html .. '</table>'
    return html
end
-- EXPERIMANTAL STUFF ENDS


function p.main(frame)
function p.main(frame)
Line 27: Line 36:
     local username = preprocessArg(args[1])
     local username = preprocessArg(args[1])
     local datatype = preprocessArg(args[2]) -- currently unused will be used whenever I implement more datatypes
     local datatype = preprocessArg(args[2]) -- currently unused will be used whenever I implement more datatypes
 
   


     if not username then -- check for blank username
     if not username then -- check for blank username
         return 'USERNAME NOT VALID OR API ERROR'
         return 'USERNAME NOT VALID OR API ERROR'
    end
    if username == '' then
        return 'NO USERNAME INPUT'
    end
    if username == '{{{username}}}' then
        return 'TEMPLATE NOTICED'
    end
    if username == '{{{1}}}' then
        return 'thecow275'
     end
     end


     if username then
     if username then
     local data = externalData.getExternalData({
     local data = mw.ext.externalData.getExternalData({
         url = "https://api.ashcon.app/mojang/v2/user/" .. username,
         url = "https://api.ashcon.app/mojang/v2/user/" .. username,
         format = "json"
         format = 'json'
     })
     })
     local uuid = data.uuid
     local uuid = data.uuid
Line 47: Line 68:


     if uuid then
     if uuid then
         local userdata = externalData.getExternalData({
         local userdata = mw.ext.externalData.getExternalData({
             url = "https://statistics.johnymuffin.com/api/v1/getUser?serverID=0&uuid=" .. uuid,
             url = "https://statistics.johnymuffin.com/api/v1/getUser?serverID=0&uuid=" .. data.uuid,
             format = "json"
            data = {deaths='playerDeaths',pkilled='playersKilled',joins='joinCount',traveled='metersTraveled',blocksplaced='blocksPlaced',itemsdropped='itemsDropped',trustlevel='trustLevel',blocksdestroyed='blocksDestroyed',groups = 'Groups', creatureskilled = 'creaturesKilled', balance='money'},
   
             format = 'json'
            })
      })


             if userdata then -- if this doesn't trigger something has gone terribly wrong
             if userdata then -- if this doesn't trigger something has gone terribly wrong
                
                
                  
                  
                local trust = userdata.trustlevel  -- Trust Level
                local blocksbroken = userdata.blocksdestroyed -- Blocks Broken
                local traveled = userdata.traveled -- Meters Traveled
                local blocksplaced = userdata.blocksplaced -- Blocks Placed
                local itemsdropped = userdata.itemsdropped -- Items Dropped
                local groups = userdata.groups  -- Groups as in Ranks
                local deaths = userdata.deaths  -- Player Deaths
                local pkilled = userdata.pkilled -- Players Killed
                local mkilled = userdata.creatureskilled -- Mob Kills
                local balance = userdata.balance -- Player's Money
                local joins = userdata.joins -- Join count
                if datatype == 'infobox' then
                    --local idk = trust.."|"..pkilled.."|"..mkilled.."|"..deaths.."|"..traveled.."|"..blocksplaced.."|"..itemsdropped.."|"..blocksbroken
                   
                    return createHTMLTable(data)
                end
                if datatype == 'uuid' then
                    return uuid
                end
                if datatype == 'joins' then
                    return joins
                end
                if datatype == 'balance' then
                    return balance
                end
                if datatype == 'mkilled' then
                    return mkilled
                end
                if datatype == 'pkilled' then
                    return pkilled
                end
                if datatype == 'deaths' then
                    return deaths
                end
                if datatype == 'itemsdropped' then
                    return itemsdropped
                end
                if datatype == 'blocksplaced' then
                    return blocksplaced
                end
                if datatype == 'traveled' then
                    return traveled
                end
                if datatype == 'trust' then
                    return trust
                end
                if datatype == 'broken' then
                    return blocksbroken
                end


                 local groups = userdata.groups
                 if datatype == 'rank' then
                 return groups
                if groups then                                              -- RANKLIST START --
                  if string.find(groups, "admin") then  --ADMIN
                  return 'Admin'
                  end
                if string.find(groups, "trial") then  -- Trial Helper
                    return 'Trial Helper'
                  end
                if string.find(groups, "moderator") then -- Moderator
                    return 'Moderator'
                end
                if string.find(groups, "helper") then -- Helper
                    return 'Helper'
                end
                if string.find(groups, "developer") then -- Developer
                    return 'Developer'
                end
                if string.find(groups, "diamondcitizen") then -- Diamond Citizen
                    return 'Diamond Citizen'
                end
                if string.find(groups, "citizen") then -- Citizen
                    return 'Citizen'
                end
                if string.find(groups, "trusted") then -- Gold Citizen
                    return 'Gold Citizen'
                end
                if string.find(groups, "hero") then -- Hero
                    return 'Hero'
                end
                if string.find(groups, "legend") then -- Legend
                    return 'Legend'
                end
                if string.find(groups, "mystic") then -- Mystic
                    return 'Mystic'
                end
                if string.find(groups, "donator") then -- Donator
                    return 'Donator'
                end
                if string.find(groups, "donatorplus") then -- Donator+
                    return 'Donator+'
                end
                 if string.find(groups, "donatorplusplus") then -- Donator++
                    return 'Donator++'
                end
                if string.find(groups, "trooper") then -- Trooper
                    return 'Trooper'
                end
                if string.find(groups, "infrastructure") then -- Infrastructure (not used)
                    return 'Infrastructure'
                end
                                                                      -- RANKLIST END --
               
             else
             else
                 return 'NO GROUPS FOUND'
                 return 'NO USERDATA OF SPECIFIED TYPE FOUND'
             end
             end


         end
         end
    end
        
        
     end
     end
 
else
       
    return 'something went horribly wrong'
 
end
 
 
 


end
end


return p
return p

Revision as of 06:09, 12 September 2024

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

--local rank = {}
--externalData = mw.ext.externalData
--local uuid = {}
local p  =  {}



--[ Thecow275's Profile Infobox Updater Module V1 ]

local function preprocessArg(s)
if not s then
    return nil 
end
s = s:match('^%s*(.-)%s*$') --trim whitespace
if s == '' then
    return nil
else
    return s
    end

end

-- HIGHLY EXPERIMENTAL STUFF
local function createHTMLTable(data)
    local html = '<table>'
    for key, value in pairs(data) do
        html = html .. '<tr><td>' .. key .. '</td><td>' .. tostring(value) .. '</td></tr>'
    end
    html = html .. '</table>'
    return html
end
-- EXPERIMANTAL STUFF ENDS

function p.main(frame)
    local args = frame.args
    local username = preprocessArg(args[1])
    local datatype = preprocessArg(args[2]) -- currently unused will be used whenever I implement more datatypes
    

    if not username then -- check for blank username
        return 'USERNAME NOT VALID OR API ERROR'
    end

    if username == '' then
        return 'NO USERNAME INPUT'
    end

    if username == '{{{username}}}' then
        return 'TEMPLATE NOTICED'
    end

    if username == '{{{1}}}' then
        return 'thecow275'
    end

    if username then
    local data = mw.ext.externalData.getExternalData({
        url = "https://api.ashcon.app/mojang/v2/user/" .. username,
        format = 'json'
    })
     local uuid = data.uuid


     if not uuid then --check for blank uuid (if this happens hell has broken lose)
        return 'NO VALID UUID FOUND'
     end
     

     if uuid then
        local userdata = mw.ext.externalData.getExternalData({
            url = "https://statistics.johnymuffin.com/api/v1/getUser?serverID=0&uuid=" .. data.uuid,
            data = {deaths='playerDeaths',pkilled='playersKilled',joins='joinCount',traveled='metersTraveled',blocksplaced='blocksPlaced',itemsdropped='itemsDropped',trustlevel='trustLevel',blocksdestroyed='blocksDestroyed',groups = 'Groups', creatureskilled = 'creaturesKilled', balance='money'},
            format = 'json'
      })

            if userdata then -- if this doesn't trigger something has gone terribly wrong
               
                
                local trust = userdata.trustlevel  -- Trust Level
                local blocksbroken = userdata.blocksdestroyed -- Blocks Broken
                local traveled = userdata.traveled -- Meters Traveled
                local blocksplaced = userdata.blocksplaced -- Blocks Placed
                local itemsdropped = userdata.itemsdropped -- Items Dropped
                local groups = userdata.groups  -- Groups as in Ranks
                local deaths = userdata.deaths  -- Player Deaths
                local pkilled = userdata.pkilled -- Players Killed
                local mkilled = userdata.creatureskilled -- Mob Kills
                local balance = userdata.balance -- Player's Money
                local joins = userdata.joins -- Join count


                if datatype == 'infobox' then
                    --local idk = trust.."|"..pkilled.."|"..mkilled.."|"..deaths.."|"..traveled.."|"..blocksplaced.."|"..itemsdropped.."|"..blocksbroken
                    
                    return createHTMLTable(data)
                 end

                if datatype == 'uuid' then
                    return uuid
                end

                if datatype == 'joins' then
                    return joins
                end

                if datatype == 'balance' then
                    return balance
                end

                if datatype == 'mkilled' then
                    return mkilled
                end

                if datatype == 'pkilled' then
                    return pkilled
                end

                if datatype == 'deaths' then
                    return deaths
                end

                if datatype == 'itemsdropped' then
                    return itemsdropped
                end

                if datatype == 'blocksplaced' then
                    return blocksplaced
                end

                if datatype == 'traveled' then
                    return traveled
                end

                if datatype == 'trust' then
                    return trust
                end

                if datatype == 'broken' then
                    return blocksbroken
                end

                if datatype == 'rank' then
                if groups then                                               -- RANKLIST START --
                  if string.find(groups, "admin") then  --ADMIN
                   return 'Admin'
                  end
                if string.find(groups, "trial") then  -- Trial Helper
                    return 'Trial Helper' 
                  end
                if string.find(groups, "moderator") then -- Moderator
                    return 'Moderator'
                end
                if string.find(groups, "helper") then -- Helper
                    return 'Helper'
                end
                if string.find(groups, "developer") then -- Developer
                    return 'Developer'
                end
                if string.find(groups, "diamondcitizen") then -- Diamond Citizen
                    return 'Diamond Citizen'
                end
                if string.find(groups, "citizen") then -- Citizen
                    return 'Citizen'
                end
                if string.find(groups, "trusted") then -- Gold Citizen
                    return 'Gold Citizen'
                end
                if string.find(groups, "hero") then -- Hero
                    return 'Hero'
                end
                if string.find(groups, "legend") then -- Legend
                    return 'Legend'
                end
                if string.find(groups, "mystic") then -- Mystic
                    return 'Mystic'
                end
                if string.find(groups, "donator") then -- Donator
                    return 'Donator'
                end
                if string.find(groups, "donatorplus") then -- Donator+
                    return 'Donator+'
                end
                if string.find(groups, "donatorplusplus") then -- Donator++
                    return 'Donator++'
                end
                if string.find(groups, "trooper") then -- Trooper
                    return 'Trooper'
                end
                if string.find(groups, "infrastructure") then -- Infrastructure (not used)
                    return 'Infrastructure'
                end
                                                                      -- RANKLIST END --
                
            else
                return 'NO USERDATA OF SPECIFIED TYPE FOUND'
            end

        end
     end
      
    end
else 
    return 'something went horribly wrong'
 end

end

return p