Lights in SpaceAPI
This commit is contained in:
parent
a4762aa45f
commit
5dd20cb66c
1 changed files with 32 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue