From 1f9192f9d6639dedd243532616fb034f0e5bb14a Mon Sep 17 00:00:00 2001 From: rebecca Date: Sat, 12 Sep 2026 20:01:32 +0100 Subject: rename nanochat_send -> nanochat --- main.lua | 2 +- nanochat/pylon.lua | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ nanochat_send/pylon.lua | 74 ------------------------------------------------- wilson.ini.example | 2 +- 4 files changed, 76 insertions(+), 76 deletions(-) create mode 100644 nanochat/pylon.lua delete mode 100644 nanochat_send/pylon.lua diff --git a/main.lua b/main.lua index 61c75ef..cd81b0e 100644 --- a/main.lua +++ b/main.lua @@ -8,7 +8,7 @@ local pylon_classes = { irc = require'irc.pylon', xmpp = require'xmpp.pylon', discord = require'discord.pylon', - nanochat_send = require'nanochat_send.pylon', + nanochat = require'nanochat.pylon', } local Wilson = class() diff --git a/nanochat/pylon.lua b/nanochat/pylon.lua new file mode 100644 index 0000000..7dae58b --- /dev/null +++ b/nanochat/pylon.lua @@ -0,0 +1,74 @@ +local cqueues = require 'cqueues' +local socket = require 'cqueues.socket' +local pprint = require 'pprint' +local class = require 'r.class' + +local BasePylon = require 'pylon' +local Channel = require 'channel' + +local Nanochat = class.extend(BasePylon) + +function Nanochat:init() + self:_check_fields "server port poll" +end + +function Nanochat:_connect() + self.sock = socket.connect(self.server, tonumber(self.port)) + self.sock:write("LAST 0\n") + self.sock:read("*l") -- discard count + self.lastid = tonumber(assert(self.sock:read("*l"))) + self.usids = {} +end + +function Nanochat:add_channel(channel) + -- don't need to do anything +end + +function Nanochat:recving() + while true do + self.sock:write("SKIP "..self.lastid.."\n") + local deliverables = {} + 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=sender, body=body } + else + deliverables[chan][#deliverables[chan]+1] = { i=i, sender=nil, body=msg:sub(msgi,-1) } + end + 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 + if self.usids[id] then + self.usids[id] = nil + else + self.wilson:deliver(Channel(self, chan), d) + end + end + end + + cqueues.sleep(tonumber(self.poll)) + end +end + +function Nanochat:sending() + for dest_channel, message in self.inbox:iter() do + print('NNN',dest_channel,message.sender,message.body) + assert(self.sock:write("SEND "..dest_channel.descriptor.." "..message.sender..": "..message.body.."\n")) + local id = tonumber(assert(self.sock:read("*l"))) + self.usids[id] = true + end +end + + +return Nanochat diff --git a/nanochat_send/pylon.lua b/nanochat_send/pylon.lua deleted file mode 100644 index f7cd60f..0000000 --- a/nanochat_send/pylon.lua +++ /dev/null @@ -1,74 +0,0 @@ -local cqueues = require 'cqueues' -local socket = require 'cqueues.socket' -local pprint = require 'pprint' -local class = require 'r.class' - -local BasePylon = require 'pylon' -local Channel = require 'channel' - -local NanochatSend = class.extend(BasePylon) - -function NanochatSend:init() - self:_check_fields "server port poll" -end - -function NanochatSend:_connect() - self.sock = socket.connect(self.server, tonumber(self.port)) - self.sock:write("LAST 0\n") - self.sock:read("*l") -- discard count - self.lastid = tonumber(assert(self.sock:read("*l"))) - self.usids = {} -end - -function NanochatSend:add_channel(channel) - -- don't need to do anything -end - -function NanochatSend:recving() - while true do - self.sock:write("SKIP "..self.lastid.."\n") - local deliverables = {} - 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=sender, body=body } - else - deliverables[chan][#deliverables[chan]+1] = { i=i, sender=nil, body=msg:sub(msgi,-1) } - end - 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 - if self.usids[id] then - self.usids[id] = nil - else - self.wilson:deliver(Channel(self, chan), d) - end - end - end - - cqueues.sleep(tonumber(self.poll)) - end -end - -function NanochatSend:sending() - for dest_channel, message in self.inbox:iter() do - print('NNN',dest_channel,message.sender,message.body) - assert(self.sock:write("SEND "..dest_channel.descriptor.." "..message.sender..": "..message.body.."\n")) - local id = tonumber(assert(self.sock:read("*l"))) - self.usids[id] = true - end -end - - -return NanochatSend diff --git a/wilson.ini.example b/wilson.ini.example index 859d23b..ee72645 100644 --- a/wilson.ini.example +++ b/wilson.ini.example @@ -18,7 +18,7 @@ token=bot_token_here temp_wh=webhook_here [pylon nanochat-gloop] -type=nanochat_send +type=nanochat server=gloop.woop.example port=44322 poll=5 -- cgit v1.2.3