Module:Staff

-- local p = {}

local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local string = require('Module:String') local table = require('Module:Table') local checkType = require('libraryUtil').checkType

local roles = { ['bureaucrat'] = { class="user-link-bcrat", title="Bureaucrat", plural="Bureaucrats", short="Bcrat", shortPlural="Bcrats", link="Bureaucrats", order=7, };	['administrator'] = { class="user-link-admin", title="Administrator", plural="Administrators", short="Admin", shortPlural="Admins", link="Admins", order=6, };		['code editor'] = { class="user-link-codeeditor", title="Code Editor", plural="Code Editors", short="Cde Edtr", shortPlural="Cde Edtrs", link="Code Editors", order=5, };	['content moderator'] = { class="user-link-mod", title="Content Moderator", plural="Content Moderators", short="Content Mod", shortPlural="Content Mods", link="Content_Moderators", order=4, };	['discussions moderator'] = { class="user-link-dmod", title="Discussions Moderator", plural="Discussions Moderators", short="Disc Mod", shortPlural="Disc Mods", link="Discussions_Moderators", order=3, };	['rollback'] = { class="user-link-rollback", title="Rollbacker", plural="Rollbackers", short="Rlbckr", shortPlural="Rlbckrs", link="Rollbackers", order=2, };	['bot'] = { class="user-link-bot", title="Bot", plural="Bots", short="Bot", shortPlural="Bots", link="Bots", order=1, }; }

local aliases = { ['bur']='bureaucrat', ['bcrat']='bureaucrat', ['bureau']='bureaucrat', ['bureaucrat']='bureaucrat', ['crat']='bureaucrat', ['b']='bureaucrat', ['admin']='administrator', ['adm']='administrator', ['ad']='administrator', ['administrator']='administrator', ['administr']='administrator', ['sysop']='administrator', ['ce'] = 'code editor', ['codeeditor'] = 'code editor', ['code editor'] = 'code editor', ['code'] = 'code editor', ['code edit'] = 'code editor', ['c e'] = 'code editor', ['cd edit'] = 'code editor', ['cde edit'] = 'code editor', ['codeedit'] = 'code editor', ['cdeedit'] = 'code editor', ['cde edtr'] = 'code editor', ['cdeedtr'] = 'code editor', ['content']='content moderator', ['cont']='content moderator', ['cont mod']='content moderator', ['cont moderator']='content moderator', ['content mod']='content moderator', ['content moderator']='content moderator', ['c moderator']='content moderator', ['c mod']='content moderator', ['cm']='content moderator', ['content-moderator']='content moderator', ['d mod']='discussions moderator', ['d moderator']='discussions moderator', ['disc mod']='discussions moderator', ['disc moderator']='discussions moderator', ['discuss m']='discussions moderator', ['discuss mod']='discussions moderator', ['discuss moderator']='discussions moderator', ['disc m']='discussions moderator', ['discussions m']='discussions moderator', ['discussions mod']='discussions moderator', ['discussions moderator']='discussions moderator', ['dm']='discussions moderator', ['thread-moderator']='discussions moderator', ['threadmoderator']='discussions moderator', ['th']='discussions moderator', ['th m']='discussions moderator', ['thr mod']='discussions moderator', ['thread mod']='discussions moderator', ['t mod']='discussions moderator', ['rollback']='rollback', ['roll']='rollback', ['rollb']='rollback', ['rb']='rollback', ['rollbacker']='rollback', ['rback']='rollback', ['b']='bot', ['bot']='bot', ['robot']='bot', ['bt']='bot', }

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 success, response = pcall(p._staffRole, name, alt, plural, shorten, linkAlt) return success and response or string.error(response) end

function p._staffRole(name, alt, plural, shorten, linkAlt) 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) 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(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

return p