diff options
| author | olive <olive@olive.ooo> | 2026-09-17 20:29:09 +0100 |
|---|---|---|
| committer | olive <olive@olive.ooo> | 2026-09-17 20:29:09 +0100 |
| commit | 9157750d04dfb2863bc5822b908336e663b141b1 (patch) | |
| tree | 3ec8ac81aef2ea1e67db38d6c2b013ee8dddab33 | |
| parent | 87ed4adab569504e4ce053f8288a84404f63c8dc (diff) | |
Use shortname config rather than hard-coding [x] and so on.
Pylons may also make their own choce in how they format the short-name
when sending out (or do it differently altogether), rather than it being
baked-in by the receiving pylon.
| -rw-r--r-- | discord/pylon.lua | 9 | ||||
| -rw-r--r-- | irc/pylon.lua | 8 | ||||
| -rw-r--r-- | main.lua | 8 | ||||
| -rw-r--r-- | nanochat/pylon.lua | 22 | ||||
| -rw-r--r-- | pylon.lua | 1 | ||||
| -rw-r--r-- | quaddle/pylon.lua | 7 | ||||
| -rw-r--r-- | todo.txt | 28 | ||||
| -rw-r--r-- | xmpp/pylon.lua | 21 |
8 files changed, 69 insertions, 35 deletions
diff --git a/discord/pylon.lua b/discord/pylon.lua index 15a1418..64fe921 100644 --- a/discord/pylon.lua +++ b/discord/pylon.lua @@ -53,7 +53,7 @@ function Discord._req(self, url, payload) if wait>5 then self.log:warn("isn't",wait,"a little long to be waiting?") end cqueues.sleep(wait) end - + if #bod == 0 then return nil end local val, _, err = json.decode(bod) if err then error(err) else return val end @@ -132,9 +132,10 @@ function Discord.handle_dispatch(self, event) and d.author.id ~= self.channel_to_webhook[d.channel_id].id and d.author.id ~= self.bot_id then - self.wilson:deliver(Channel(self, d.channel_id), { + self.wilson:deliver({ + source_channel = Channel(self, d.channel_id), body = d.content, - sender = '[d]' .. d.author.username, + sender = d.author.username, }) end end @@ -145,7 +146,7 @@ function Discord.sending(self) self.log:proto('>',dest_channel,message.sender,message.body) local wh = self.channel_to_webhook[dest_channel.descriptor] self:_req('webhooks/'..wh.id..'/'..wh.token, { - username = message.sender, + username = message.sender.." ["..message.source_channel.pylon.shortname.."]", content = message.body, }) end diff --git a/irc/pylon.lua b/irc/pylon.lua index db88c6c..11c8250 100644 --- a/irc/pylon.lua +++ b/irc/pylon.lua @@ -34,9 +34,10 @@ function Irc.recving(self) local channel_name = msg.args[1] local body = msg.args[2] local sender = msg.source - self.wilson:deliver(Channel(self, channel_name), { + self.wilson:deliver({ + source_channel = Channel(self, channel_name), body = body, - sender = sender..'[i]' + sender = sender, }) elseif msg.op == 'ERROR' then error(msg.args[1]) @@ -64,8 +65,9 @@ function Irc.sending(self) say('WILSON', '#test', 'i am wilson') for dest_channel, message in self.inbox:iter() do + local nick = message.sender.."["..message.source_channel.pylon.shortname.."]" local channel_name = dest_channel.descriptor - say(message.sender, channel_name, message.body) + say(nick, channel_name, message.body) end end @@ -51,12 +51,12 @@ function Wilson._find_bus(self, channel) end self.log:warn("unfound bus for",channel) end -function Wilson.deliver(self, source_channel, message) - local bus = self:_find_bus(source_channel) +function Wilson.deliver(self, message) + local bus = self:_find_bus(assert(message.source_channel)) if bus then for _, dest_channel in ipairs(bus) do - if source_channel ~= dest_channel then - self.log:debug(source_channel, "-->", dest_channel, message) + if message.source_channel ~= dest_channel then + self.log:debug(message.source_channel, "-->", dest_channel, message) dest_channel.pylon:post(dest_channel, message) end end diff --git a/nanochat/pylon.lua b/nanochat/pylon.lua index 8e510bc..6546f05 100644 --- a/nanochat/pylon.lua +++ b/nanochat/pylon.lua @@ -22,33 +22,33 @@ end function Nanochat:recving() while true do self.sock:write("SKIP "..self.lastid.."\n") - local deliverables = {} + local deliverables = {} -- holey local n = tonumber(assert(self.sock:read("*l"))) for i=1,n do local msg = assert(self.sock:read("*l")) local chan, msgi = msg:match("^([^ ]+) ()") if chan then - if not deliverables[chan] then deliverables[chan] = {} end local sender, body = msg:match("^([^:]+): (.+)$", msgi) if sender then - deliverables[chan][#deliverables[chan]+1] = { i=i, sender="[n]"..sender, body=body } + deliverables[i] = { source_channel=Channel(self, chan), sender=sender, body=body } else - deliverables[chan][#deliverables[chan]+1] = { i=i, sender="[n]", body=msg:sub(msgi,-1) } + deliverables[i] = { source_channel=Channel(self, chan), sender="", body=msg:sub(msgi,-1) } end + else + -- ignore messages without a channel, they stay nanochat-local end end local s = self.sock:read("*l") self.lastid = tonumber(assert(s)) - for chan,blorp in pairs(deliverables) do - for _,d in ipairs(blorp) do - local id = d.i - n + self.lastid - d.i = nil + for i=1,n do + local msg = deliverables[i] ; if msg then + local id = i - n + self.lastid if self.usids[id] then self.usids[id] = nil else - self.log:proto('<',chan,d.sender,d.body) - self.wilson:deliver(Channel(self, chan), d) + self.log:proto('<', msg.source_channel.descriptor, msg.sender, msg.body) + self.wilson:deliver(msg) end end end @@ -60,7 +60,7 @@ end function Nanochat:sending() for dest_channel, message in self.inbox:iter() do self.log:proto('>',dest_channel,message.sender,message.body) - assert(self.sock:write("SEND "..dest_channel.descriptor.." "..message.sender..": "..message.body.."\n")) + assert(self.sock:write("SEND "..dest_channel.descriptor.." ["..message.source_channel.pylon.shortname.."] "..message.sender..": "..message.body.."\n")) local id = tonumber(assert(self.sock:read("*l"))) self.usids[id] = true end @@ -13,6 +13,7 @@ function BasePylon.make(cls, wilson, conf) self.wilson = wilson self.inbox = Queue() self.log = Log(self.name,self.loglevel) + self:_check_fields"shortname" self:init() return self end function BasePylon._check_fields(self, fields) for k in qw.i(fields) do diff --git a/quaddle/pylon.lua b/quaddle/pylon.lua index d176260..2213a76 100644 --- a/quaddle/pylon.lua +++ b/quaddle/pylon.lua @@ -81,9 +81,10 @@ end function Quaddle.handle_message(self, msg) self.log:proto('<',msg.channel_id,msg.author.username,msg.content) if msg.author.id ~= self.bot_user.id then - self.wilson:deliver(Channel(self, msg.channel), { + self.wilson:deliver({ + source_channel = Channel(self, msg.channel), body = msg.content, - sender = '[q]' .. msg.author.name, + sender = msg.author.name, }) end end @@ -93,7 +94,7 @@ function Quaddle.sending(self) self.log:proto('>', dest_channel, message.sender, message.body) self:_req('channels/'..dest_channel.descriptor..'/messages', { - content = message.sender..": "..message.body, + content = "["..message.source_channel.pylon.shortname.."] "..message.sender..": "..message.body, }) end end @@ -1,7 +1,27 @@ -pylon.subclass should not have a pylon_type arg. is only used for logging. a pylon's _name_ should be used in log messages. - -pylons harcode prepend names with [x] [d] [n] etc. this is not robust and is weird it should be in some way dynamic? maybe pylons can have configured short names? but then what in the case of two channels with different users of the same nick? they should not be conflated.. - discord and quaddle hard-depend on the configured url ending with a / note that http does not conflate // into / in the path. + +at least for nanochat, multiple coros interact with the socket. a little work has been done to lower the chances of one yielding and then another trying to do things and reading stuff meant for the other one, but it's a race condition. there is no way to do a write() then read() without a potential race condition, or magically knowing how much to read exactly. so, the socket should be directly controlled by a single thread of execution, then the recv and send coros should interact with that via *>An Interface<* (robotic voice) (i.e. wrap the protocol away into a protocoller and the pylon only deals with the messages and not lower details) + + + +2026-09-15 13:47:16+0100 error [xmpp-olive] ./xmpp/pylon.lua:98: attempt to call a string value (local 'x') +2026-09-15 13:47:16+0100 error [(toplevel)] 👉xmpp-olive ./xmpp/pylon.lua:98: attempt to call a string value (local 'x') +stack traceback: + ./xmpp/pylon.lua:98: in function 'xmpp.pylon.recving' +lua5.4: 👉(toplevel) 👉xmpp-olive ./xmpp/pylon.lua:98: attempt to call a string value (local 'x') +stack traceback: + ./xmpp/pylon.lua:98: in function 'xmpp.pylon.recving' +stack traceback: + [C]: in function 'error' + ./log.lua:42: in function 'log.loop' + ./pylon.lua:30: in function 'pylon.run' +stack traceback: + [C]: in function 'error' + ./log.lua:42: in function 'log.loop' + main.lua:71: in method 'run' + main.lua:78: in main chunk + [C]: in ? + +yielding() iterator inside of cqueues where the iterator uses cqueues read inside of itself mayyy be causing issues?? rebecca says no it's using the proper cqueues coro wrapper. diff --git a/xmpp/pylon.lua b/xmpp/pylon.lua index 930a54c..90a155a 100644 --- a/xmpp/pylon.lua +++ b/xmpp/pylon.lua @@ -56,8 +56,10 @@ function Xmpp.add_channel(self, channel) bot.user, bot.nick, bot.user_jid, bot.nick_jid = self:ensure_and_get_user(channel.descriptor, "wilson") end -function Xmpp.ensure_and_get_user(self, muc_jid, nick) +function Xmpp.ensure_and_get_user(self, muc_jid, msg_sender, source_pylon) local muc = assert(self.mucs[muc_jid]) + local nick = msg_sender + if source_pylon then nick = nick.."["..source_pylon.shortname.."]" end local user = muc.nick_to_user[nick] if user then local user_jid = user..'@'..self.component @@ -68,7 +70,12 @@ function Xmpp.ensure_and_get_user(self, muc_jid, nick) -- join up new user user = nick:gsub("[^a-zA-Z0-9%.]","."):match("^%.*(.-)%.*$") - while muc.user_to_nick[user] do user = user..'-' end + if source_pylon then + while muc.user_to_nick[user.."."..source_pylon.name] do user = user..'-' end + user = user.."."..source_pylon.name + else + while muc.user_to_nick[user] do user = user..'-' end + end muc.nick_to_user[nick] = user muc.user_to_nick[user] = nick @@ -94,7 +101,6 @@ function Xmpp.recving(self) return t(self.sock:read'-2048') end for x in xml.stanzae(getmore) do - ::next:: self.log:debug(xmlify(x)) if type(x) == 'string' then self.log:warn("x was a string: ("..x..")") @@ -111,20 +117,23 @@ function Xmpp.recving(self) and from_nick and not muc.nick_to_user[from_nick] then self.log:proto('<',from_bare_jid,from_nick,body) - self.wilson:deliver(Channel(self, from_bare_jid), { + self.wilson:deliver({ + source_channel = Channel(self, from_bare_jid), body = body, - sender = '[x]'..from_nick + sender = from_nick, }) end end end + ::next:: end end function Xmpp.sending(self) for dest_channel, message in self.inbox:iter() do self.log:proto('>',dest_channel,message.sender,message.body) - local user, nick, user_jid, nick_jid = self:ensure_and_get_user(dest_channel.descriptor, message.sender) + local user, nick, user_jid, nick_jid + = self:ensure_and_get_user(dest_channel.descriptor, message.sender, message.source_channel.pylon) self.sock:write(xmlify( X.message{to=dest_channel.descriptor, type='groupchat', from=user_jid, X.body{message.body}})) |
