Module:Sandbox/MjolnirPants

From Wikipedia, the free encyclopedia
local getArgs = require('Module:Arguments').getArgs
p = {}

--Hurls a randomly generated, nonsensical insult.
--Invoke using:
--{{#invoke:MjolnirPants|NonsenseNameCaller}}
p.NonsenseNameCaller = function()
	--set up the syntax
	local syntaxes = {
		"You are a _1_ _2_.", 
		"Go away, you _1_ _2_.", 
		"You _1_ _2_.", 
		"Have you always been so _1_, you _2_?", 
		"Listen, _2_, stop being so _1_."
	}
	local syntaxMax = 5
	
	--set up the adjective
	local adjectives = {
		"bildering",
		"globulish",
		"pustulating",
		"gilberous",
		"blartous"
	}
	local adjMax = 5
	
	--set up the noun
	local nouns = {
		"bustule",
		"narklaholic",
		"gandypuffer",
		"dorkleragger",
		"plonk"
	}
	local nounMax = 5
	
	--pick the three elements
	local seed = math.floor(os.time())
	math.randomseed(seed)
	local syntax = syntaxes[math.random(syntaxMax)]
	local adjective = adjectives[math.random(adjMax)]
	local noun = nouns[math.random(nounMax)]
	
	--make the insult
	local insult = string.gsub(syntax, "_1_", adjective)
	insult = string.gsub(insult, "_2_", noun)
	return insult
end

p.GraphSelector = function()
	--initialize the random number genny
	local seed = math.floor(os.time())
	math.randomseed(seed)
	
	--Get the X and Y offsets
	local xOffset = math.random(10) * 250
	local yOffset = math.random(10) * 250
	
	--Concatenate the string and return it
	local resString = "{{CSS image drop|Image = ECDF-100.png|bSize = 2500|cWidth = 250|cHeight = 250|oTop = " .. xOffset .. "|oLeft = " .. yOffset .. "|Location = left|Description = The blue step function graph shows an empirical distribution function. The grey bars represent the observations in the sample corresponding to the sample’s empirical distribution function, and the green curve, which asymptotically approaches a height of 1 without reaching it, is the true cumulative distribution function.}}"
	
	return resString
end

p.GraphPickerX = function()
	local seed = math.floor(os.time())
	math.randomseed(seed)
	
	--Get the X and Y offsets
	local xOffset = math.random(0, 9) * 250
	
	return xOffset
end

p.GraphPickerY = function()
	local seed = math.floor(os.time()) + 1 -- just to be sure
	math.randomseed(seed)
	
	--Get the X and Y offsets
	local yOffset = math.random(0, 9) * 250
	
	return yOffset
end

function p.test(frame)
	local pgCont = mw.title.new("User:MjolnirPants/Voices"):getContent()
	return pgCont
end

function p.PingRFCUsers(frame)
	local args = getArgs(frame)
	return p._PingRFCUsers(args)
end

function p._PingRFCUsers(args)
	local pageSource = ""
	--check the size of the arguments array
	--if there's more than one, the second one
	--should be the name of the page on which
	--to find the discussion
	if args[2] then
		--get the title from the second argument
		pageSource = mw.title.new(args[2]):getContent()
		flag = 1
	else		
		--If no second parameter was passed, then
		--the discussion is on the current page
		pageSource = mw.title.getCurrentTitle():getContent()
		flag = 2
	end
	
	local users = {}
	local ii = 1
	local i, j = string.find(pageSource, "==" .. args[1])
	pageSource = string.sub(pageSource, i + string.len(args[1]) + 4)
	i, j = string.find(pageSource, "==")
	pageSource = string.sub(pageSource, 1, i - 1)
	i, j = string.find(pageSource, "%[%[User:")
	local uName = ""
	local k, l, m, n = i + 1
	local cat = "Pinging participants of [[#" .. args[1] .."|previous RfC]]: {{ping"
	while i ~= nil do
		i, j = string.find(pageSource, "%[%[User:")
		if j then
			pageSource = string.sub(pageSource, j)
			j = 1
			k, l = string.find(pageSource, "|")
			m, n = string.find(pageSource, "%]%]")
			if (m > k) then
				uName = string.sub(pageSource, j + 1, k - 1)
				pageSource = string.sub(pageSource, k)
			else
				uName = string.sub(pageSource, j + 1, m - 1)
				pageSource = string.sub(pageSource, m)
			end
			users[ii] = uName
			cat = cat .. "|" .. uName
			ii = ii + 1
		end
	end
	
	cat = cat .. "}} ~~~~"
	
	-- local ret = "{{u|"
	
	-- for _, v in ipairs(users) do
		-- ret = ret .. v .. "|"
	-- end
	--return string.sub(ret, 1, string.len(ret) - 1) .. "}}"
	--return pageSource.. "\r\nusers:" .. cat .. "\r\ni:" .. i .. " j:" .. j .. " k:" .. k .. " l:" .. l .. " m:" .. m .. " n:" .. n
	return cat
	--return "\r\n" .. mw.title.new(args[2]):getContent()
end

return p