Module:ProfileInfoboxUpdater: Difference between revisions

From RetroMC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 84: Line 84:
                 --local groups = userdata.groups  -- Groups as in Ranks
                 --local groups = userdata.groups  -- Groups as in Ranks
                 local rank = 'nul'
                 local rank = 'nul'
                 local bracketstyle = 'icr-data-a'
                 local bracketstyle = 'icr-a icr-data'
                 local rankstyle = 'icr-data-a'
                 local rankstyle = 'icr-data-a'
                 --local balance = string.format("%.2f", userdata.balance)
                 --local balance = string.format("%.2f", userdata.balance)
Line 96: Line 96:
                     if string.find(userdata.groups, "admin") then  --ADMIN
                     if string.find(userdata.groups, "admin") then  --ADMIN
                     rank = 'Admin'
                     rank = 'Admin'
                     bracketstyle = 'icr-data-6'
                     bracketstyle = 'icr-f icr-data'
                    rankstyle = 'icr-4 icr-data'
                     end
                     end
                   if string.find(userdata.groups, "trial") then  -- Trial Helper
                   if string.find(userdata.groups, "trial") then  -- Trial Helper
Line 147: Line 148:
               else
               else
                   rank = 'Wanderer'
                   rank = 'Wanderer'
                   bracketstyle = 'icr-data-a'
                   bracketstyle = 'icr-a icr-data'
               end
               end


Line 188: Line 189:
                          
                          
                         --:addWikitext('File:https://minotar.net/armor/bust'..username..'.png')
                         --:addWikitext('File:https://minotar.net/armor/bust'..username..'.png')
                         :addRow( 'Username', username, 'icr-data-6', 'icr-a icr-data' )
                         :addRow( 'Username', username, 'icr-6', 'icr-a icr-data' )
                         :addRow( 'Rank', string.format('<span class="%s">[</span><span class="icr-data icr-data-a">%s</span><span class="%s">]</span>', bracketstyle,rank,bracketstyle), 'icr-hack-right')
                         :addRow( 'Rank', string.format('<span class="%s">[</span><span class="&s">%s</span><span class="%s">]</span>', bracketstyle,rankstyle,rank,bracketstyle), 'icr-hack-right')
                         :addRow( 'UUID', data.uuid )
                         :addRow( 'UUID', data.uuid )
                         :addRow( 'Balance', string.format("%.2f", userdata.balance))
                         :addRow( 'Balance', string.format("%.2f", userdata.balance))

Revision as of 09:22, 13 October 2024

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

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


--[ 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 data.uuid then --check for blank uuid (if this happens hell has broken lose)
        return 'NO VALID UUID FOUND'
     end
     

     if data.uuid then --if uuid is valid then get data from johnymuffin jstats api
        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 rank = 'nul'
                local bracketstyle = 'icr-a icr-data'
                local rankstyle = 'icr-data-a'
                --local balance = string.format("%.2f", userdata.balance)
               -- 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 userdata.groups then                                               -- RANKLIST START --
                    if string.find(userdata.groups, "admin") then  --ADMIN
                     rank = 'Admin'
                     bracketstyle = 'icr-f icr-data'
                     rankstyle = 'icr-4 icr-data'
                    end
                  if string.find(userdata.groups, "trial") then  -- Trial Helper
                      rank = 'Trial Helper' 
                    end
                  if string.find(userdata.groups, "moderator") then -- Moderator
                      rank = 'Moderator'
                  end
                  if string.find(userdata.groups, "helper") then -- Helper
                      rank = 'Helper'
                  end
                  if string.find(userdata.groups, "developer") then -- Developer
                      rank = 'Developer'
                  end
                  if string.find(userdata.groups, "diamondcitizen") then -- Diamond Citizen
                      rank = 'Diamond Citizen'
                  end
                  if string.find(userdata.groups, "citizen") then -- Citizen
                      rank = 'Citizen'
                  end
                  if string.find(userdata.groups, "trusted") then -- Gold Citizen
                      rank = 'Gold Citizen'
                  end
                  if string.find(userdata.groups, "hero") then -- Hero
                      rank = 'Hero'
                  end
                  if string.find(userdata.groups, "legend") then -- Legend
                      rank = 'Legend'
                  end
                  if string.find(userdata.groups, "mystic") then -- Mystic
                      rank = 'Mystic'
                  end
                  if string.find(userdata.groups, "donator") then -- Donator
                      rank = 'Donator'
                  end
                  if string.find(userdata.groups, "donatorplus") then -- Donator+
                      rank = 'Donator+'
                  end
                  if string.find(userdata.groups, "donatorplusplus") then -- Donator++
                      rank = 'Donator++'
                  end
                  if string.find(userdata.groups, "trooper") then -- Trooper
                      rank = 'Trooper'
                  end
                  if string.find(userdata.groups, "infrastructure") then -- Infrastructure (not used)
                      rank = 'Infrastructure'
                  end
                                                                        -- RANKLIST END --
                  
              else
                  rank = 'Wanderer'
                  bracketstyle = 'icr-a icr-data'
              end


                if datatype == 'infobox' then
                    --local idk = trust.."|"..pkilled.."|"..mkilled.."|"..deaths.."|"..traveled.."|"..blocksplaced.."|"..itemsdropped.."|"..blocksbroken
                    
                    --return createHTMLTable(data)
                    
                        local args = frame:getParent().args
                       -- local headerStyle
                        --    headerStyle = 'background-color:red'
                       -- local labelStyle
                          --  labelStyle = 'background-color:#55FF55'
                      --  local dataStyle
                          --  dataStyle = 'background-color:#55FF55; font-weight:bold; display:inline-block; float:right'
                       -- local labelStyle2
                           --  labelStyle2 = 'style="background-color:#444444"'
                       -- local dataStyle2
                           --  dataStyle2 = 'style="background-color:#222222; font-weight:bold; display:inline-block; float:left"'
                        
                        local retval = capiunto.create({
                            --title = username,
                            --titleStyle = 
                            --headerStyle = headerStyle,
                           -- labelStyle = labelStyle,
                            --dataStyle = dataStyle,
                           -- labelStyle2 = labelStyle2,
                            --dataStyle2 = dataStyle2,
                            top = username,
                            topStyle = 'background:#cfc;'
                        })
                        
                        
                       
                        --:addImage( args.image, args.caption )
                        :addImage('https://minotar.net/armor/bust/'..username..'.png','Player Bust','icr-hack')
                        --:addHeader(username, 'icr-title')
                        :addRow('','')
                        
                        --:addWikitext('File:https://minotar.net/armor/bust'..username..'.png')
                        :addRow( 'Username', username, 'icr-6', 'icr-a icr-data' )
                        :addRow( 'Rank', string.format('<span class="%s">[</span><span class="&s">%s</span><span class="%s">]</span>', bracketstyle,rankstyle,rank,bracketstyle), 'icr-hack-right')
                        :addRow( 'UUID', data.uuid )
                        :addRow( 'Balance', string.format("%.2f", userdata.balance))
                        :addHeader( 'Miscellaneous Stats', 'icr-header' )
                        :addRow( 'Join Count', userdata.joins )
	                    :addRow( 'Trust Level', userdata.trustlevel, '', 'icr-data icr-data-8')
	                    :addRow( 'Player Kills', userdata.pkilled, 'icr-right-align', 'icr-right-align' )
                        :addRow( 'Mob Kills', userdata.creatureskilled )
                        :addRow( 'Deaths', userdata.deaths )
                        :addRow( 'Blocks Traveled', userdata.traveled )
                        :addRow( 'Blocks Placed', userdata.blocksplaced )
                        :addRow( 'Items Dropped', userdata.itemsdropped )
                        :addRow( 'Blocks Broken', userdata.blocksdestroyed )
                        
	                    return retval
                        
                        
                        


                 end

                if datatype == 'rank' then
                

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

end

return p