diff options
| -rw-r--r-- | channel.lua | 14 | ||||
| -rw-r--r-- | discord/pylon.lua | 6 | ||||
| -rw-r--r-- | irc/pylon.lua | 4 | ||||
| -rw-r--r-- | main.lua | 4 | ||||
| -rw-r--r-- | nanochat/pylon.lua | 6 | ||||
| -rw-r--r-- | quaddle/pylon.lua | 5 | ||||
| -rw-r--r-- | terminology.txt | 4 | ||||
| -rw-r--r-- | thing.lua | 22 | ||||
| -rw-r--r-- | xmpp/pylon.lua | 4 |
9 files changed, 41 insertions, 28 deletions
diff --git a/channel.lua b/channel.lua deleted file mode 100644 index f921e36..0000000 --- a/channel.lua +++ /dev/null @@ -1,14 +0,0 @@ -local class = require'r.class' --- channel descriptor - -local Channel = class() -function Channel.make(cls, pylon, descriptor) - return setmetatable({pylon=pylon, descriptor=descriptor}, cls) -end -function Channel.__eq(self, other) - return self.pylon == other.pylon and self.descriptor == other.descriptor -end -function Channel.__tostring(self) - return self.pylon.name .. ':' .. self.descriptor -end -return Channel diff --git a/discord/pylon.lua b/discord/pylon.lua index 64fe921..b996ee7 100644 --- a/discord/pylon.lua +++ b/discord/pylon.lua @@ -5,7 +5,7 @@ local json = require 'dkjson' local class = require 'r.class' local BasePylon = require 'pylon' -local Channel = require 'channel' +local Thing = require 'thing' local consts = require 'discord.consts' local opcodes = consts.opcodes @@ -133,9 +133,9 @@ function Discord.handle_dispatch(self, event) and d.author.id ~= self.bot_id then self.wilson:deliver({ - source_channel = Channel(self, d.channel_id), + channel = Thing(self, d.channel_id, 'channel name here'), + author = Thing(self, d.author.id, d.author.username), body = d.content, - sender = d.author.username, }) end end diff --git a/irc/pylon.lua b/irc/pylon.lua index 11c8250..bed8261 100644 --- a/irc/pylon.lua +++ b/irc/pylon.lua @@ -2,7 +2,7 @@ local cqueues = require'cqueues' local socket = require'cqueues.socket' local class = require'r.class' -local Channel = require'channel' +local Thing = require'thing' local BasePylon = require'pylon' local rirc = require'irc.rirc' @@ -35,7 +35,7 @@ function Irc.recving(self) local body = msg.args[2] local sender = msg.source self.wilson:deliver({ - source_channel = Channel(self, channel_name), + source_channel = Thing(self, channel_name), body = body, sender = sender, }) @@ -3,7 +3,7 @@ local class = require'r.class' local pprint = require'pprint' local config = require'config' -local Channel = require'channel' +local Thing = require'thing' local Log = require 'log' local Store = require 'store' @@ -38,7 +38,7 @@ function Wilson.make(cls, conf) local pylon_name, channel_descriptor = item[1], item[2] local pylon = self.pylons[pylon_name] assert(pylon,"no such pylon named "..pylon_name) - table.insert(bus, Channel(pylon, channel_descriptor)) + table.insert(bus, Thing(pylon, channel_descriptor)) end self.log("constructed bus ",name,'with '..#bus_conf..' channels') self.busses[name] = bus diff --git a/nanochat/pylon.lua b/nanochat/pylon.lua index dfd8532..aa3aaa6 100644 --- a/nanochat/pylon.lua +++ b/nanochat/pylon.lua @@ -3,7 +3,7 @@ local socket = require 'cqueues.socket' local class = require 'r.class' local BasePylon = require 'pylon' -local Channel = require 'channel' +local Thing = require 'thing' local Nanochat = class.extend(BasePylon) @@ -30,9 +30,9 @@ function Nanochat:recving() if chan then local sender, body = msg:match("^([^:]+): (.+)$", msgi) if sender then - deliverables[i] = { source_channel=Channel(self, chan), sender=sender, body=body } + deliverables[i] = { source_channel=Thing(self, chan), sender=sender, body=body } else - deliverables[i] = { source_channel=Channel(self, chan), sender="", body=msg:sub(msgi,-1) } + deliverables[i] = { source_channel=Thing(self, chan), sender="", body=msg:sub(msgi,-1) } end else -- luacheck: ignore 542 -- ignore messages without a channel, they stay nanochat-local diff --git a/quaddle/pylon.lua b/quaddle/pylon.lua index 2213a76..e85b699 100644 --- a/quaddle/pylon.lua +++ b/quaddle/pylon.lua @@ -4,7 +4,8 @@ local json = require 'dkjson' local class = require 'r.class' local BasePylon = require 'pylon' -local Channel = require 'channel' +local Message = require 'message' +local Thing = require 'thing' local Quaddle = class.extend(BasePylon) function Quaddle.init(self) @@ -82,7 +83,7 @@ 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({ - source_channel = Channel(self, msg.channel), + source_channel = Thing(self, msg.channel), body = msg.content, sender = msg.author.name, }) diff --git a/terminology.txt b/terminology.txt index 23298f8..d8d029a 100644 --- a/terminology.txt +++ b/terminology.txt @@ -14,6 +14,10 @@ Channel: a particular chatroom on a particular service in the code, a Channel is identified by a combination of a Pylon and a string 'channel descriptor', whose format depends on the Pylon type for instance xmpp channel descriptors are jids, discord uses numeric ids + +Thing: used in the code for such a tuple of (pylon, pylon-specific-descriptor) + actually it also has a display name, which defaults to the descriptor + used to represent Channels, Authors, ... Bus: a family of connected channels that messages will be bridged between diff --git a/thing.lua b/thing.lua new file mode 100644 index 0000000..33a4bb1 --- /dev/null +++ b/thing.lua @@ -0,0 +1,22 @@ +local class = require'r.class' +-- author or channel or whatever +-- tuple of (pylon, pylon-specific-descriptor, optional displayname) + +local Thing = class() +function Thing.make(cls, pylon, descriptor, displayname) + displayname = displayname or descriptor + return setmetatable({ + pylon=pylon, + descriptor=descriptor, + displayname=displayname, + }, cls) +end +function Thing.__eq(self, other) + return self.pylon == other.pylon and self.descriptor == other.descriptor +end +function Thing.__tostring(self) + return self.pylon.name + .. ':' .. self.descriptor + .. (self.displayname == self.descriptor and '('..self.displayname..')' or '') +end +return Thing diff --git a/xmpp/pylon.lua b/xmpp/pylon.lua index 90a155a..c9f18f5 100644 --- a/xmpp/pylon.lua +++ b/xmpp/pylon.lua @@ -1,7 +1,7 @@ local socket = require'cqueues.socket' local class = require'r.class' -local Channel = require'channel' +local Thing = require'thing' local BasePylon = require 'pylon' local xml = require'xmpp.xml' local X,xmlify = xml.X, xml.xmlify @@ -118,7 +118,7 @@ function Xmpp.recving(self) then self.log:proto('<',from_bare_jid,from_nick,body) self.wilson:deliver({ - source_channel = Channel(self, from_bare_jid), + source_channel = Thing(self, from_bare_jid), body = body, sender = from_nick, }) |
