Module:VillageTest: Difference between revisions

From RetroMC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 19: Line 19:
end
end


function p.debug(frame)
p.main(
    mw.getCurrentFrame():newChild{
        title = "Module:VillageTest",
        args ={"thecow275","villagelist"}
   
    }
   
    )
end
function p.main(frame)
function p.main(frame)
     local args = frame.args
     local args = frame.args
     --local input = preprocessArg(args[1])
     local input = preprocessArg(args[1])
  -- local datatype = preprocessArg(args[2]) -- currently unused will be used whenever I implement more datatypes
    local infoboxtype = preprocessArg(args[2]) -- currently unused will be used whenever I implement more datatypes
  -- local UUIDORUSER = preprocessArg(args[3]) -- Selector for if input is username OR UUID
   
  -- local PlayerORVillage = preprocessArg(args[4]) -- Jesus christ argument just so you can specify if you are searching for village data YES village data
  -- this module will get bloated with the jvillage stuff but EHHH


   --if not input then -- CHECK FOR BLANK INPUT
   if not input then -- CHECK FOR BLANK INPUT
  --    return 'INPUT ERROR INPUT IS NULL'
      return 'INPUT ERROR INPUT IS NULL'
     --end
     end


     --local uuid = '8fa8f70d-eb7d-4743-b0ad-837cdfb69f4e' --[thecow275]--
     local uuid = '8fa8f70d-eb7d-4743-b0ad-837cdfb69f4e' --[thecow275]--
     local uuid = 'b08b6a7a-aada-4787-bb4b-07fc393ad6e5' --[QueenOfAsh]--
     --local uuid = 'b08b6a7a-aada-4787-bb4b-07fc393ad6e5' --[QueenOfAsh]--
  --  local villagedata = mw.ext.externalData.getExternalData({
    local villagelist = mw.ext.externalData.getExternalData({
  --      url =  "api.retromc.org/api/v1/village/getVillageList",
        url =  "https://api.retromc.org/api/v1/village/getVillageList",
  --      format =  'json',
        format =  'json',
  --      data = url
        data = url
--   })
    })
    --mw.log('Village List API')
     --mw.logObject(villagelist.villages)
    --mw.logObject(villagelist.error)


     local playerVillages = mw.ext.externalData.getExternalData({
     local playerVillages = mw.ext.externalData.getExternalData({
Line 54: Line 66:
     retval:addRow('HOWDY', 'HOWDEE', '', 'icr-transparency1 icr-data')
     retval:addRow('HOWDY', 'HOWDEE', '', 'icr-transparency1 icr-data')


     local villagels = {}
      
     if playerVillages.__json.data then
     if playerVillages.__json.data then


Line 77: Line 89:
                         elseif type(PV_Data) == "string" or PV_Data == nil then
                         elseif type(PV_Data) == "string" or PV_Data == nil then
                             mw.logObject(PV_Data)
                             mw.logObject(PV_Data)
                              
                             --local PV_Data_Local = 'ERROR: API FAILURE'
                             mw.log('ERROR: PV_Data is a String or nil, Supposed to be a Table')
                             mw.log('ERROR: PV_Data is a String or nil, Supposed to be a Table')
                         end
                         end
                         end     
                         end     
         end
         end
        function villagelistprocessor(VP_Input, VP_Name)
            local VP_Input = VP_Input
            local VP_Name = VP_Name
            retval:addHeader(VP_Name)
            for i, VP_Data in ipairs(VP_Input) do
                if type(VP_Data) == "table" and VP_Data.name then
                    local VP_Data_Local = VP_Data.name
                    retval:addRow('',VP_Data_Local,'','icr-transparency1 icr-data')
                    mw.logObject(VP_Data_Local)
                elseif type(VP_Data) == "string" or VP_Data == nil then
                    --mw.logObject(VP_Data)
                    mw.log('VP_Data is nil this shouldn\'t be the case')
                end
            end
        end
        if infoboxtype == "playervillages" then
                 villagehelper(playerVillages.__json.data.member, "Member")
                 villagehelper(playerVillages.__json.data.member, "Member")
                 villagehelper(playerVillages.__json.data.owner, "Owner")
                 villagehelper(playerVillages.__json.data.owner, "Owner")
                 villagehelper(playerVillages.__json.data.assistant, "Assistant")
                 villagehelper(playerVillages.__json.data.assistant, "Assistant")
        elseif infoboxtype == "villagelist" then
                mw.log('-------------------------------')
                mw.log('|                              |')
                mw.log('|    VILLAGE LIST TESTING      |')
                mw.log('|                              |')
                mw.log('--------------------------------')
                mw.logObject(villagelistprocessor(villagelist.__json.villages, "Villages"))
                villagelistprocessor(villagelist.__json.villages, "Villages")
                --mw.logObject(villagelist.__json)
        end




Line 99: Line 140:
     --mw.logObject(playerVillages.data)
     --mw.logObject(playerVillages.data)
     --mw.logObject(playerVillages.status)
     --mw.logObject(playerVillages.status)
    --mw.logObject(villagelist.villages)
     return retval
     return retval
end
end
return p
return p

Revision as of 13:54, 27 January 2025

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

local p  =  {}
local capiunto = require 'capiunto'


--[ Thecow275's WikiStats V2 VIllages MODULE PROTOTYPE ]
--[ Nicknamed: UUID and J-Village Update]

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.debug(frame)
p.main(
    mw.getCurrentFrame():newChild{
        title = "Module:VillageTest",
        args ={"thecow275","villagelist"}
    
     }
    
    )

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

   if not input then -- CHECK FOR BLANK INPUT
       return 'INPUT ERROR INPUT IS NULL'
    end

    local uuid = '8fa8f70d-eb7d-4743-b0ad-837cdfb69f4e' --[thecow275]--
    --local uuid = 'b08b6a7a-aada-4787-bb4b-07fc393ad6e5' --[QueenOfAsh]--
    local villagelist = mw.ext.externalData.getExternalData({
        url =  "https://api.retromc.org/api/v1/village/getVillageList",
        format =  'json',
        data = url
    })
     --mw.log('Village List API')
     --mw.logObject(villagelist.villages)
     --mw.logObject(villagelist.error)

    local playerVillages = mw.ext.externalData.getExternalData({
        url = "https://statistics.retromc.org/api/user_villages?uuid=" .. uuid,
        format = 'json',
        data = url

    })
    
    local retval = capiunto.create({
        top = 'TESTING',
        bodyClass = 'icr-DiamondCitizenBodyStyle',
        topClass = 'icr-title'
    })

    retval:addRow('HOWDY', 'HOWDEE', '', 'icr-transparency1 icr-data')

    
    if playerVillages.__json.data then

        --table.insert(villagels, "1st layer works")
        
        function villagehelper(PV_Input, PV_Name)
            local PV_Input =  PV_Input
            local PV_Name = PV_Name
            retval:addHeader(PV_Name)
            mw.log(' DATA FOR:  '..PV_Name..':')
                    for i, PV_Data in ipairs(PV_Input) do  --[[ For Example: playerVillages.__json.data.member ]]--
                         --mw.log('villagehelper iterations:  '..i)
                         --mw.logObject(PV_Data)
                         
            
                         if type(PV_Data) == "table" and PV_Data.village then
                            mw.logObject(PV_Data.village)
                            mw.log('SUCCESS: PV_Data is a Table')
                            local PV_Data_Local = PV_Data.village
                            
                            retval:addRow('',PV_Data_Local,'','icr-transparency1 icr-data')
                         elseif type(PV_Data) == "string" or PV_Data == nil then
                            mw.logObject(PV_Data)
                            --local PV_Data_Local = 'ERROR: API FAILURE'
                            mw.log('ERROR: PV_Data is a String or nil, Supposed to be a Table')
                         end
                        end     
        end
        function villagelistprocessor(VP_Input, VP_Name)
            local VP_Input = VP_Input
            local VP_Name = VP_Name
            retval:addHeader(VP_Name)
            for i, VP_Data in ipairs(VP_Input) do
                if type(VP_Data) == "table" and VP_Data.name then
                    local VP_Data_Local = VP_Data.name

                    retval:addRow('',VP_Data_Local,'','icr-transparency1 icr-data')
                    mw.logObject(VP_Data_Local)
                elseif type(VP_Data) == "string" or VP_Data == nil then
                    --mw.logObject(VP_Data)
                    mw.log('VP_Data is nil this shouldn\'t be the case')

                end

            end
        end
        if infoboxtype == "playervillages" then
                villagehelper(playerVillages.__json.data.member, "Member")
                villagehelper(playerVillages.__json.data.owner, "Owner")
                villagehelper(playerVillages.__json.data.assistant, "Assistant")
        elseif infoboxtype == "villagelist" then
                mw.log('-------------------------------')
                mw.log('|                               |')
                mw.log('|    VILLAGE LIST TESTING       |')
                mw.log('|                               |')
                mw.log('--------------------------------')
                mw.logObject(villagelistprocessor(villagelist.__json.villages, "Villages"))
                villagelistprocessor(villagelist.__json.villages, "Villages")
                --mw.logObject(villagelist.__json)
        end


        
       
            
        
        
        
    end
    --mw.logObject(villagels)
    --mw.logObject(playerVillages.__json.data.member)
    --mw.logObject(member.village)
    --mw.logObject(playerVillages.data)
    --mw.logObject(playerVillages.status)
    --mw.logObject(villagelist.villages)
    return retval
end
return p