Module:Bot task
Appearance
Usage
Used in template Wikipedia:Bot activity monitor/config/task.
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 '<span class=error>Unknown paramter: ' .. param .. ' used</span>'
end
end
if not args.bot or not args.task then
return '<span class=error>Required paramters "bot" and/or "task" missing</span>'
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