Difference between revisions of "Module:FRS notification"
Jump to navigation
Jump to search
blackwiki>Naypta (Setup a module that should work with multiple queued notifications) |
blackwiki>Naypta (Make it actually work) |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| − | function p.notification( frame ) | + | function p.notification(frame) |
finalString = "" | finalString = "" | ||
| − | + | args = frame:getParent().args | |
| − | num = tostring( num ) | + | argNums = getArgNums(args, "title") |
| − | + | for index, num in ipairs(argNums) do | |
| + | num = tostring(num) | ||
finalString = finalString .. frame:expandTemplate{ | finalString = finalString .. frame:expandTemplate{ | ||
title = 'User:Yapperbot/FRS notification/content', | title = 'User:Yapperbot/FRS notification/content', | ||
| Line 14: | Line 15: | ||
} | } | ||
} | } | ||
| + | if #argNums ~= 1 then | ||
| + | if index == (#argNums - 2) then | ||
| + | -- penultimate element, append "and" | ||
| + | finalString = finalString .. " and " | ||
| + | else | ||
| + | finalString = finalString .. ", " | ||
| + | end | ||
| + | end | ||
end | end | ||
return finalString | return finalString | ||
end | end | ||
| − | + | function getArgNums(args, prefix) | |
-- Returns a table containing the numbers of the arguments that exist | -- Returns a table containing the numbers of the arguments that exist | ||
-- for the specified prefix. For example, if the prefix was 'data', and | -- for the specified prefix. For example, if the prefix was 'data', and | ||
Revision as of 22:17, 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 then
if index == (#argNums - 2) 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