summaryrefslogtreecommitdiff
path: root/xmpp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp.lua')
-rw-r--r--xmpp.lua23
1 files changed, 14 insertions, 9 deletions
diff --git a/xmpp.lua b/xmpp.lua
index 0b7a33d..5c3371b 100644
--- a/xmpp.lua
+++ b/xmpp.lua
@@ -1,4 +1,3 @@
-
local cqueues = require'cqueues'
local cqaux = require'cqueues.auxlib'
local socket = require'cqueues.socket'
@@ -9,6 +8,7 @@ local pprint=require'pprint'
local Queue = require'queue'
local base64 = require'base64'
local sha1 = require'sha1'
+local Channel = require'channel'
local Xmpp = {}
@@ -22,14 +22,16 @@ function Xmpp.make(wilson, conf)
name = conf.name,
wilson = wilson,
inbox = Queue.make(),
+ cq = wilson.cq, -- todo
+ nicks_inuse = {}, -- todo
}
local function conf_var(name)
assert(conf[name] ~= nil, 'missing conf field '..name)
self[name] = conf[name]
end
- conf_var 'jid'
+ -- conf_var 'jid'
conf_var 'server'
- conf_var 'resource'
+ -- conf_var 'resource'
conf_var 'component'
conf_var 'component_secret'
@@ -121,10 +123,11 @@ function Xmpp.recving(self)
if x.label == 'message' then
local fr = x.xarg.from
local t = x.xarg.to
- if body and fr:match"/" and t == 'wilson@'..self.component then
+ local from_nick = fr:match("/(.*)")
+ if not self.nicks_inuse[from_nick] and body and fr:match"/" and t == 'wilson@'..self.component then
self.wilson:deliver(Channel(self, THE_MUC), {
body = body,
- sender = '[x]'..x.xarg.from:match("/(.*)")
+ sender = '[x]'..from_nick
})
end
end
@@ -133,14 +136,13 @@ end
function Xmpp.sending(self)
local users_inuse = {}
- local nicks_inuse = {}
local function ensure_joined(muc,user,nick)
- if nicks_inuse[nick] then return end
+ if self.nicks_inuse[nick] then return end
user = user:gsub("[^a-zA-Z0-9%.]","."):match("^%.*(.-)%.*$")
while users_inuse[user] do user = user..'-' end
local jid = user..'@'..self.component
local mucjid = muc..'/'..nick
- nicks_inuse[nick] = true
+ self.nicks_inuse[nick] = true
users_inuse[user] = true
self.sock:write(xmlify(
@@ -156,10 +158,13 @@ function Xmpp.sending(self)
local jid = user..'@'..self.component
self.sock:write(xmlify(
X.message{to=THE_MUC, type='groupchat', from=jid,
- X.body{msg.body}}))
+ X.body{message.body}}))
end
end
+function Xmpp.post(self, dest_channel, message)
+ self.inbox:enqueue(dest_channel, message)
+end
return Xmpp