summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrebecca <ubq323@ubq323.website>2026-09-24 17:20:42 +0100
committerrebecca <ubq323@ubq323.website>2026-09-24 18:55:05 +0100
commit71cee0014368f5d83fe94989526a4ffb2824f50c (patch)
treecd87a5c7d859d98f48866ff769ef89d60a28d5d5
parentdff5363f96029aba6d0f222d3e31ab3888d7111f (diff)
change fields on Message to include author
-rw-r--r--discord/pylon.lua9
-rw-r--r--irc/pylon.lua9
-rw-r--r--main.lua6
-rw-r--r--nanochat/pylon.lua25
-rw-r--r--quaddle/pylon.lua14
-rw-r--r--store.lua7
-rw-r--r--terminology.txt6
-rw-r--r--thing.lua3
-rw-r--r--todo.txt3
-rw-r--r--xmpp/pylon.lua17
10 files changed, 59 insertions, 40 deletions
diff --git a/discord/pylon.lua b/discord/pylon.lua
index 70c6a40..f035fbc 100644
--- a/discord/pylon.lua
+++ b/discord/pylon.lua
@@ -132,8 +132,9 @@ 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 = Thing(self, d.channel_id, 'channel name here'),
+ self.wilson:deliver(Message {
+ pylon = self,
+ channel = Thing(self, d.channel_id, 'TODO discord channel names'),
author = Thing(self, d.author.id, d.author.username),
body = d.content,
})
@@ -143,10 +144,10 @@ end
function Discord.sending(self)
for dest_channel, message in self.inbox:iter() do
- self.log:proto('>',dest_channel,message.sender,message.body)
+ self.log:proto('>',dest_channel,message.author,message.body)
local wh = self.channel_to_webhook[dest_channel.id]
self:_req('webhooks/'..wh.id..'/'..wh.token, {
- username = message.sender.." ["..message.source_channel.pylon.shortname.."]",
+ username = message.author:name_with_shortname(),
content = message.body,
})
end
diff --git a/irc/pylon.lua b/irc/pylon.lua
index 039ec38..1be3ab2 100644
--- a/irc/pylon.lua
+++ b/irc/pylon.lua
@@ -34,10 +34,11 @@ function Irc.recving(self)
local channel_name = msg.args[1]
local body = msg.args[2]
local sender = msg.source
- self.wilson:deliver({
- source_channel = Thing(self, channel_name),
+ self.wilson:deliver(Message {
+ pylon = self,
+ channel = Thing(self, channel_name),
+ author = Thing(self, sender),
body = body,
- sender = sender,
})
elseif msg.op == 'ERROR' then
error(msg.args[1])
@@ -65,7 +66,7 @@ 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 nick = message.author:name_with_shortname()
local channel_name = dest_channel.id
say(nick, channel_name, message.body)
end
diff --git a/main.lua b/main.lua
index 03f681e..d5469d0 100644
--- a/main.lua
+++ b/main.lua
@@ -54,12 +54,12 @@ function Wilson._find_bus(self, channel)
self.log:warn("unfound bus for",channel)
end
function Wilson.deliver(self, message)
- local bus = self:_find_bus(assert(message.source_channel))
+ local bus = self:_find_bus(assert(message.channel))
if bus then
self.store:store(message)
for _, dest_channel in ipairs(bus) do
- if message.source_channel ~= dest_channel then
- self.log:debug(message.source_channel, "-->", dest_channel, message)
+ if message.channel ~= dest_channel then
+ self.log:debug(message.channel, "-->", dest_channel, message)
dest_channel.pylon:post(dest_channel, message)
end
end
diff --git a/nanochat/pylon.lua b/nanochat/pylon.lua
index 2f408d4..6fbd725 100644
--- a/nanochat/pylon.lua
+++ b/nanochat/pylon.lua
@@ -30,9 +30,19 @@ function Nanochat:recving()
if chan then
local sender, body = msg:match("^([^:]+): (.+)$", msgi)
if sender then
- deliverables[i] = { source_channel=Thing(self, chan), sender=sender, body=body }
+ deliverables[i] = {
+ pylon=self,
+ channel=Thing(self, chan),
+ author=Thing(self,sender),
+ body=body
+ }
else
- deliverables[i] = { source_channel=Thing(self, chan), sender="", body=msg:sub(msgi,-1) }
+ deliverables[i] = {
+ pylon=self,
+ channel=Thing(self, chan),
+ author=Thing(self,""),
+ body=msg:sub(msgi,-1)
+ }
end
else -- luacheck: ignore 542
-- ignore messages without a channel, they stay nanochat-local
@@ -47,7 +57,7 @@ function Nanochat:recving()
if self.usids[id] then
self.usids[id] = nil
else
- self.log:proto('<', msg.source_channel.id, msg.sender, msg.body)
+ self.log:proto('<', msg.channel.id, msg.author, msg.body)
self.wilson:deliver(msg)
end
end
@@ -59,8 +69,13 @@ 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.id.." ["..message.source_channel.pylon.shortname.."] "..message.sender..": "..message.body.."\n"))
+ self.log:proto('>',dest_channel,message.author,message.body)
+ assert(self.sock:write(
+ "SEND "
+ ..dest_channel.id
+ ..message.author:name_with_shortname()
+ ..": "..message.body
+ .."\n"))
local id = tonumber(assert(self.sock:read("*l")))
self.usids[id] = true
end
diff --git a/quaddle/pylon.lua b/quaddle/pylon.lua
index 2d283ea..4387342 100644
--- a/quaddle/pylon.lua
+++ b/quaddle/pylon.lua
@@ -80,22 +80,22 @@ function Quaddle.recving(self)
end
function Quaddle.handle_message(self, msg)
- self.log:proto('<',msg.channel_id,msg.author.username,msg.content)
+ self.log:proto('<',msg.channel_id,msg.author.name,msg.content)
if msg.author.id ~= self.bot_user.id then
- self.wilson:deliver({
- source_channel = Thing(self, msg.channel),
+ self.wilson:deliver(Message {
+ pylon = self,
+ channel = Thing(self, msg.channel),
+ author = Thing(self,msg.author.id,msg.author.username),
body = msg.content,
- sender = msg.author.name,
})
end
end
function Quaddle.sending(self)
for dest_channel, message in self.inbox:iter() do
- self.log:proto('>', dest_channel, message.sender, message.body)
-
+ self.log:proto('>', dest_channel, message.author, message.body)
self:_req('channels/'..dest_channel.id..'/messages', {
- content = "["..message.source_channel.pylon.shortname.."] "..message.sender..": "..message.body,
+ content = message.author:name_with_shortname()..": "..message.body,
})
end
end
diff --git a/store.lua b/store.lua
index 8e0b31e..b978b17 100644
--- a/store.lua
+++ b/store.lua
@@ -38,10 +38,9 @@ function Store.storing(self)
insert into messages (p_type,
p_name,channel,author,ts,body)
values (?, ?, ?, ?, ?, ?); ]],
- msg.source_channel.pylon.type,
- msg.source_channel.pylon.name,
- msg.source_channel.id,--hello.
- msg.sender,os.time(),msg.body)
+ msg.pylon.type,msg.pylon.name,
+ msg.channel.id, msg.author.id,
+ os.time(),msg.body)
self.log("stored",msg.body)
assert(conn:commit()) end end
function Store.store(self, msg) self.q:enqueue(msg) end
diff --git a/terminology.txt b/terminology.txt
index e26085f..a5a8edd 100644
--- a/terminology.txt
+++ b/terminology.txt
@@ -23,11 +23,9 @@ Thing: used in the code for such a tuple of (pylon, pylon-specific-descriptor)
Bus: a family of connected channels that messages will be bridged between
Message: you know what a message is. it has a bunch of fields, which are
- source_channel: the Channel the message came from
- maybe rename to source
+ channel: the channel the message came from (as a Thing)
+ author: the user who created the message (as a Thing)
body: the string contents of the message
- sender: the username (on the source service) of the message's author
- TODO we need more info than that surely
[RFC] Author: a user or personality on a service who created a message
like Channel it's a tuple of (pylon, pylon-specific-descriptor)
diff --git a/thing.lua b/thing.lua
index f7cc32a..eee742b 100644
--- a/thing.lua
+++ b/thing.lua
@@ -19,4 +19,7 @@ function Thing.__tostring(self)
.. ':' .. self.id
.. (self.name == self.id and '('..self.name..')' or '')
end
+function Thing.name_with_shortname(self)
+ return self.name .. ' [' .. self.pylon.shortname .. ']'
+end
return Thing
diff --git a/todo.txt b/todo.txt
index 647f7ed..77ef7fe 100644
--- a/todo.txt
+++ b/todo.txt
@@ -22,6 +22,9 @@ puppeteering:
detect existing nicks in use, avoid collisions, keep this in sync
store:
+ think about how to store authors, given that
+ a) we want to be able to search by username
+ b) usernames can change over time on some platforms
nicer web ui
fts
sort by channel, etc
diff --git a/xmpp/pylon.lua b/xmpp/pylon.lua
index 0e6094c..7fd7a1a 100644
--- a/xmpp/pylon.lua
+++ b/xmpp/pylon.lua
@@ -56,10 +56,8 @@ function Xmpp.add_channel(self, channel)
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, msg_sender, source_pylon)
+function Xmpp.ensure_and_get_user(self, muc_jid, nick, 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
@@ -117,10 +115,11 @@ 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({
- source_channel = Thing(self, from_bare_jid),
+ self.wilson:deliver(Message {
+ pylon = self,
+ channel = Thing(self, from_bare_jid),
+ author = Thing(self, x.xarg.from, from_nick),
body = body,
- sender = from_nick,
})
end
end
@@ -131,9 +130,9 @@ 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.id, message.sender, message.source_channel.pylon)
+ self.log:proto('>',dest_channel,message.author,message.body)
+ local user, nick, user_jid, nick_jid = self:ensure_and_get_user(
+ dest_channel.id, message.author:name_with_shortname(), message.pylon)
self.sock:write(xmlify(
X.message{to=dest_channel.id, type='groupchat', from=user_jid,
X.body{message.body}}))