diff options
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 88 |
1 files changed, 70 insertions, 18 deletions
@@ -1,34 +1,86 @@ -local irc=require'irc' -local xmpp=require'xmpp' -local discord=require'discord' +local cqueues = require'cqueues' + +local pylon_types = { + irc = require'irc', + xmpp = require'xmpp', +} + +local Network = {} +function Network.make(pylon_confs, bus_confs) + local self = { + pylons={}, + busses={}, + cq = cqueues.new(), + } + for pylonname, conf in pairs(pylon_confs) do + local pty = pylon_types[conf.type] + self.pylons[pylonname] = pty.makepylon(pylonname, conf, self.cq, self) + print("constructed pylon",pylonname,conf.type) + end + for busname, conf in pairs(bus_confs) do + local bus = {} + for _, item in ipairs(conf) do + table.insert(bus, {pylonname=item[1], channel=item[2]}) + end + self.busses[busname] = bus + end + return setmetatable(self, {__index=Network}) +end +function Network._find_bus(self, pylonname, channel) + for name, bus in pairs(self.busses) do + for _, entry in ipairs(bus) do + if entry.pylonname == pylonname and entry.channel == channel then + return bus + end + end + end + print("warning: unfound bus for",pylonname,channel) +end +function Network.post(self, pylonname, channel, message) + local bus = self:_find_bus(pylonname, channel) + if bus then + for _, dest in ipairs(bus) do + if not (dest.pylonname == pylonname and dest.channel == channel) then + local target_pylon = self.pylons[dest.pylonname] + target_pylon.inbox:enqueue(dest.channel, message) + end + end + end +end +function Network.run(self) + for pylonname, pylon in pairs(self.pylons) do + self.cq:wrap(pylon.run, pylon) + print("now running pylon", pylonname) + end + print(self.cq:loop()) +end + + + local pylon_confs = { xmpp_ubq323 = { type='xmpp', jid='wilson@ubq323.website', - server='ubq323.website', - auth='...', + server='localhost', + component='wilson.ubq323.website', + component_secret='super_secret_wilson_password', resource='wilson', }, - irc_apionet = { + irc_local = { + type='irc', host='localhost', - port=6667 + port=6667, password='mypassword', nodename='wilson.ubq323', }, } - -local pylons = {} -for name, conf in pairs(pylon_confs) do - pylons[name] = pylon_types[conf.type].make_pylon(name, conf) -end - - -local channels = { +local bus_confs = { d = { - {xmpp_ubq323, 'd@conference.ubq323.website'}, - {irc_apionet, '#d'}, + {'xmpp_ubq323', 'd@conference.ubq323.website'}, + {'irc_local', '#test'}, }, } - +local the_network = Network.make(pylon_confs, bus_confs) +the_network:run() |