diff options
| author | olive <olive@olive.ooo> | 2026-09-12 17:41:39 +0100 |
|---|---|---|
| committer | olive <olive@olive.ooo> | 2026-09-12 17:41:39 +0100 |
| commit | 3687e97db6c035d0cc7065f5d22d801e6553bb2a (patch) | |
| tree | ac18569462557827c3637e7538bf8ca52c7a5eea | |
| parent | 6b23f969dd3d89146b6ace5ee53aef46cfbdd339 (diff) | |
Nanochat!
| -rw-r--r-- | main.lua | 1 | ||||
| -rw-r--r-- | nanochat_send/pylon.lua | 72 | ||||
| -rw-r--r-- | wilson.ini.example | 7 |
3 files changed, 80 insertions, 0 deletions
@@ -6,6 +6,7 @@ local pylon_classes = { irc = require'irc.pylon', xmpp = require'xmpp.pylon', discord = require'discord.pylon', + nanochat_send = require'nanochat_send.pylon', } local Wilson = {} diff --git a/nanochat_send/pylon.lua b/nanochat_send/pylon.lua new file mode 100644 index 0000000..5263e1b --- /dev/null +++ b/nanochat_send/pylon.lua @@ -0,0 +1,72 @@ +local Queue = require 'queue' +local cqueues = require 'cqueues' +local pylon = require 'pylon' +local pprint = require 'pprint' +local Channel = require 'channel' +local socket = require 'cqueues.socket' + +local NanochatSend = pylon.subclass "nanochat_send" + + +function NanochatSend:init() + self:check_config "server port poll" +end + +function NanochatSend:_connect() + if not self.sock then + 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 +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 8a06b03..859d23b 100644 --- a/wilson.ini.example +++ b/wilson.ini.example @@ -17,8 +17,15 @@ type=discord token=bot_token_here temp_wh=webhook_here +[pylon nanochat-gloop] +type=nanochat_send +server=gloop.woop.example +port=44322 +poll=5 + [bus test] xmpp-barbaz test@conference.example.org irc-boopbanana #test discord-foobar channel_id_here +nanochat-gloop #test |
