From 5dd20cb66c220d6ecff984784c1df1de9ad4e6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20Baza=C5=84ski?= Date: Tue, 11 Mar 2014 13:56:06 +0100 Subject: [PATCH] Lights in SpaceAPI --- plugins/hackerspace.lua | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/plugins/hackerspace.lua b/plugins/hackerspace.lua index 88e5c47..727c434 100644 --- a/plugins/hackerspace.lua +++ b/plugins/hackerspace.lua @@ -19,7 +19,7 @@ plugin.AddCommand('at', 0, function(Username, Channel) local Sensor = Data.sensors.people_now_present[1] local Users = Sensor.names or {} if #Users == 0 then - Channel:Say("Trochę Łotwa. Nawet zimnioka nie ma.") + Channel:Say("-ENOPEOPLE") else Channel:Say(table.concat(Users, ', ')) end @@ -28,6 +28,37 @@ plugin.AddCommand('at', 0, function(Username, Channel) end end, "Show who's at the Warsaw Hackerspace.") +plugin.AddCommand("lights", 0, function(Username, Channel)local URL = SpaceAPI[Channel.Name] + if not URL then + Channel:Say("This is not a hackerspace channel!") + return + end + local Body, Code, Headers = https.request(URL) + + if Code ~= 200 then + error(string.format("Status code returned: %i", Code)) + end + + local Data = json.decode.decode(Body) + if Data.sensors and Data.sensors.ext_lights then + local Lights = Data.sensors.ext_lights[1] + local LightsOn = {} + for Light, Status in pairs(Lights) do + if Status then + LightsOn[#LightsOn+1] = Light + end + end + if #LightsOn == 0 then + Channel:Say("No lights on.") + else + Channel:Say("Lights on in: " .. table.concat(LightsOn, ", ")) + end + else + Channel:Say("Halo? Hackerspace? Macie wy światała w SpaceAPI?") + end + +end, "Show lights status") + 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