Software /
code /
verse
Annotate
plugins/groupchat.lua @ 186:bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 19 Jan 2011 20:41:53 +0100 |
parent | 185:4f897d0e01c4 |
child | 187:7ad218bd5fde |
rev | line source |
---|---|
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local events = require "events"; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local room_mt = {}; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 room_mt.__index = room_mt; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local xmlns_delay = "urn:xmpp:delay"; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local xmlns_muc = "http://jabber.org/protocol/muc"; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 function verse.plugins.groupchat(stream) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 stream:add_plugin("presence") |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 stream.rooms = {}; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 stream:hook("stanza", function (stanza) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local room_jid = jid.bare(stanza.attr.from); |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
16 local room = stream.rooms[room_jid] or stream.rooms[stanza.attr.to.." "..room_jid] or nil |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
17 if room and room.opts.source and stanza.attr.to ~= room.opts.source then return end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 if room then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local nick = select(3, jid.split(stanza.attr.from)); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local body = stanza:get_child("body"); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 local delay = stanza:get_child("delay", xmlns_delay); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 local event = { |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 room_jid = room_jid; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 room = room; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 sender = room.occupants[nick]; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 nick = nick; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 body = (body and body:get_text()) or nil; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 stanza = stanza; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 delay = (delay and delay.attr.stamp); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 }; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 local ret = room:event(stanza.name, event); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 return ret or (stanza.name == "message") or nil; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end, 500); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
36 function stream:join_room(jid, nick, opts) |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 if not nick then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 return false, "no nickname supplied" |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 local room = setmetatable({ |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 stream = stream, jid = jid, nick = nick, |
185
4f897d0e01c4
plugins.groupchat: Trying to get subject to behave properly
Kim Alvefur <zash@zash.se>
parents:
184
diff
changeset
|
42 subject = nil, |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 occupants = {}, |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
44 opts = opts, |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 events = events.new() |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 }, room_mt); |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
47 if opts.source then |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
48 self.rooms[opts.source.." "..jid] = room; |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
49 else |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
50 self.rooms[jid] = room; |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
51 end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 local occupants = room.occupants; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 room:hook("presence", function (presence) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 local nick = presence.nick or nick; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 if not occupants[nick] and presence.stanza.attr.type ~= "unavailable" then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 occupants[nick] = { |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 nick = nick; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 jid = presence.stanza.attr.from; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 presence = presence.stanza; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 }; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 local x = presence.stanza:get_child("x", xmlns_muc .. "#user"); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 if x then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 local x_item = x:get_child("item"); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 if x_item and x_item.attr then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 occupants[nick].real_jid = x_item.attr.jid; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 occupants[nick].affiliation = x_item.attr.affiliation; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 occupants[nick].role = x_item.attr.role; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 --TODO Check for status 100? |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 if nick == room.nick then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 room.stream:event("groupchat/joined", room); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 else |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 room:event("occupant-joined", occupants[nick]); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 elseif occupants[nick] and presence.stanza.attr.type == "unavailable" then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 if nick == room.nick then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 room.stream:event("groupchat/left", room); |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
79 if room.opts.source then |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
80 self.rooms[room.opts.source.." "..jid] = nil; |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
81 else |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
82 self.rooms[jid] = nil; |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
83 end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 else |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 occupants[nick].presence = presence.stanza; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 room:event("occupant-left", occupants[nick]); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 occupants[nick] = nil; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 end); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 room:hook("message", function(msg) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 local subject = msg.stanza:get_child("subject"); |
185
4f897d0e01c4
plugins.groupchat: Trying to get subject to behave properly
Kim Alvefur <zash@zash.se>
parents:
184
diff
changeset
|
93 subject = subject and subject:get_text(); |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 if subject then |
185
4f897d0e01c4
plugins.groupchat: Trying to get subject to behave properly
Kim Alvefur <zash@zash.se>
parents:
184
diff
changeset
|
95 room.subject = #subject > 0 and subject or nil; |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 end); |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
98 local join_st = st.presence():tag("x",{xmlns = xmlns_muc}):reset(); |
184
8173e57522bf
plugins.groupchat: Fix a missing `st.` and send join stanza regardless of return value from pre-join event.
Kim Alvefur <zash@zash.se>
parents:
182
diff
changeset
|
99 self:event("pre-groupchat/joining", join_st); |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
100 room:send(join_st) |
184
8173e57522bf
plugins.groupchat: Fix a missing `st.` and send join stanza regardless of return value from pre-join event.
Kim Alvefur <zash@zash.se>
parents:
182
diff
changeset
|
101 self:event("groupchat/joining", room); |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 return room; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 stream:hook("presence-out", function(presence) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 if not presence.attr.to then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 for _, room in pairs(stream.rooms) do |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 room:send(presence); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 presence.attr.to = nil; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 end); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 function room_mt:send(stanza) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 if stanza.name == "message" and not stanza.attr.type then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 stanza.attr.type = "groupchat"; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 end |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
119 if stanza.name == "presence" or not stanza.attr.to then |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
120 stanza.attr.to = self.jid .."/"..self.nick; |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
121 end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 if stanza.attr.type == "groupchat" or not stanza.attr.to then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 stanza.attr.to = self.jid; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 end |
186
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
125 if self.opts.source then |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
126 stanza.attr.from = self.opts.source |
bb34b8bc00ae
plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents:
185
diff
changeset
|
127 end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 self.stream:send(stanza); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
129 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
130 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 function room_mt:send_message(text) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 self:send(st.message():tag("body"):text(text)); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 function room_mt:set_subject(text) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 self:send(st.message():tag("subject"):text(text)); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 function room_mt:leave(message) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 self.stream:event("groupchat/leaving", room); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 self:send(st.presence({type="unavailable"})); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 function room_mt:admin_set(nick, what, value, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 self:send(st.iq({type="set"}) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 :query(xmlns_muc .. "#admin") |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 :tag("item", {nick = nick, [what] = value}) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 :tag("reason"):text(reason or "")); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 function room_mt:set_role(nick, role, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 self:admin_set(nick, "role", role, reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 function room_mt:set_affiliation(nick, affiliation, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 self:admin_set(nick, "affiliation", affiliation, reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
157 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
158 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
159 function room_mt:kick(nick, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 self:set_role(nick, "none", reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
161 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
162 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
163 function room_mt:ban(nick, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
164 self:set_affiliation(nick, "outcast", reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
165 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
166 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
167 function room_mt:event(name, arg) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
168 self.stream:debug("Firing room event: %s", name); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
169 return self.events.fire_event(name, arg); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
170 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
171 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
172 function room_mt:hook(name, callback, priority) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
173 return self.events.add_handler(name, callback, priority); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
174 end |