Module:ProfileInfoboxUpdaterExperimental: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Adding Debug stuff) |
||
(17 intermediate revisions by the same user not shown) | |||
Line 22: | Line 22: | ||
function p.main(frame) | function p.main(frame) | ||
frame = frame or { getParent = function() return {} end } | |||
local args = frame.args | local args = frame.args | ||
local input = preprocessArg(args[1]) | local input = preprocessArg(args[1]) | ||
Line 214: | Line 215: | ||
local playerVillages = mw.ext.externalData.getExternalData({ | local playerVillages = mw.ext.externalData.getExternalData({ | ||
url = "https://statistics.retromc.org/api/user_villages?uuid=" .. uuid, | url = "https://statistics.retromc.org/api/user_villages?uuid=" .. uuid, | ||
data = { | data = {data='data',member='data:member',assistant='data:assistant'}, | ||
format = 'json' | format = 'json' | ||
}) | }) | ||
mw.logObject(playerVillages) | |||
mw.log(playerVillages) | |||
print(playerVillages) | |||
--error(table.concat(playerVillages, ',')) | |||
local villagels = {} | |||
if playerVillages.data.owner then | |||
if playerVillages.owner then | |||
for _, ownerData in ipairs(playerVillages.data.owner) do | |||
for _, ownerData in ipairs( | |||
if ownerData.village then | if ownerData.village then | ||
table.insert(villagels, ownerData.village) | table.insert(villagels, ownerData.village) | ||
Line 229: | Line 233: | ||
end | end | ||
end | |||
Line 271: | Line 275: | ||
if | if villagels == nil then | ||
retval: | retval:addRow( 'Villages', 'ERROR', 'icr-data') | ||
else | else | ||
local villageconcat = table.concat(villagels, ', ') | local villageconcat = table.concat(villagels, ', ') | ||
retval: | retval:addRow('Villages', villageconcat) | ||
end | end | ||
Latest revision as of 20:07, 17 October 2024
Documentation for this module may be created at Module:ProfileInfoboxUpdaterExperimental/doc
local p = {} local capiunto = require 'capiunto' --[ Thecow275's Profile Infobox Updater Module V2 ] --[ 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) frame = frame or { getParent = function() return {} end } 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 username return 'USERNAME OR UUID NOT VALID OR YOU SPECIFIED UUID WITH THE WRONG TEMPLATE' end if input == '' then return 'NO USERNAME OR UUID INPUT' end if input == '{{{username}}}' then return 'TEMPLATE NOTICED' end if input == '{{{1}}}' then input = 'thecow275' end local uuid = '8fa8f70d-eb7d-4743-b0ad-837cdfb69f4e' if input then if UUIDORUSER == '' or '{{{2}}}' then local data = mw.ext.externalData.getExternalData({ url = "https://api.ashcon.app/mojang/v2/user/" .. input, format = 'json' }) uuid = data.uuid end if UUIDORUSER == 'UUID' then local data2 = mw.ext.externalData.getExternalData({ url = 'https://api.ashcon.app/mojang/v2/user/' .. input, format = 'json' }) input = data2.username uuid = input end if not uuid then --check for blank uuid (if this happens hell has broken lose) return 'NO VALID UUID FOUND' end if 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=" .. 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 rank = 'Wanderer' local bracketstyle = 'icr-t-8 icr-data' local rankstyle = 'icr-t-7 icr-data' local plusstyle = 'icr-t-4 icr-data' local plus = '' if userdata.groups then if string.find(userdata.groups, "wanderer") then rank = 'Wanderer' bracketstyle = 'icr-t-8 icr-data' rankstyle = 'icr-t-7 icr-data' end -- RANKLIST START -- if string.find(userdata.groups, "admin") then --ADMIN rank = 'Admin' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-4 icr-data' end if string.find(userdata.groups, "trial") then -- Trial Helper rank = 'Trial Helper' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-a icr-data' end if string.find(userdata.groups, "moderator") then -- Moderator rank = 'Moderator' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-6 icr-data' end if string.find(userdata.groups, "helper") then -- Helper rank = 'Helper' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-3 icr-data' end if string.find(userdata.groups, "developer") then -- Developer rank = 'Developer' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-c icr-data' end if string.find(userdata.groups, "diamondcitizen") then -- Diamond Citizen rank = 'Diamond Citizen' bracketstyle = 'icr-t-b icr-data' rankstyle = 'icr-t-a icr-data' end if string.find(userdata.groups, "citizen") then -- Citizen rank = 'Citizen' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-a icr-data' end if string.find(userdata.groups, "trusted") then -- Gold Citizen rank = 'Gold Citizen' bracketstyle = 'icr-t-6 icr-data' rankstyle = 'icr-t-a icr-data' end if string.find(userdata.groups, "hero") then -- Hero rank = 'Hero' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-2 icr-data' end if string.find(userdata.groups, "legend") then -- Legend rank = 'Legend' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-9 icr-data' end if string.find(userdata.groups, "mystic") then -- Mystic rank = 'Mystic' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-b icr-data' end if string.find(userdata.groups, "donator") then -- Donator rank = 'Donator' bracketstyle = 'icr-t-8 icr-data' rankstyle = 'icr-t-c icr-data' end if string.find(userdata.groups, "donatorplus") then -- Donator+ rank = 'Donator' bracketstyle = 'icr-t-8 icr-data' rankstyle = 'icr-t-c icr-data' plus = '+' end if string.find(userdata.groups, "donatorplusplus") then -- Donator++ rank = 'Donator' bracketstyle = 'icr-t-8 icr-data' rankstyle = 'icr-t-c icr-data' plus = '++' end if string.find(userdata.groups, "trooper") then -- Trooper rank = 'Trooper' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-d icr-data' end if string.find(userdata.groups, "infrastructure") then -- Infrastructure (not used) rank = 'Infrastructure' bracketstyle = 'icr-t-f icr-data' rankstyle = 'icr-t-6 icr-data' end -- RANKLIST END -- else rank = 'Wanderer' bracketstyle = 'icr-t-8 icr-data' rankstyle = 'irc-t-7 icr-data' end local formattedrank = string.format('<span class="%s">[</span><span class="%s">%s</span><span class="%s">%s</span><span class="%s">]</span>', bracketstyle,rankstyle,rank,plusstyle,plus,bracketstyle) local styletop = 'background:#cfc;' if input == 'JohnyMuffin' then styletop = 'background:#5555FF; color:#FFFFFF;' else styletop = 'background:#cfc;' end if datatype == 'PlayerInfobox' then local villagedata = mw.ext.externalData.getExternalData({ url = "api.retromc.org/api/v1/village/getVillageList", format = 'json' }) local playerVillages = mw.ext.externalData.getExternalData({ url = "https://statistics.retromc.org/api/user_villages?uuid=" .. uuid, data = {data='data',member='data:member',assistant='data:assistant'}, format = 'json' }) mw.logObject(playerVillages) mw.log(playerVillages) print(playerVillages) --error(table.concat(playerVillages, ',')) local villagels = {} if playerVillages.data.owner then for _, ownerData in ipairs(playerVillages.data.owner) do if ownerData.village then table.insert(villagels, ownerData.village) end end end local args = frame:getParent().args local retval = capiunto.create({ top = input, topStyle = styletop }) --:addImage( args.image, args.caption ) retval:addImage('https://minotar.net/armor/bust/'..input..'.png','Player Bust','icr-hack') --:addHeader(username, 'icr-title') retval:addRow('','') --:addWikitext('File:https://minotar.net/armor/bust'..username..'.png') retval:addRow( 'Username', input, 'icr-f', 'icr-f icr-data' ) if rank == 'Wanderer' then retval:addRow('Rank', formattedrank, 'icr-wanderer icr-data', 'icr-wanderer') else retval:addRow( 'Rank', formattedrank, 'icr-7 icr-data', 'icr-7' ) end retval:addRow( 'UUID', uuid, 'icr-data' ) retval:addRow( 'Balance', string.format("%.2f", userdata.balance),'icr-data icr-7', 'icr-7') retval:addHeader( 'Miscellaneous Stats', 'icr-header' ) retval:addRow( 'Join Count', userdata.joins, 'icr-data' ) retval:addRow( 'Trust Level', userdata.trustlevel, 'icr-data icr-7', 'icr-7') retval:addRow( 'Player Kills', userdata.pkilled, 'icr-data' ) retval:addRow( 'Mob Kills', userdata.creatureskilled, 'icr-data icr-7', 'icr-7' ) retval:addRow( 'Deaths', userdata.deaths, 'icr-data' ) retval:addRow( 'Blocks Traveled', userdata.traveled, 'icr-data icr-7', 'icr-7' ) retval:addRow( 'Blocks Placed', userdata.blocksplaced, 'icr-data' ) retval:addRow( 'Items Dropped', userdata.itemsdropped, 'icr-data icr-7', 'icr-7' ) retval:addRow( 'Blocks Broken', userdata.blocksdestroyed, 'icr-data') if villagels == nil then retval:addRow( 'Villages', 'ERROR', 'icr-data') else local villageconcat = table.concat(villagels, ', ') retval:addRow('Villages', villageconcat) end return retval end end end else return 'something went horribly wrong' end end return p