Module:Staff

-- local p = {}

local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local string, table, yesno, libUtil = loader.require('String', 'Table', 'Yesno', 'LibraryUtil') local checkType = libUtil.checkType

local roles, aliases, members = loader.loadData('Staff/Data', 'Staff/Aliases', 'Staff/Members')

function p.staffRole(frame) local args = getArgs(frame) local name = args[1] local alt = args[2] local plural = yesno(args['plural'] or args['plur'] or args['p'], false) local shorten = yesno(args['short'] or args['shr'] or args['s'], false) local linkAlt = args['link_alt'] or args['link'] or args['linkalt'] or args['la'] or args['l'] local altText = args['alt'] or args['a'] local success, response = pcall(p._staffRole, name, alt, plural, shorten, linkAlt, altText) return success and response or string.error(response) end

function p._staffRole(name, alt, plural, shorten, linkAlt, altText) if type(name) == 'table' then alt = name[2] or name.alt or name.alttext or name.altText plural = name[3] or name.plural shorten = name[4] or name.short or name.shorten linkAlt = name[5] or name.linkAlt or name.link name = name[1] or name.name end if name ==  or name == nil then return  end checkType('_staffRole', 1, name, 'string') checkType('_staffRole', 2, alt, 'string', true) checkType('_staffRole', 3, plural, 'boolean', true) checkType('_staffRole', 4, shorten, 'boolean', true) checkType('_staffRole', 5, linkAlt, 'string', true) checkType('_staffRole', 6, altText, 'string', true) if name:lower:match('(\'?s)$') or plural then plural = true name = name:gsub('(\'?s)$', '') else plural = false end local titleId = aliases[name:gsub('_', ' '):lower] local data = roles[titleId] if not titleId then error(string.format('Invalid staff rank name %s', name), 2) end local function hideAlways(s) return ' ' .. s .. ' '	end if alt then text = alt else if (shorten and plural) then text = data.shortPlural elseif shorten then text = data.short elseif plural then text = data.plural else text = data.title end end if linkAlt and linkAlt:match('https?%:%/%/%S*') then output_text = table.concat{ hideAlways(data.order), '[',			linkAlt, ' ', 			string.wrapHtml(text, ' ', { class=data.class }) ']',		}	elseif linkAlt then output_text = table.concat{ hideAlways(data.order), ,			string.wrapHtml(text, ' ', { class=data.class }),			, }	else output_text = table.concat{ hideAlways(data.order), ,			string.wrapHtml(altText or text, ' ', { class=data.class }),			, }	end return output_text end

function p.staffMsgBox(frame) local args = getArgs(frame) local function createList(ranks) local ret = {} for i, v in ipairs(ranks) do			table.push(ret, 				(#ranks > 2 and i > 1) and ', ' or ,				(#ranks == i and i > 1) and 'and ' or ,				v:match('^([aeiouy]+)') and 'an ' or 'a ', 				p.staffRole{ v },				#ranks == 2 and ' ' or ''			) end return ret end local ranks = {} for k, v in ipairs(args) do		if tonumber(k) or tostring(k):match('^rank[_ ]?%d*$') then table.push(ranks, v)		end end local msgBox = mw.html.create('div') :addClass('messagebox') :attr{ style=args['style'] } :wikitext(table.concat{			'This user is ',			table.concat(createList(ranks), ''),			' on the wiki.',			rank2 and ' ' or ' ',			'The wiki is not affiliated with Hypixel.',			' ',			string.wrapHtml{				text = 'This user is \'\'\'not\'\'\' part of the Hypixel staff and has \'\'\'no\'\'\' power in-game.',				tag = 'span',				attrs = { style='color:red;' }			},		}) return tostring(msgBox) end

-- : -- --   -- function p.staffLookup(frame) local args = getArgs(frame) local lookup = args[1] local mode = args[2] or 'list' role = roles[aliases[lookup:lower] or lookup:lower] if not role then return string.wrapHtml(('Staff Lookup: Role %s not valid.'):format(lookup), 'span', { class = 'error' }) end local code = role.code local a, count = {}, 0 for staff, staffdata in pairs(members) do		if (code == 'BOT' and staffdata.bot) then a[staff] = staffdata count = count + table.length(mw.text.split(staffdata.bot, '%|')) elseif staffdata.rank:match(code) then a[staff] = staffdata count = count + 1 end end local sortedpairs = table.sortedPairs(a, function(one, two) return one < two end) if mode == 'num' or mode == 'count' then return count elseif mode == 'list' then local t = {} if code == 'BOT' then table.push(t, '{| class="article-table"\n!Bot\n!Operator') for owner, ownerdata in sortedpairs do				local temp = {} -- bots by one owner can be separated by the pipe character (|) for bot in mw.text.gsplit(ownerdata.bot, '%|') do					table.push(temp, (''):format(bot)) end table.push(t, ('|-\n| %s || '):format( table.concat(temp, ', '), owner, ownerdata.rank:sub(1,2) -- highest rank ))			end table.push(t, '|}') else for staff, staffdata in sortedpairs do				table.push(t, ('* '):format( staff, staffdata.activity or '', code ))			end end return mw.getCurrentFrame:preprocess((table.concat(t, '\n'))) else return string.wrapHtml(('Staff Lookup: Mode %s not valid.'):format(mode), 'span', { class = 'error' }) end end

return p