450 lines
16 KiB
Lua
450 lines
16 KiB
Lua
local SpaceAPI = {}
|
||
SpaceAPI['#hackerspace-pl-members'] = 'https://hackerspace.pl/spaceapi'
|
||
SpaceAPI['#hackerspace-krk'] = 'https://hskrk-spacemon.herokuapp.com/'
|
||
|
||
plugin.AddCommand('at', 0, function(Username, Channel)
|
||
if Channel.Name:match("^#hackerspace%-pl") then
|
||
local URL = 'https://at.hackerspace.pl/api'
|
||
local Body, Code, Headers = https.request(URL)
|
||
if Code ~= 200 then
|
||
error("Status code returned: " .. Code)
|
||
end
|
||
local Data = json.decode.decode(Body)
|
||
local Line = ""
|
||
local Users = {}
|
||
for k, v in pairs(Data.users) do
|
||
if v["login"] == "nuke" then
|
||
Users[#Users+1] = "STASZKE?!"
|
||
else
|
||
Users[#Users+1] = v["login"]
|
||
end
|
||
end
|
||
if #Users == 0 and Data.unknown == 0 and Data.kektops == 0 and Data.esps == 0 then
|
||
Line = "-ENOPEOPLE"
|
||
else
|
||
local Parts = Users
|
||
local Categories = {}
|
||
Categories['esps'] = {'ESP8266', 'ESP8266es'}
|
||
Categories['kektops'] = {'kektop', 'kektops'}
|
||
Categories['unknown'] = {'unknown device', 'unknown devices'}
|
||
if Channel.Name:match("gimbaza") then
|
||
Categories['unknown'] = {'NORMIEEEEE', 'NORMIEEEEEES'}
|
||
end
|
||
for K, V in pairs(Categories) do
|
||
local Count = Data[K] or 0
|
||
if Count == 1 then
|
||
Parts[#Parts+1] = "one " .. V[1]
|
||
elseif Count > 0 then
|
||
Parts[#Parts+1] = tostring(Count) .. " " .. V[2]
|
||
end
|
||
end
|
||
if #Parts == 1 then
|
||
Line = Parts[1]
|
||
else
|
||
local Last = Parts[#Parts]
|
||
Parts[#Parts] = nil
|
||
|
||
Line = table.concat(Parts, ", ") .. ", " .. Last
|
||
end
|
||
if #Users == 0 then
|
||
Line = Line:gsub("^%l", string.upper) .. "."
|
||
else
|
||
Line = Line .. " and five lathes."
|
||
end
|
||
end
|
||
|
||
Channel:Say(Line)
|
||
else
|
||
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.people_now_present then
|
||
local Sensor = Data.sensors.people_now_present[1]
|
||
local Users = Sensor.names or {}
|
||
if #Users == 0 then
|
||
Channel:Say("-ENOPEOPLE")
|
||
else
|
||
Channel:Say(table.concat(Users, ', '))
|
||
end
|
||
else
|
||
Channel:Say("API się wzięło i zjebało.")
|
||
end
|
||
end
|
||
end, "Show who's at the Warsaw Hackerspace.", 0)
|
||
|
||
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 światła w SpaceAPI?")
|
||
end
|
||
|
||
end, "Show lights status")
|
||
|
||
|
||
-- TOOD(q3k): change this to SpaceAPI once our sensors are there
|
||
plugin.AddCommand("sensors", 0, function(Username, Channel)
|
||
local Body, Code, Headers = http.request("http://dht01api.waw.hackerspace.pl")
|
||
if Code ~= 200 then
|
||
error("Oi lad, the dht01 api is down")
|
||
end
|
||
local TA, TB, HA, HB = Body:match("temperature:(%d+),(%d+)*C humidity:(%d+),(%d+)%%")
|
||
if TA == nil or TB == nil or HA == nil or HB == nil then
|
||
error("Oi lad, the dht01 speaks garbage")
|
||
end
|
||
Channel:Say(string.format("%d.%d °C, %d.%d %%RH.", TA, TB, HA, HB))
|
||
end, "Show sensor status")
|
||
|
||
local function SayDue(Target, Channel)
|
||
local Body, Code, Headers, Status = https.request('https://kasownik.hackerspace.pl/api/months_due/' .. Target:lower() .. '.json')
|
||
if Code == 404 then
|
||
Channel:Say("No such member.")
|
||
return
|
||
end
|
||
if Code == 410 then
|
||
Channel:Say("HTTP 410 Gone.")
|
||
return
|
||
end
|
||
if Code == 420 then
|
||
Channel:Say("HTTP 420 Stoned.")
|
||
return
|
||
end
|
||
if Code ~= 200 then
|
||
error(string.format("Status code returned: %s", 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 their 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)
|
||
if not WarsawHackerspaceChannels[Channel.Name] then
|
||
return
|
||
end
|
||
SayDue(Target, Channel)
|
||
end, "Show months due for user.")
|
||
|
||
plugin.AddCommand('due-me', 0, function(Username, Channel)
|
||
if not WarsawHackerspaceChannels[Channel.Name] then
|
||
return
|
||
end
|
||
SayDue(Username, Channel)
|
||
end, "Show months due for speaker.")
|
||
|
||
Nagged = {}
|
||
plugin.AddHook('irc.Message', 'nag', function(Username, Channel, Message)
|
||
if not WarsawHackerspaceChannels[Channel.Name] then
|
||
return
|
||
end
|
||
local Target = Username:lower()
|
||
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'] > 1 then
|
||
Nagged[Target] = os.time() + 60 * 60 * 24
|
||
local Months = 'months'
|
||
if Data['content'] == 1 then
|
||
Months = 'month'
|
||
end
|
||
if Username == "maciek" then
|
||
--Channel:Say(string.format('%s: chujuuuuu zaplac skladki chujuuu jestes %i miesiecy do tylu chujuuu', Username, Data['content']))
|
||
return
|
||
end
|
||
Channel:Say(string.format('%s: pay your membership fees! you are %i %s behind!', Username, Data['content'], Months))
|
||
end
|
||
end
|
||
end
|
||
end)
|
||
|
||
plugin.AddHook('irc.Message', 'winner', function(Username, Channel, Message)
|
||
if Username ~= 'ood' and Message == '1st' then
|
||
Channel._irc:_Send("kick " .. Channel.Name .. " " .. Username .. " :we have a winner!")
|
||
end
|
||
end)
|
||
|
||
plugin.AddHook('irc.Message', 'ebin', function(Username, Channel, Message)
|
||
Message = string.match(Message, ":+_+D+")
|
||
if Message then
|
||
if Channel.Name == "#hackerspace-krk" then
|
||
return
|
||
end
|
||
-- fuuuuuuuuuck
|
||
local countChar = function(s, c)
|
||
local Replaced, _ = string.gsub(s, "[^" .. c .. "]", "")
|
||
return #Replaced
|
||
end
|
||
local CountA = countChar(Message, ":")
|
||
local CountB = countChar(Message, "_")
|
||
local CountC = countChar(Message, "D")
|
||
local Ebin = string.rep(":", CountA) .. string.rep("_", CountB+1) .. string.rep("D", CountC+1)
|
||
Channel:Say(Ebin)
|
||
end
|
||
end)
|
||
|
||
WarsawHackerspaceChannels = {}
|
||
WarsawHackerspaceChannels["#hackerspace-pl"] = true
|
||
WarsawHackerspaceChannels["#hackerspace-pl-gimbaza"] = true
|
||
WarsawHackerspaceChannels["#hackerspace-pl-members"] = true
|
||
|
||
plugin.AddCommand('mana', 0, function(Username, Channel)
|
||
if not WarsawHackerspaceChannels[Channel.Name] then
|
||
return
|
||
end
|
||
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
|
||
local Counter = 0
|
||
for Row in db:Query('select _oid::text from _term where lower(_name) = lower(?);', Term) do
|
||
local Oid = Row._oid
|
||
for Row2 in db:Query('select _text from _entry where _term_oid = ?', Oid) do
|
||
if not Header then
|
||
Channel:Say(string.format('I heard "%s" is:', Term))
|
||
Header = true
|
||
end
|
||
local Text = Row2._text
|
||
Channel:Say(string.format('[%i] ', Counter) .. Text)
|
||
Counter = Counter + 1
|
||
end
|
||
end
|
||
if not Header then
|
||
Channel:Say("No such term!")
|
||
end
|
||
|
||
end, "Describe a saved term.")
|
||
|
||
plugin.AddHook('bot.UnknownCommand', 'DescribeTerm', function(Username, Channel, Command, Arguments)
|
||
local db = plugin.DBOpen('main')
|
||
for Row in db:Query('select _oid::text from _term where lower(_name) = lower(?);', Command) do
|
||
local Oid = Row._oid
|
||
for Row2 in db:Query('select _text from _entry where _term_oid = ? order by random() limit 1;', Oid) do
|
||
Channel:Say(Row2._text)
|
||
return true
|
||
end
|
||
end
|
||
end)
|
||
|
||
|
||
|
||
local DominosIEStatus = function(token)
|
||
local URL = "https://www.dominos.ie/pizzaTracker/getOrderDetails?id=" .. token
|
||
local Body, Code, Headers = https.request(URL)
|
||
if Code ~= 200 then
|
||
return nil
|
||
end
|
||
local Data = json.decode.decode(Body)
|
||
return Data.statusId
|
||
end
|
||
|
||
local DominosIETranslate = function(status)
|
||
if status == 7 then
|
||
return "Order placed"
|
||
end
|
||
if status == 6 then
|
||
return "Preparing"
|
||
end
|
||
if status == 5 then
|
||
return "Baking"
|
||
end
|
||
if status == 9 then
|
||
return "Out for delivery"
|
||
end
|
||
return "UNKNOWN(" .. tostring(status) .. ")"
|
||
end
|
||
|
||
pizzas = {}
|
||
plugin.AddCommand('dominosie', 1, function(Username, Channel, Token)
|
||
local Status = DominosIEStatus(Token)
|
||
if Status == nil then
|
||
Channel:Say(Username .. ": bitch please, that's not a valid token.")
|
||
return
|
||
end
|
||
Channel:Say(Username .. ": Status: " .. DominosIETranslate(Status))
|
||
pizzas[#pizzas+1] = {Channel, Username, Token, Status}
|
||
end)
|
||
plugin.AddHook('irc.Message', 'dominosienag', function(Username, Channel, Message)
|
||
for K, V in pairs(pizzas) do
|
||
local TChannel = V[1]
|
||
local Username = V[2]
|
||
local Token = V[3]
|
||
local Status = V[4]
|
||
if TChannel.Name == Channel.name then
|
||
local NewStatus = DominosIEStatus(Token)
|
||
if NewStatus ~= Status then
|
||
V[4] = NewStatus
|
||
Channel:Say(Username .. ": pizza is: " .. DominosIETranslate(Status))
|
||
end
|
||
end
|
||
end
|
||
end)
|
||
|
||
plugin.AddCommand('op', 1, function(Username, Channel, Target)
|
||
Channel._irc:_Send(string.format("MODE %s +o %s", Channel, Target))
|
||
end, "Give operator status to someone on the channel.", 40)
|
||
|
||
bandnames = nil
|
||
bandnames_check = nil
|
||
|
||
plugin.AddCommand('kapela', 0, function(Username, Channel)
|
||
if bandnames_check == nil or bandnames_check + 3600 < os.time() then
|
||
local Body, Code, Headers = https.request('http://www.reddit.com/r/Bandnames/top/.json?sort=top&t=month')
|
||
if Code ~= 200 then
|
||
Channel:Say("Reddit API doesn't like us, got " .. tostring(Code))
|
||
return
|
||
end
|
||
local Data = json.decode.decode(Body)
|
||
bandnames = {}
|
||
for k, v in pairs(Data['data']['children']) do
|
||
bandnames[#bandnames+1] = v['data']['title']
|
||
end
|
||
bandnames_check = os.time()
|
||
end
|
||
-- fuck I forgot to expose random() to the API
|
||
local Bandname = bandnames[(os.time() % #bandnames) + 1]
|
||
Channel:Say(Bandname)
|
||
end, "Get a bandname from /r/Bandnames")
|
||
|
||
plugin.AddCommand('hswan', 0, function(Username, Channel)
|
||
local Body, Code, Headers = http.request('http://bgpapi.hackerspace.pl/api/1/neighbors.json')
|
||
if Code ~= 200 then
|
||
Channel:Say("Oh shit BGPAPI seems to be down.")
|
||
return
|
||
end
|
||
local Data = json.decode.decode(Body)
|
||
local Established = {}
|
||
local Down = {}
|
||
for k, v in pairs(Data) do
|
||
if v['state'] == 'Established' then
|
||
Established[#Established+1] = v['description']
|
||
else
|
||
Down[#Down+1] = v['description']
|
||
end
|
||
end
|
||
local Body, Code, Headers = http.request('http://bgpapi.hackerspace.pl/api/1/routes.json')
|
||
if Code ~= 200 then
|
||
Channel:Say("Oh shit BGPAPI seems to be down.")
|
||
return
|
||
end
|
||
local Data = json.decode.decode(Body)
|
||
local Routes = {}
|
||
for k, v in pairs(Data) do
|
||
Routes[#Routes+1] = v['prefix']
|
||
end
|
||
|
||
Channel:Say("Peers UP: " .. table.concat(Established, ", "))
|
||
Channel:Say("Peers DOWN: " .. table.concat(Down, ", "))
|
||
Channel:Say("Prefixes: " .. table.concat(Routes, ", "))
|
||
end, "Get HSWAN BGP status")
|
||
|
||
plugin.AddCommand('lednow', 1, function(Username, Channel, URL)
|
||
local Body, Core, Headers = http.request('http://led.waw.hackerspace.pl/api/1/webled/playlist/play/now?uri=' .. URL)
|
||
local Data = json.decode.decode(Body)
|
||
Channel:Say(Username .. ": " .. Data['error'])
|
||
end, "Play something on the space LED display.")
|
||
|
||
plugin.AddCommand('ledappend', 1, function(Username, Channel, URL)
|
||
local Body, Core, Headers = http.request('http://led.waw.hackerspace.pl/api/1/webled/playlist/play/append?uri=' .. URL)
|
||
local Data = json.decode.decode(Body)
|
||
Channel:Say(Username .. ": " .. Data['error'])
|
||
end, "Play something on the space LED display.")
|
||
|
||
plugin.AddCommand('sage', 1, function(Username, Channel, Target)
|
||
if Target == "klacz" or Target == "ood" or Target == "moonspeak" or Target == "q3k" then
|
||
Channel._irc:_Send("KICK " .. Channel.Name .. " " .. Username .. " :Gdzie na pana rękę podnosisz, polski psie?!")
|
||
else
|
||
Channel._irc:_Send("REMOVE " .. Channel.Name .. " " .. Target .. " :Your behaviour is not conducive to the desired environment.")
|
||
end
|
||
end, "Remove kebab")
|
||
|
||
plugin.AddCommand('gimbaza', 1, function(Username, Channel, Target)
|
||
if Target == "klacz" or Target == "ood" or Target == "moonspeak" or Target == "q3k" then
|
||
Channel._irc:_Send("KICK " .. Channel.Name .. " " .. Username .. " :Gdzie na pana rękę podnosisz, polski psie?!")
|
||
else
|
||
Channel._irc:_Send("REMOVE " .. Channel.Name .. " " .. Target .. " :/j #hackerspace-pl-gimbaza")
|
||
end
|
||
end, "Remove gimbaza")
|
||
|
||
plugin.AddCommand('play', -1, function(Username, Channel, Song)
|
||
Channel:Say("ɴᴏᴡ ᴘʟᴀʏɪɴɢ: " .. Song)
|
||
Channel:Say("───────────────⚪────────────────────────────")
|
||
Channel:Say("◄◄⠀▐▐ ⠀►►⠀⠀ ⠀ 1:17 / 3:48 ⠀ ───○ 🔊⠀ ᴴᴰ ⚙ ❐ ⊏⊐")
|
||
end)
|
||
|
||
plugin.AddHook("irc.Message", "CyckiObusieczne", function(Username, Channel, Message)
|
||
if Channel.Name == "#hackerspace-pl" and Message:match("^ *:cycki") then
|
||
if Username ~= "ood" then
|
||
Channel:Say(Username .. ": oh no you didn't!")
|
||
plugin.Sleep(3)
|
||
Channel._irc:_Send("KICK " .. Channel.Name .. " " .. Username .. " :Your behaviour is not conducive to the desired environment.")
|
||
end
|
||
end
|
||
end)
|
||
|
||
plugin.AddCommand('bawr', 0, function(Username, Channel, Target)
|
||
local Body, Core, Headers = https.request('https://isbawra.live/json')
|
||
local Data = json.decode.decode(Body)
|
||
if Data['error'] ~= '' then
|
||
Channel:Say('isbawr.alive dead :(')
|
||
else
|
||
Channel:Say('bawr is ' .. Data['state'] .. ' ' .. Data['human'] .. ' (from isbawra.live)')
|
||
end
|
||
end, 'jew health check')
|