mun/plugins/hackerspace.lua

451 lines
16 KiB
Lua
Raw Normal View History

2013-11-04 15:52:48 +00:00
local SpaceAPI = {}
2015-03-13 22:53:44 +00:00
SpaceAPI['#hackerspace-pl-members'] = 'https://hackerspace.pl/spaceapi'
2013-11-04 15:52:48 +00:00
SpaceAPI['#hackerspace-krk'] = 'https://hskrk-spacemon.herokuapp.com/'
plugin.AddCommand('at', 0, function(Username, Channel)
2018-09-14 18:34:10 +00:00
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
2013-11-04 11:38:09 +00:00
2018-09-14 18:34:10 +00:00
Line = table.concat(Parts, ", ") .. " and " .. Last
end
if #Users == 0 then
Line = Line:gsub("^%l", string.upper) .. "."
else
Line = Line .. "."
end
end
2018-09-14 18:34:10 +00:00
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
2013-11-04 11:38:09 +00:00
else
2018-09-14 18:34:10 +00:00
Channel:Say("API się wzięło i zjebało.")
2013-11-04 11:38:09 +00:00
end
end
2018-09-14 18:34:10 +00:00
end, "Show who's at the Warsaw Hackerspace.", 0)
2013-09-29 18:33:44 +00:00
2014-03-11 12:58:56 +00:00
plugin.AddCommand("lights", 0, function(Username, Channel)
local URL = SpaceAPI[Channel.Name]
2014-03-11 12:56:06 +00:00
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]
2018-09-14 18:34:10 +00:00
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
2014-03-11 12:56:06 +00:00
else
2014-03-11 12:57:45 +00:00
Channel:Say("Halo? Hackerspace? Macie wy światła w SpaceAPI?")
2014-03-11 12:56:06 +00:00
end
end, "Show lights status")
2018-09-14 18:34:10 +00:00
-- 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")
2013-11-03 22:05:16 +00:00
local function SayDue(Target, Channel)
2018-09-14 18:34:10 +00:00
local Body, Code, Headers, Status = https.request('https://kasownik.hackerspace.pl/api/months_due/' .. Target:lower() .. '.json')
2013-11-03 22:05:16 +00:00
if Code == 404 then
Channel:Say("No such member.")
2018-09-14 18:34:10 +00:00
return
end
if Code == 410 then
Channel:Say("HTTP 410 Gone.")
return
end
if Code == 420 then
Channel:Say("HTTP 420 Stoned.")
return
2013-11-03 22:05:16 +00:00
end
if Code ~= 200 then
2018-09-14 18:34:10 +00:00
error(string.format("Status code returned: %s", Code))
2013-11-03 22:05:16 +00:00
end
local Data = json.decode.decode(Body)
if Data['status'] ~= 'ok' then
error("No such member?")
else
local Due = Data['content']
2018-09-14 18:34:10 +00:00
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
2013-11-03 22:05:16 +00:00
Channel:Say(Target .. " " .. Comment)
end
end
plugin.AddCommand('due', 1, function(Username, Channel, Target)
2015-03-13 22:53:44 +00:00
if not WarsawHackerspaceChannels[Channel.Name] then
return
end
2013-11-03 22:05:16 +00:00
SayDue(Target, Channel)
end, "Show months due for user.")
plugin.AddCommand('due-me', 0, function(Username, Channel)
2015-03-13 22:53:44 +00:00
if not WarsawHackerspaceChannels[Channel.Name] then
return
end
2013-11-03 22:05:16 +00:00
SayDue(Username, Channel)
end, "Show months due for speaker.")
Nagged = {}
plugin.AddHook('irc.Message', 'nag', function(Username, Channel, Message)
2015-03-13 22:53:44 +00:00
if not WarsawHackerspaceChannels[Channel.Name] then
return
end
2013-11-03 22:05:16 +00:00
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)
2013-11-04 11:41:11 +00:00
if Data['content'] > 1 then
2013-11-03 22:05:16 +00:00
Nagged[Target] = os.time() + 60 * 60 * 24
local Months = 'months'
2018-09-14 18:34:10 +00:00
if Data['content'] == 1 then
2013-11-03 22:05:16 +00:00
Months = 'month'
end
2018-09-14 18:34:10 +00:00
if Username == "maciek" then
--Channel:Say(string.format('%s: chujuuuuu zaplac skladki chujuuu jestes %i miesiecy do tylu chujuuu', Username, Data['content']))
return
end
2013-11-03 22:05:16 +00:00
Channel:Say(string.format('%s: pay your membership fees! you are %i %s behind!', Username, Data['content'], Months))
end
end
end
end)
2015-03-13 22:53:44 +00:00
plugin.AddHook('irc.Message', 'winner', function(Username, Channel, Message)
2018-09-14 18:34:10 +00:00
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
2015-03-13 22:53:44 +00:00
end)
WarsawHackerspaceChannels = {}
WarsawHackerspaceChannels["#hackerspace-pl"] = true
2018-09-14 18:34:10 +00:00
WarsawHackerspaceChannels["#hackerspace-pl-gimbaza"] = true
2015-03-13 22:53:44 +00:00
WarsawHackerspaceChannels["#hackerspace-pl-members"] = true
2013-11-03 22:05:16 +00:00
plugin.AddCommand('mana', 0, function(Username, Channel)
2015-03-13 22:53:44 +00:00
if not WarsawHackerspaceChannels[Channel.Name] then
return
end
2013-11-03 22:05:16 +00:00
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))
2015-03-13 23:06:09 +00:00
end, "Show Hackerspace mana (due fees in total).")
2013-11-03 22:05:16 +00:00
2013-09-29 18:33:44 +00:00
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
2015-03-13 23:06:09 +00:00
end
2013-09-29 18:33:44 +00:00
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)
2013-09-29 18:56:06 +00:00
2018-09-14 18:34:10 +00:00
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)
2013-09-29 18:56:06 +00:00
plugin.AddCommand('op', 1, function(Username, Channel, Target)
2018-09-14 18:34:10 +00:00
Channel._irc:_Send(string.format("MODE %s +o %s", Channel, Target))
2013-09-29 18:56:06 +00:00
end, "Give operator status to someone on the channel.", 40)
2013-10-16 19:24:47 +00:00
2015-03-13 22:53:44 +00:00
bandnames = nil
bandnames_check = nil
plugin.AddCommand('kapela', 0, function(Username, Channel)
2018-09-14 18:34:10 +00:00
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)
2015-03-13 22:53:44 +00:00
end, "Get a bandname from /r/Bandnames")
2015-03-13 23:06:09 +00:00
2015-07-21 15:50:39 +00:00
plugin.AddCommand('hswan', 0, function(Username, Channel)
2018-09-14 18:34:10 +00:00
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, ", "))
2015-07-21 15:50:39 +00:00
end, "Get HSWAN BGP status")
2018-09-14 18:34:10 +00:00
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.")
2015-03-13 23:06:09 +00:00
plugin.AddCommand('sage', 1, function(Username, Channel, Target)
2018-09-14 18:34:10 +00:00
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?!")
2015-03-13 23:06:09 +00:00
else
2018-09-14 18:34:10 +00:00
Channel._irc:_Send("REMOVE " .. Channel.Name .. " " .. Target .. " :Your behaviour is not conducive to the desired environment.")
2015-03-13 23:06:09 +00:00
end
end, "Remove kebab")
2015-07-21 15:50:39 +00:00
2018-09-14 18:34:10 +00:00
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)
Channel:Say("ɴᴏᴡ ᴘʟᴀʏɪɴɢ: Despacito")
Channel:Say("───────────────⚪────────────────────────────")
Channel:Say("◄◄⠀▐▐ ⠀►►⠀⠀ 1:17 / 3:48 ───○ 🔊⠀ ᴴᴰ ⚙ ❐ ⊏⊐")
end)
2015-07-21 15:50:39 +00:00
plugin.AddHook("irc.Message", "CyckiObusieczne", function(Username, Channel, Message)
2018-09-14 18:34:10 +00:00
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
2015-07-21 15:50:39 +00:00
end)
2018-09-14 18:34:10 +00:00
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')