Module:ProfileInfoboxUpdater: Difference between revisions

From RetroMC
Jump to navigation Jump to search
(debug)
No edit summary
Line 54: Line 54:


         local userdata2 = mw.ext.externalData.getExternalData({
         local userdata2 = mw.ext.externalData.getExternalData({
        url = "https://statistics.johnymuffin.com/api/v1/getUser?serverID=0&uuid=" .. data.uuid,
            url = "https://statistics.johnymuffin.com/api/v1/getUser?serverID=0&uuid=" .. data.uuid,
        format = 'json'
            data = {trustlevel='trustLevel',blocksdestroyed='blocksDestroyed',groups = 'Groups'},
            format = 'json'
     })
     })


Line 61: Line 62:
                
                
                  
                  
                 local trust = userdata2.trustLevel
                 local trust = userdata2.trustlevel
                 local broken = userdata2.blocksDestroyed
                 local broken = userdata2.blocksdestroyed
                 local groups = userdata.groups
                 local groups = userdata.groups


                 if datatype == 'debug' then
                 if datatype == 'debug' then
                     return broken
                     return uuid .. trust .. broken .. groups
                 end
                 end



Revision as of 12:24, 28 August 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



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
    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 = {trustLevel='Trust Level',blocksDestroyed='Blocks Broken',groups = 'Groups'},
            format = 'json'
      })

        local userdata2 = mw.ext.externalData.getExternalData({
             url = "https://statistics.johnymuffin.com/api/v1/getUser?serverID=0&uuid=" .. data.uuid,
             data = {trustlevel='trustLevel',blocksdestroyed='blocksDestroyed',groups = 'Groups'},
             format = 'json'
     })

            if userdata then -- if this doesn't trigger something has gone terribly wrong
               
                
                local trust = userdata2.trustlevel
                local broken = userdata2.blocksdestroyed
                local groups = userdata.groups

                if datatype == 'debug' then
                    return uuid .. trust .. broken .. groups
                end

                if datatype == 'uuid' then
                    return uuid
                end

                if datatype == 'trust' then
                    return trust
                end

                if datatype == 'broken' then
                    return broken
                end

                if datatype == 'rank' then
                if groups then
                  if string.find(groups, "admin") then
                   return 'Admin'
                  
                  end
                if string.find(groups, "trial") then
                    return 'Trial Helper'
                  end
                if string.find(groups, "moderator") then
                    return 'Moderator'
                end
                if string.find(groups, "diamondcitizen") then
                    return 'Diamond Citizen'
                end
                
            else
                return 'NO USERDATA OF SPECIFIED TYPE FOUND'
            end

        end
    end
    end

        





end
end

return p