summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrebecca <ubq323@ubq323.website>2026-09-25 16:33:35 +0100
committerrebecca <ubq323@ubq323.website>2026-09-25 16:35:27 +0100
commit9efee4531261898c5c1666d010a22eab4f3ea457 (patch)
treeef164bfdda3086f8e22a150e465871a2bac9fb4b
parent00060d7965d42386e15dca6361683b72e430808c (diff)
deduplicate add_channel loops
-rw-r--r--discord/pylon.lua8
-rw-r--r--main.lua17
-rw-r--r--pylon.lua1
-rw-r--r--quaddle/pylon.lua8
-rw-r--r--xmpp/pylon.lua8
5 files changed, 11 insertions, 31 deletions
diff --git a/discord/pylon.lua b/discord/pylon.lua
index 6cebc16..ebf185d 100644
--- a/discord/pylon.lua
+++ b/discord/pylon.lua
@@ -69,14 +69,6 @@ function Discord._connect(self)
local me = self:_req"users/@me"
self.bot_id = me.id
self.log('logged in as ',me.username)
-
- for busname, bus in pairs(self.wilson.busses) do
- for _, channel in ipairs(bus) do
- if channel.pylon == self then
- self:add_channel(channel)
- end
- end
- end
end
function Discord.add_channel(self, channel)
diff --git a/main.lua b/main.lua
index d5469d0..bf9a0b6 100644
--- a/main.lua
+++ b/main.lua
@@ -46,13 +46,19 @@ function Wilson.make(cls, conf)
return self
end
--- find bus containing given channel
+function Wilson.add_channels_for(self, pylon)
+ if not pylon.add_channel then return end
+ for busname, bus in pairs(self.busses) do
+ for _, channel in ipairs(bus) do
+ if channel.pylon == pylon then
+ pylon:add_channel(channel)
+end end end end
+
function Wilson._find_bus(self, channel)
for name, bus in pairs(self.busses) do
for _, q in ipairs(bus) do if q == channel then return bus end end
end
- self.log:warn("unfound bus for",channel)
-end
+ self.log:warn("unfound bus for",channel) end
function Wilson.deliver(self, message)
local bus = self:_find_bus(assert(message.channel))
if bus then
@@ -61,10 +67,7 @@ function Wilson.deliver(self, message)
if message.channel ~= dest_channel then
self.log:debug(message.channel, "-->", dest_channel, message)
dest_channel.pylon:post(dest_channel, message)
- end
- end
- end
-end
+end end end end
function Wilson.run(self)
for pylonname, pylon in pairs(self.pylons) do
self.cq:wrap(pylon.run, pylon)
diff --git a/pylon.lua b/pylon.lua
index 9d4a02d..b703495 100644
--- a/pylon.lua
+++ b/pylon.lua
@@ -24,6 +24,7 @@ function BasePylon.run(self)
self.cq = cqueues.new()
self.cq:wrap(function()
self:_connect()
+ self.wilson:add_channels_for(self)
self.log"connected!"
self.cq:wrap(self.recving, self)
self.cq:wrap(self.sending, self)
diff --git a/quaddle/pylon.lua b/quaddle/pylon.lua
index 4387342..86e465a 100644
--- a/quaddle/pylon.lua
+++ b/quaddle/pylon.lua
@@ -41,14 +41,6 @@ function Quaddle._connect(self)
self.ws = websocket.new_from_uri(self.base_url:gsub("^http","ws").."app")
assert(self.ws:connect())
self.ws:send(json.encode{ op="identify", token=self.token }, 'text')
-
- for busname, bus in pairs(self.wilson.busses) do
- for _, channel in ipairs(bus) do
- if channel.pylon == self then
- self:add_channel(channel)
- end
- end
- end
end
function Quaddle.add_channel(self, channel)
diff --git a/xmpp/pylon.lua b/xmpp/pylon.lua
index 9f5ccfe..d00c41b 100644
--- a/xmpp/pylon.lua
+++ b/xmpp/pylon.lua
@@ -39,14 +39,6 @@ function Xmpp._connect(self)
sock:write(xmlify(X.handshake{sha1.sha1(streamid..self.component_secret)}))
check_and_send('<handshake/>',nil)
- for busname, bus in pairs(self.wilson.busses) do
- for _, channel in ipairs(bus) do
- if channel.pylon == self then
- self:add_channel(channel)
- end
- end
- end
-
return sock
end