Difference between revisions of "Module:FRS notification"
Jump to navigation
Jump to search
blackwiki>Naypta (Make it actually work) |
blackwiki>Naypta (Lua indexes arrays from 1...) |
||
| Line 7: | Line 7: | ||
for index, num in ipairs(argNums) do | for index, num in ipairs(argNums) do | ||
num = tostring(num) | num = tostring(num) | ||
| − | finalString = finalString .. frame:expandTemplate{ | + | finalString = finalString .. " " .. frame:expandTemplate{ |
title = 'User:Yapperbot/FRS notification/content', | title = 'User:Yapperbot/FRS notification/content', | ||
args = { | args = { | ||
| Line 15: | Line 15: | ||
} | } | ||
} | } | ||
| − | if #argNums ~= 1 then | + | if #argNums ~= 1 and index ~= #argNums then |
| − | if index == (#argNums - | + | if index == (#argNums - 1) then |
-- penultimate element, append "and" | -- penultimate element, append "and" | ||
| − | finalString = finalString .. " and " | + | finalString = finalString .. " and" |
else | else | ||
| − | finalString = finalString .. ", " | + | finalString = finalString .. "," |
end | end | ||
end | end | ||
Revision as of 22:22, 6 July 2020
This module is used by Yapperbot (talk⧼dot-separator⧽contribs) to deliver the Feedback Request Service's notifications to its users. It allows Yapperbot to queue multiple deliveries and send them simultaneously.
{{#invoke:FRS notification|function_name}}
local p = {}
function p.notification(frame)
finalString = ""
args = frame:getParent().args
argNums = getArgNums(args, "title")
for index, num in ipairs(argNums) do
num = tostring(num)
finalString = finalString .. " " .. frame:expandTemplate{
title = 'User:Yapperbot/FRS notification/content',
args = {
title = args["title" .. num],
rfcid = args["rfcid" .. num],
type = args["type" .. num]
}
}
if #argNums ~= 1 and index ~= #argNums then
if index == (#argNums - 1) then
-- penultimate element, append "and"
finalString = finalString .. " and"
else
finalString = finalString .. ","
end
end
end
return finalString
end
function getArgNums(args, prefix)
-- Returns a table containing the numbers of the arguments that exist
-- for the specified prefix. For example, if the prefix was 'data', and
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
-- This function is adapted from [[Module:Infobox]], and is released under
-- the Creative Commons Attribution-Share-Alike License 3.0.
-- https://creativecommons.org/licenses/by-sa/3.0/
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
end
table.sort(nums)
return nums
end
return p