Module:Staff

-- local p = {}

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

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

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

local lang = mw.language.getContentLanguage

-- This is for generating staff strings for AF:41 -- Staff name not listed here will be the name itself -- All staff and retired staff are handled in the list local abuseFilterRegexSpecialCases = { Thundercraft5 = 'Thundercraft\\d?', Pa3ckP7 = 'Pa\\d?ckP\\d', }

local function getdaysinmonth(m, y)	local t = { 31, 28 + (((y % 4 == 0 and y % 100 ~= 0) or y % 400 == 0) and 1 or 0), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } return t[m] end

-- Template:StaffMsgbox function p.staffMsgBox(frame) local args = getArgs(frame) local function createList(ranks) table.sort(ranks, function(a, b)			return thisdata[aliases[a:lower]].order > thisdata[aliases[b:lower]].order 			end) 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 ,				userM.userRole{ v },				#ranks == 2 and ' ' or ''			) end return ret end local ranks = {} if args.user then local user = members[args.user] if not user then error(('User "%s" does not exist on record'):format(args.user)) end if user.rank then ranks = string.split(user.rank, '%|') end else for k, v in pairs(args) do			if tonumber(k) or tostring(k):match('^rank[_ ]?%d*$') then table.push(ranks, v)			end end end local text = (#ranks > 0) and ('This user has the staff role(s) of %s on the Hypixel SkyBlock Wiki. %s'):format(		table.concat(createList(ranks), ''),		string.wrapHtml{			text = 'The Hypixel SkyBlock Wiki is not affiliated with Hypixel Inc. Staff roles on the wiki are unrelated to roles on game servers or sites run by Hypixel Inc.',			tag = 'span',			attrs = { style = 'color: red;' }		}	) or ('\'\'\'This user is a former staff member of the Hypixel SkyBlock Wiki.\'\'\' %s'):format(		string.wrapHtml{			text = 'Please do not message them about matters of the wiki unless necessary.',			tag = 'span',			attrs = { style = 'color: red;' }		}	) return text end

-- Project:Staff/user function p.staffLink(frame) local args = getArgs(frame) local staff = args.staff or args.name or args[1] local rank = args.rank or args.r	local showname = args.showname local showlinks = args.showlinks or args.showlink local notes = args.notes or args.note or args[2] return p._staffLink(name, rank, { showname = showname, showlinks = showlinks, note = notes }) end

function p._staffLink(name, rank, opts) local member = members[name] if not member then string.wrapHtml(('Staff Link: No staff named %s.'):format(name), 'tr', { class = 'error' }) end opts = opts or {} rank = rank or 'RB' if (aliases[rank:lower] or rank:lower) == 'bot' then return ('%s'):format(name, name) end local showname = yesno(opts.showname, true) local disp = showname and userM._userRole(rank, name, nil, nil, ('User:%s'):format(name)) or '' local nolink = yesno(opts.showlinks, true) == false or yesno(opts.showlink, true) == false -- reverse evaluation needed local bull = '\'\'\'&bull;\'\'\'' local links = nolink and  or string.wrapHtml((' \'\'\'(%s %s %s %s %s)\'\'\):format( userM._userRole(rank, 'wall', nil, nil, ('Message_Wall:%s'):format(name)), bull, userM._userRole(rank, 'CC Wall', nil, nil, ('w:c:Message_Wall:%s'):format(name)), bull, userM._userRole(rank, 'contribs', nil, nil, ('Special:Contributions/%s'):format(name)) ), 'small') local note = opts.notes or opts.note note = note and (' (%s)'):format(note) or '' return ('%s%s%s'):format(disp, links, note) end

-- Project:Staff/data function p.staffLookup(frame) local args = getArgs(frame) local lookup = args[1] local mode = args[2] return p._staffLookup(lookup, mode) end

function p._staffLookup(lookup, mode) local function countWith(t, callbackfn) local ret = {} for i, v in pairs(t) do			if callbackfn(v, i, t) then table.push(ret, v)			end end return table.length(ret) end mode = mode or 'list' if lookup:match('^former') then local period = lookup:match('^former (%w+)$') if not period then return string.wrapHtml(('Staff Lookup: Format not valid. Try "former current" or "former past".'):format(lookup), 'tr', { class = 'error' }) end return p._formerLookup(period, mode) end if lookup:match('^total') then local target = lookup:match('^total (.+)$') if target == 'staff' then return countWith(members, function (m)				return not not m.rank			end) elseif target == 'former past' then return countWith(members, function (m)				return not m.rank and m.period == 'past'			end) elseif target == 'former current' then return countWith(members, function (m)				return not m.rank and m.period ~= 'past'			end) else return string.wrapHtml(('Staff Lookup: Format not valid. Try "staff", total former current", or "total former past".'):format(lookup), 'tr', { class = 'error' })		end	end	local roleId = aliases[lookup:lower]	if not roleId then return string.wrapHtml(('Staff Lookup: Role "%s" not valid.'):format(lookup), 'tr', { class = 'error' }) end	local a, count = {}, 0	for staff, staffdata in pairs(members) do		if staffdata.rank then			if (roleId == 'bot' and staffdata.bot) then				a[staff] = staffdata				count = count + table.length(mw.text.split(staffdata.bot, '%|'))			elseif staffdata.rank:match(userData.roles[roleId].code) then				a[staff] = staffdata				count = count + 1			end		end	end	local sortedpairs = table.sortedPairs(a, function(one, two) return one:lower < two:lower end)	if mode == 'num' or mode == 'count' then		return count	elseif mode == 'list' then		local t = {}		if roleId == 'bot' then			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, p._staffLink(bot, 'bot')) end if ownerdata.rank then -- find highest rank of that user, default Rollback local order, highestrank = 0, 'RB' for r in mw.text.gsplit(ownerdata.rank, '%|') do						local rd = thisdata[aliases[lookup:lower] or lookup:lower] if rd then if rd.order > order then order, highestrank = rd.order, r							end end end local row = mw.html.create('tr') row:tag('td'):wikitext(table.concat(temp, ', ')) row:tag('td'):wikitext(p._staffLink(owner, highestrank)) table.push(t, tostring(row)) else table.push(t, ('|-\n| %s || %s'):format( table.concat(temp, ', '), owner, owner ))				end end else for staff, staffdata in sortedpairs do				if not staffdata.rank then return string.wrapHtml(('Staff Lookup: Staff %s does not have the required key "rank".'):format(staff), 'tr', { class = 'error' }) end local row = mw.html.create('tr') row:tag('td'):wikitext(p._staffLink(staff, roleId, { showname = true, showlinks = false })) row:tag('td'):wikitext(p._staffLink(staff, roleId, { showname = false, showlinks = true })) row:tag('td'):wikitext(staffdata.activity or '') table.push(t, tostring(row)) end end return mw.getCurrentFrame:preprocess((table.concat(t))) else return string.wrapHtml(('Staff Lookup: Mode "%s" not valid.'):format(mode or 'nil'), 'tr', { class = 'error' }) end end

function p._formerLookup(period, mode) mode = mode or 'list' local a = {} for staff, staffdata in pairs(members) do		local p = staffdata.period or 'current' if staffdata.resignation and p == period then if not staffdata.former then return string.wrapHtml(('Staff Lookup: Staff %s does not have the required key "former".'):format(staff), 'tr', { class = 'error' }) end -- verify date local y, m, d = staffdata.resignation:match('^(%d+)%-(%d+)%-(%d+)$') y, m, d = tonumber(y), tonumber(m), tonumber(d) if (not y) or (not m) or (not d) or (y > 2099) or (y < 2019) or (not getdaysinmonth(m, y)) or (d < 1) or (d > getdaysinmonth(m, y)) then return string.wrapHtml(('Staff Lookup: Resignation date "%s" for %s not valid.'):format(staffdata.resignation, staff), 'tr', { class = 'error' }) end a[#a + 1] = table.merge(table.deepCopy(staffdata, true), { name = staff, y = y, m = m, d = d }) end end table.sort(a, function(one, two)		-- sort by resignation date; if equal, sort by name		if one.y == two.y then			if one.m == two.m then				if one.d == two.d then					return one.name:lower < two.name:lower				else					return one.d > two.d				end			else				return one.m > two.m			end		else			return one.y > two.y		end	end) if mode == 'num' or mode == 'count' then return table.length(a) elseif mode == 'list' then local t = {} for _, staffdata in ipairs(a) do			local u = {} for r in mw.text.gsplit(staffdata.former, '%|') do				local success, response = pcall(userM._userRole, r)				if success then table.push(u, userM._userRole(r)) else string.wrapHtml(('Staff Lookup: Role "%s" for %s not valid.'):format(r, nm), 'tr', { class = 'error' }) end end local row = mw.html.create('tr') row:tag('td'):wikitext(('%s'):format(staffdata.name, staffdata.name)) row:tag('td'):wikitext(mw.text.listToText(u)) row:tag('td'):wikitext(lang:formatDate('j F Y', (staffdata.resignation))) table.push(t, tostring(row)) end return mw.getCurrentFrame:preprocess(table.concat(t)) else return string.wrapHtml(('Staff Lookup: Mode "%s" not valid.'):format(mode or 'nil'), 'tr', { class = 'error' }) end end

function p.abuseFilterStaffString -- local members = table.deepCopy(members, true) local t = table.keys(members) -- special cases for name, replacement in pairs(abuseFilterRegexSpecialCases) do		local i = table.findIndex(t, name) if i then t[i] = replacement end end return table.concat(t, "|") end

return p