Jump to content

Module:Bot task

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SD0001 (talk | contribs) at 15:12, 22 February 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

local function has_value (array, val)
    for index, value in ipairs(array) do
        if value == val then
            return true
        end
    end
    return false
end


function p._main(args)
	
	-- check for invalid parameters
	for param, value in pairs(args) do
		if not has_value({'bot','task','min_edits','duration','title_regex','title','namespaces','action','summary','summary_regex'}, param) then
			return '*<div class=error>Unknown paramter: ' .. param .. ' used</div>'
		end
	end
	
	if not args.bot or not args.task then
		return '*<div class=error>Required paramters "bot" and/or "task" missing</div>'
	end
	
	-- set defaults if not given
	args.min_edits = args.min_edits or 1
	args.duration = args.duration or '1 day'
	
	local str = string.format("* [[User:%s|%s]]: %s. '''Frequency''': minimum %s action%s in the last %s. ", 
		args.bot, args.bot,
		args.task, 
		args.min_edits, 
		args.min_edits == 1 and '' or 's', 
		args.duration
	)
	
	if args.title_regex then
		str = str .. string.format("'''Pages''': matching <code>%s</code> %s", args.title_regex, args.namespaces and "in namespace(s). " .. args.namespaces or '')
	elseif args.title then
		str = str .. string.format("'''Page''': [[%s]] ", args.title)
	elseif args.namespaces then
		str = str .. string.format("In namespace(s) %s. ", args.namespaces)
	end
	
	if args.summary_regex then
		str = str .. string.format("With summary matching <code>%s</code>. ", args.summary_regex)
	elseif args.summary then
		str = str .. string.format("With summary <code>%s</code>. ", args.summary)
	end
	
	if (args.action and args.action ~= 'edit') then
		str = str .. string.format("Type of action: %s ", args.action)
	end
	

	return str
end

return p