Skip to content

Instantly share code, notes, and snippets.

@meskarune
Last active April 4, 2019 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meskarune/490e697d7c983ac96f7a10e54bf2118d to your computer and use it in GitHub Desktop.
Save meskarune/490e697d7c983ac96f7a10e54bf2118d to your computer and use it in GitHub Desktop.
local plugin = {}
local plugin.commands = {}
plugin.polls = {}
plugin.commands.open = function (args)
-- poll open <poll name> <response1, response2, ...>
local _, _, pollid, responses = args.message:find("open%s+(%S+)%s+(.+)")
plugin.polls[#plugin.polls + 1] = { pollid = {poll_creator = args.sender, choices = {}, votes = {} } }
if responses then
for i in responses:gmatch("%S+,?") do
plugin.polls.pollid.choices[#plugin.polls.pollid.choices + 1] = i
end
else
args.modules.irc.privmsg(args.target, ('%s: Please give me a list of poll responses.'):format(args.sender))
return
end
end
plugin.commands.vote = function (args)
local _, _, pollid, vote = args.message:find("vote%s+(%S+)%s+(%S+)")
local voter = args.sender
-- poll vote <poll name> <response>
-- vote on a poll, users who vote twice should be handled
end
plugin.commands.tally = function (args)
local _, _, pollid = args.message:find("tally%s+(%S+)")
-- poll tally <poll name>
-- give current running totals
end
plugin.commands.close = function (args)
local _, _, pollid = args.message:find("close%s+(%S+)")
-- poll close <poll name>
-- print the results of the poll and deletes the table?
-- should it save the data somewhere?
-- only the user who started the poll can close it
end
local h = ''
for k in pairs(plugin.commands) do
h = ('%s|%s'):format(h, k)
end
plugin.help = ('usage: poll <%s>'):format(h:sub(2))
plugin.main = function (args)
local _, _, action = args.message:find('(%S+)')
local f = plugin.commands[action]
if f then return f(args) end
args.modules.irc.privmsg(args.target, plugin.help)
end
return plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment