From 6bbe91be27eaa3d4735c8ab1be65fe492682bb54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20=27q3k=27=20Baza=C5=84ski?= Date: Wed, 16 Oct 2013 21:24:47 +0200 Subject: [PATCH] More HS commands. --- plugins/hackerspace.lua | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/plugins/hackerspace.lua b/plugins/hackerspace.lua index 1995828..ed83c3a 100644 --- a/plugins/hackerspace.lua +++ b/plugins/hackerspace.lua @@ -16,6 +16,56 @@ plugin.AddCommand('at', 0, function(Username, Channel) end end, "Show who's at the Warsaw Hackerspace.") +local function SayDue(Target, Channel) + local Body, Code, Headers, Status = https.request('https://kasownik.hackerspace.pl/api/months_due/' .. Target .. '.json') + if Code == 404 then + Channel:Say("No such member.") + return + end + if Code ~= 200 then + error(string.format("Status code returned: %i", Code)) + end + + local Data = json.decode.decode(Body) + if Data['status'] ~= 'ok' then + error("No such member?") + else + local Due = Data['content'] + local Comment = "" + if Due < 0 then + Comment = string.format("is %i months ahead. Cool!", -Due) + elseif Due == 0 then + Comment = "has paid all his membership fees." + elseif Due == 1 then + Comment = "needs to pay one membership fee." + else + Comment = string.format("needs to pay %i membership fees.", Due) + end + Channel:Say(Target .. " " .. Comment) + end +end + +plugin.AddCommand('due', 1, function(Username, Channel, Target) + SayDue(Target, Channel) +end, "Show months due for user.") + +plugin.AddCommand('due-me', 0, function(Username, Channel) + SayDue(Username, Channel) +end, "Show months due for speaker.") + +plugin.AddCommand('mana', 0, function(Username, Channel) + local Body, Code, Headers, Status = https.request('https://kasownik.hackerspace.pl/api/mana.json') + if Code ~= 200 then + error(string.format("Status code returned: %i", Code)) + end + + local Data = json.decode.decode(Body) + local Required = Data['content']['required'] + local Paid = Data['content']['paid'] + local Updated = Data['modified'] + Channel:Say(string.format("%i paid, %i required (last updated %s)", Paid, Required, Updated)) +end, "Show Hackerspace mana (due fees in total.") + plugin.AddCommand('describe', 1, function(Username, Channel, Term) local db = plugin.DBOpen('main') local Header = false @@ -53,3 +103,4 @@ end) plugin.AddCommand('op', 1, function(Username, Channel, Target) irc:_Send(string.format("MODE %s +o %s", Channel, Target)) end, "Give operator status to someone on the channel.", 40) +