diff options
| author | rebecca <ubq323@ubq323.website> | 2026-09-25 16:41:52 +0100 |
|---|---|---|
| committer | rebecca <ubq323@ubq323.website> | 2026-09-25 16:49:36 +0100 |
| commit | 28a876fa341174e8d17640fc215854328ce65b42 (patch) | |
| tree | 64be5771e6dd48e0d45a3cdc65bcda1f62369277 | |
| parent | 89c71b2939ce610b4251d0d9f22b9e0d2217a106 (diff) | |
consistentize 'channels' maps in pylons
for live reloading to work, wilson needs to know which channels
each pylon currently cares about, so it knows which combination of
add_channel and remove_channel to call on each one
discord: rename channel_to_webhook --> channels
xmpp: rename mucs --> channels
quaddle: add channels map
| -rw-r--r-- | discord/pylon.lua | 12 | ||||
| -rw-r--r-- | main.lua | 2 | ||||
| -rw-r--r-- | quaddle/pylon.lua | 2 | ||||
| -rw-r--r-- | xmpp/pylon.lua | 9 |
4 files changed, 13 insertions, 12 deletions
diff --git a/discord/pylon.lua b/discord/pylon.lua index ebf185d..c2afc3a 100644 --- a/discord/pylon.lua +++ b/discord/pylon.lua @@ -15,7 +15,7 @@ local API_BASE = "https://discord.com/api/v10/" local Discord = class.extend(BasePylon) function Discord.init(self) self:_check_fields "token" - self.channel_to_webhook = {} + self.channels = {} end local function identify_payload(token) @@ -76,14 +76,14 @@ function Discord.add_channel(self, channel) for _,wh in pairs(webhooks) do if wh.application_id == self.bot_id then self.log("Found existing webhook for channel",channel.id) - self.channel_to_webhook[channel.id] = wh + self.channels[channel.id] = {wh=wh} return end end self.log("Making webhook for channel",channel.id) local wh = self:_req("channels/"..channel.id.."/webhooks", { name=self.name:gsub("discord",""):gsub("clyde","").." wilson hook" }) - self.channel_to_webhook[channel.id] = wh + self.channels[channel.id] = {wh=wh} end function Discord._heartbeating(self, interval_ms) @@ -121,8 +121,8 @@ function Discord.handle_dispatch(self, event) if event.t == 'MESSAGE_CREATE' then self.log:proto('<',d.channel_id,d.author.username,d.content) if - self.channel_to_webhook[d.channel_id] - and d.author.id ~= self.channel_to_webhook[d.channel_id].id + self.channels[d.channel_id] + and d.author.id ~= self.channels[d.channel_id].wh.id and d.author.id ~= self.bot_id then self.wilson:deliver(Message { @@ -138,7 +138,7 @@ end function Discord.sending(self) for dest_channel, message in self.inbox:iter() do self.log:proto('>',dest_channel,message.author,message.body) - local wh = self.channel_to_webhook[dest_channel.id] + local wh = self.channels[dest_channel.id].wh self:_req('webhooks/'..wh.id..'/'..wh.token, { username = message.author:name_with_shortname(), content = message.body, @@ -47,7 +47,7 @@ function Wilson.make(cls, conf) end function Wilson.add_channels_for(self, pylon) - if not pylon.add_channel then return end + if not pylon.channels then return end for busname, bus in pairs(self.busses) do for _, channel in ipairs(bus) do if channel.pylon == pylon then diff --git a/quaddle/pylon.lua b/quaddle/pylon.lua index 86e465a..20eeb3a 100644 --- a/quaddle/pylon.lua +++ b/quaddle/pylon.lua @@ -10,6 +10,7 @@ local Thing = require 'thing' local Quaddle = class.extend(BasePylon) function Quaddle.init(self) self:_check_fields "base_url bot_name bot_password" + self.channels = {} end -- https://codeberg.org/QWD/Quaddle/src/branch/main/doc/api.md @@ -46,6 +47,7 @@ end function Quaddle.add_channel(self, channel) self.log("Subscribing to channel",channel.id) self.ws:send(json.encode{ op="subscribe", channel_id=channel.id }) + self.channels[channel.id] = true end function Quaddle.recving(self) diff --git a/xmpp/pylon.lua b/xmpp/pylon.lua index d00c41b..a3415dd 100644 --- a/xmpp/pylon.lua +++ b/xmpp/pylon.lua @@ -13,8 +13,7 @@ local Xmpp = class.extend(BasePylon) function Xmpp.init(self) self:_check_fields"server component component_secret" - - self.mucs = {} + self.channels = {} end -- only use on local connections! @@ -44,13 +43,13 @@ end function Xmpp.add_channel(self, channel) local muc = { nick_to_user={}, user_to_nick={} } - self.mucs[channel.id] = muc + self.channels[channel.id] = muc local bot = {} ; self.bot = bot bot.user, bot.nick, bot.user_jid, bot.nick_jid = self:ensure_and_get_user(channel.id, "wilson") end function Xmpp.ensure_and_get_user(self, muc_jid, nick, source_pylon) - local muc = assert(self.mucs[muc_jid]) + local muc = assert(self.channels[muc_jid]) local user = muc.nick_to_user[nick] if user then local user_jid = user..'@'..self.component @@ -101,7 +100,7 @@ function Xmpp.recving(self) if x.label == 'message' then local from_bare_jid, from_nick if x.xarg.from then from_bare_jid, from_nick = x.xarg.from:match"(.*)/(.*)" end - local muc = self.mucs[from_bare_jid] ; if muc then + local muc = self.channels[from_bare_jid] ; if muc then if x.xarg.to == 'wilson@'..self.component and body |
