From f50a3118640e76fdd6fc245a9138e46f953caffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20Baza=C5=84ski?= Date: Sun, 3 Nov 2013 23:05:16 +0100 Subject: [PATCH] plugins and stuff --- plugins/hackerspace.lua | 74 +++++++++++++++++++++++++++++++++++++++++ plugins/wolfram.lua | 10 ++++++ 2 files changed, 84 insertions(+) create mode 100644 plugins/wolfram.lua diff --git a/plugins/hackerspace.lua b/plugins/hackerspace.lua index 1995828..985f96b 100644 --- a/plugins/hackerspace.lua +++ b/plugins/hackerspace.lua @@ -16,6 +16,80 @@ 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.") + +-- hax +os = {} +os.time = table.time + +Nagged = {} +plugin.AddHook('irc.Message', 'nag', function(Username, Channel, Message) + local Target = Username:lower() + if Target == 'enleth' then return end + if Nagged[Target] == nil or Nagged[Target] < os.time() then + local Body, Code, Headers, Status = https.request('https://kasownik.hackerspace.pl/api/months_due/' .. Target .. '.json') + if Code == 200 then + local Data = json.decode.decode(Body) + if Data['content'] > 0 then + Nagged[Target] = os.time() + 60 * 60 * 24 + local Months = 'months' + if Data['content'] == 0 then + Months = 'month' + end + Channel:Say(string.format('%s: pay your membership fees! you are %i %s behind!', Username, Data['content'], Months)) + end + end + end +end) + +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 diff --git a/plugins/wolfram.lua b/plugins/wolfram.lua new file mode 100644 index 0000000..6e23512 --- /dev/null +++ b/plugins/wolfram.lua @@ -0,0 +1,10 @@ +plugin.AddCommand('c', -1, function(Username, Channel, Line) + local Body, Code = https.request('https://www.wolframalpha.com/input/?i=' .. Line) + if Code == 200 then + Body:gsub('{"stringified": "([^"]+)"', function(m) + Channel:Say(m) + end) + else + Channel:Say('Got weird status code from WA: ' .. tostring(Code)) + end +end, 'Calculate something on Wolfram Alpha')