Ch-ch-ch-changeees!~
This commit is contained in:
parent
0f31751105
commit
81410ef5a5
6 changed files with 102 additions and 6 deletions
|
@ -43,6 +43,10 @@ function bot:OnChannelMessage(Username, Channel, Message)
|
|||
end
|
||||
end
|
||||
|
||||
if Command == nil then
|
||||
Channel:Say("No command given.")
|
||||
return
|
||||
end
|
||||
if not self._commands[Command] then
|
||||
local FellBack = hook.Call("bot.UnknownCommand", Username, Channel, Command, Arguments)
|
||||
if not FellBack then
|
||||
|
|
|
@ -204,6 +204,8 @@ function plugin.PrepareEnvironment(plugin_id)
|
|||
Env.DBI = DeepCopy(require('DBI'))
|
||||
local https = require('ssl.https')
|
||||
Env.https = DeepCopy(https)
|
||||
local http = require("socket.http")
|
||||
Env.http = DeepCopy(http)
|
||||
Env.print = print
|
||||
Env.error = error
|
||||
Env.tonumber = tonumber
|
||||
|
|
|
@ -12,6 +12,7 @@ function reactor:Initialize(quantum)
|
|||
self._co_sleep = {}
|
||||
self._co_event = {}
|
||||
self._coroutines = {}
|
||||
self._ev_timeout = {}
|
||||
|
||||
self._timers = {}
|
||||
self._events = {}
|
||||
|
@ -41,12 +42,27 @@ function reactor.Event:Wait()
|
|||
if Status == false then
|
||||
-- exception!
|
||||
error(Data)
|
||||
end
|
||||
end
|
||||
return unpack(Data)
|
||||
end
|
||||
|
||||
function reactor.Event:WaitTimeout(Timeout)
|
||||
if coroutine.running() == nil then
|
||||
error("Main thread waiting for event... wtf?")
|
||||
end
|
||||
self.Waiting[#self.Waiting + 1] = coroutine.running()
|
||||
reactor._ev_timeout[self.Identifier] = {self, os.time() + Timeout, coroutine.running()}
|
||||
local Status, Data = coroutine.yield()
|
||||
print("Event result")
|
||||
print(Status)
|
||||
print(Data)
|
||||
return Status, unpack(Data)
|
||||
end
|
||||
|
||||
function reactor.Event:Fire(...)
|
||||
local Data = {...}
|
||||
-- remove any timeout events
|
||||
reactor._ev_timeout[self.Identifier] = nil
|
||||
-- make a local copy of the old waiters, and clear the new ones
|
||||
local Waiters = {}
|
||||
for i, Coroutine in pairs(self.Waiting) do
|
||||
|
@ -75,6 +91,7 @@ function reactor:NewEvent()
|
|||
reactor.Event.__index = reactor.Event
|
||||
|
||||
self._events[Table.Identifier] = Identifier
|
||||
print("New event " .. tostring(Table.Identifier))
|
||||
return Table
|
||||
end
|
||||
|
||||
|
@ -124,13 +141,25 @@ function reactor:Run()
|
|||
end
|
||||
end
|
||||
end
|
||||
-- See, if we should wake up any sleepers
|
||||
-- See if we should wake up any sleepers
|
||||
for Coroutine, Timeout in pairs(self._co_sleep) do
|
||||
if os.time() > Timeout then
|
||||
self._co_sleep[Coroutine] = nil
|
||||
coroutine.resume(Coroutine)
|
||||
end
|
||||
end
|
||||
-- See if any event timeouts expired
|
||||
for k, v in pairs(self._ev_timeout) do
|
||||
local Event = v[1]
|
||||
local Timeout = v[2]
|
||||
local Coroutine = v[3]
|
||||
if Timeout < os.time() then
|
||||
print("Timeout firing for event " .. tostring(Event.Identifier))
|
||||
self._ev_timeout[k] = nil
|
||||
self._events[Event.Identifier] = nil
|
||||
coroutine.resume(Coroutine, false, "Timeout")
|
||||
end
|
||||
end
|
||||
hook.Call('ReactorTick')
|
||||
local Time = os.time()
|
||||
for TimerName, Data in pairs(self._timers) do
|
||||
|
|
|
@ -19,6 +19,11 @@ plugin.AddCommand('at', 0, function(Username, Channel)
|
|||
if Data.sensors and Data.sensors.people_now_present then
|
||||
local Sensor = Data.sensors.people_now_present[1]
|
||||
local Users = Sensor.names or {}
|
||||
for k, v in pairs(Users) do
|
||||
if v == "nuke" then
|
||||
Users[k] = "STASZKE?!"
|
||||
end
|
||||
end
|
||||
if #Users == 0 then
|
||||
Channel:Say("-ENOPEOPLE")
|
||||
else
|
||||
|
@ -212,10 +217,52 @@ plugin.AddCommand('kapela', 0, function(Username, Channel)
|
|||
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('sage', 1, function(Username, Channel, Target)
|
||||
if Target == "klacz" or Target == "ood" then
|
||||
irc:_Send("KICK " .. Channel.Name .. " " .. Username .. " :Gdzie na pana rękę podnosisz, polski psie?!")
|
||||
if Target == "klacz" or Target == "ood" or Target == "moonspeak" then
|
||||
Channel._irc:_Send("KICK " .. Channel.Name .. " " .. Username .. " :Gdzie na pana rękę podnosisz, polski psie?!")
|
||||
else
|
||||
irc:_Send("KICK " .. Channel.Name .. " " .. Target .. " :Your behaviour is not conducive to the desired environment.")
|
||||
Channel._irc:_Send("KICK " .. Channel.Name .. " " .. Target .. " :Your behaviour is not conducive to the desired environment.")
|
||||
end
|
||||
end, "Remove kebab")
|
||||
|
||||
plugin.AddHook("irc.Message", "CyckiObusieczne", function(Username, Channel, Message)
|
||||
if Channel.Name == "#hackerspace-pl" and Message:match("^ *:cycki") then
|
||||
if Username ~= "ood" then
|
||||
ghannel: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)
|
||||
|
|
|
@ -9,14 +9,22 @@ plugin.AddHook('auth.GetAccount', 'GetAccount', function(IRC, Username)
|
|||
Pending[Username] = Event
|
||||
IRC:Whois(Username)
|
||||
end
|
||||
return Pending[Username]:Wait()
|
||||
local Status, Data = Pending[Username]:WaitTimeout(2)
|
||||
if Status == false then
|
||||
print("Timeout on getting auth event.")
|
||||
return nil
|
||||
end
|
||||
print("Got auth event.")
|
||||
return Data
|
||||
end
|
||||
return Map[Username]
|
||||
end)
|
||||
|
||||
plugin.AddHook('irc.GetResponse330', 'WHOISResponse', function(_, Username, Account, Message)
|
||||
print("Got response for WHOIS for " .. Username .. " who is logged in as " .. Account)
|
||||
Map[Username] = Account
|
||||
if Pending[Username] ~= nil then
|
||||
print("...and firing event for that user: " .. Account)
|
||||
Pending[Username]:Fire(Account)
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -41,11 +41,17 @@ plugin.AddCommand('eval', -1, function(User, Channel, String)
|
|||
Env.print = function(...)
|
||||
local Args = {...}
|
||||
local Output = table.concat(Args, "\t")
|
||||
if #Output > 128 then
|
||||
Output = Output:sub(1,128) .. " [...] (truncated)"
|
||||
end
|
||||
Channel:Say("stdout: " .. Output)
|
||||
end
|
||||
|
||||
setfenv(Function, Env)
|
||||
local Result, Message = pcall(Function)
|
||||
if #Message > 128 then
|
||||
Message = Message:sub(1,128) .. " [...] (truncated)"
|
||||
end
|
||||
if Result then
|
||||
Channel:Say("OK -> " .. tostring(Message))
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue