Module:VillageTest: Difference between revisions

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


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


Line 59: Line 59:
         --table.insert(villagels, "1st layer works")
         --table.insert(villagels, "1st layer works")
          
          
 
        function villagehelper(PV_Input, PV_Name)
        retval:addHeader('Member')
            local PV_Input =  PV_Input
        for i, member in ipairs(playerVillages.__json.data.member) do  --maybe this needs to be for pairs in data and then again for ipairs in owner, member and assistant ? so maybe I need to create 2 tables for this and then handle it through that ?
            local PV_Name = PV_Name
            mw.log('iterations:  '..i)
            retval:addHeader(PV_Name)
            mw.logObject(member)
            mw.log(' DATA FOR:  '..PV_Name..':')
            --local member2 = member
                    for i, PV_Data in ipairs(PV_Input) do  --[[ For Example: playerVillages.__json.data.member ]]--
 
                        --mw.log('villagehelper iterations:  '..i)
            if type(member) == "table" and member.village then
                        --mw.logObject(PV_Data)
                mw.logObject(member.village)
                       
                mw.log('table WTF?')
           
                local localmember = member.village
                        if type(PV_Data) == "table" and PV_Data.village then
               
                            mw.logObject(PV_Data.village)
                retval:addRow('',localmember,'','icr-transparency1 icr-data')
                            mw.log('SUCCESS: PV_Data is a Table')
            elseif type(member) == "string" then
                            local PV_Data_Local = PV_Data.village
                mw.logObject(member)
                           
               
                            retval:addRow('',PV_Data_Local,'','icr-transparency1 icr-data')
                mw.log('do be string')
                        elseif type(PV_Data) == "string" or PV_Data == nil then
            end
                            mw.logObject(PV_Data)
                --for k, village in pairs(member2) do
                           
                --    if village then
                            mw.log('ERROR: PV_Data is a String or nil, Supposed to be a Table')
                  --      retval:addRow('',village,'','icr-transparency1 icr-data')
                        end
                  --      mw.log('VillageStuff? : '..k)
                        end    
                  --      mw.logObject(village)
                  --  end
                --end
         end
         end
        retval:addHeader('Owner')
                villagehelper(playerVillages.__json.data.member, "Member")
        for i, owner in ipairs(playerVillages.__json.data.owner) do  --maybe this needs to be for pairs in data and then again for ipairs in owner, member and assistant ? so maybe I need to create 2 tables for this and then handle it through that ?
                villagehelper(playerVillages.__json.data.owner, "Owner")
            mw.log('iterations:  '..i)
                villagehelper(playerVillages.__json.data.assistant, "Assistant")
            mw.logObject(owner)
           


            if type(owner) == "table" and owner.village then
              mw.logObject(owner.village)
              mw.log('table WTF?')
              local localowner = owner.village
             
              retval:addRow('',localowner,'','icr-transparency1 icr-data')
            elseif type(owner) == "string" then
              mw.logObject(owner)
             
              mw.log('do be string')
            end
             
      end
      retval:addHeader('Assistant')
        for i, assistant in ipairs(playerVillages.__json.data.assistant) do  --maybe this needs to be for pairs in data and then again for ipairs in assistant, member and assistant ? so maybe I need to create 2 tables for this and then handle it through that ?
            mw.log('iterations:  '..i)
            mw.logObject(assistant)
           


            if type(assistant) == "table" and assistant.village then
       
              mw.logObject(assistant.village)
        
              mw.log('table WTF?')
              local localassistant = assistant.village
             
              retval:addRow('',localassistant,'','icr-transparency1 icr-data')
            elseif type(assistant) == "string" then
              mw.logObject(assistant)
             
              mw.log('do be string')
            end
             
       end
              
              
          
          

Revision as of 13:27, 18 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.main(frame)
    local args = frame.args
    --local input = preprocessArg(args[1])
   -- local datatype = 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
   --    return 'INPUT ERROR INPUT IS NULL'
    --end

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

    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')

    local villagels = {}
    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)
                            
                            mw.log('ERROR: PV_Data is a String or nil, Supposed to be a Table')
                         end
                        end     
        end
                villagehelper(playerVillages.__json.data.member, "Member")
                villagehelper(playerVillages.__json.data.owner, "Owner")
                villagehelper(playerVillages.__json.data.assistant, "Assistant")


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