Software /
code /
verse
Annotate
plugins/groupchat.lua @ 207:78f59d7b1ef7
plugins.groupchat: Bump topic change handling up a bit
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 20 Mar 2011 19:00:26 +0100 |
parent | 197:7e98cf2c1d8d |
child | 215:f86e0b0a0be3 |
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 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local room_mt = {}; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 room_mt.__index = room_mt; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local xmlns_delay = "urn:xmpp:delay"; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local xmlns_muc = "http://jabber.org/protocol/muc"; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 function verse.plugins.groupchat(stream) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 stream:add_plugin("presence") |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 stream.rooms = {}; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 stream:hook("stanza", function (stanza) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local room_jid = jid.bare(stanza.attr.from); |
187
7ad218bd5fde
plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents:
186
diff
changeset
|
15 if not room_jid then return end |
7ad218bd5fde
plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents:
186
diff
changeset
|
16 local room = stream.rooms[room_jid] |
7ad218bd5fde
plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents:
186
diff
changeset
|
17 if not room and stanza.attr.to and room_jid then |
7ad218bd5fde
plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents:
186
diff
changeset
|
18 room = stream.rooms[stanza.attr.to.." "..room_jid] |
7ad218bd5fde
plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents:
186
diff
changeset
|
19 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
|
20 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
|
21 if room then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 local nick = select(3, jid.split(stanza.attr.from)); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local body = stanza:get_child("body"); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local delay = stanza:get_child("delay", xmlns_delay); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 local event = { |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 room_jid = room_jid; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 room = room; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 sender = room.occupants[nick]; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 nick = nick; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 body = (body and body:get_text()) or nil; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 stanza = stanza; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 delay = (delay and delay.attr.stamp); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 }; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 local ret = room:event(stanza.name, event); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 return ret or (stanza.name == "message") or nil; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 end, 500); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 |
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
|
39 function stream:join_room(jid, nick, opts) |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 if not nick then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 return false, "no nickname supplied" |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 end |
187
7ad218bd5fde
plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents:
186
diff
changeset
|
43 opts = opts or {}; |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 local room = setmetatable({ |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 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
|
46 subject = nil, |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 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
|
48 opts = opts, |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 events = events.new() |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 }, 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 local occupants = room.occupants; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 room:hook("presence", function (presence) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 local nick = presence.nick or nick; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 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
|
60 occupants[nick] = { |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 nick = nick; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 jid = presence.stanza.attr.from; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 presence = presence.stanza; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 }; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 local x = presence.stanza:get_child("x", xmlns_muc .. "#user"); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 if x then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 local x_item = x:get_child("item"); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 if x_item and x_item.attr then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 occupants[nick].real_jid = x_item.attr.jid; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 occupants[nick].affiliation = x_item.attr.affiliation; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 occupants[nick].role = x_item.attr.role; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 --TODO Check for status 100? |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 if nick == room.nick then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 room.stream:event("groupchat/joined", room); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 else |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 room:event("occupant-joined", occupants[nick]); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 elseif occupants[nick] and presence.stanza.attr.type == "unavailable" then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 if nick == room.nick then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 else |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 occupants[nick].presence = presence.stanza; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 room:event("occupant-left", occupants[nick]); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 occupants[nick] = nil; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 end); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 room:hook("message", function(msg) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 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
|
97 subject = subject and subject:get_text(); |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 if subject then |
185
4f897d0e01c4
plugins.groupchat: Trying to get subject to behave properly
Kim Alvefur <zash@zash.se>
parents:
184
diff
changeset
|
99 room.subject = #subject > 0 and subject or nil; |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 end |
207
78f59d7b1ef7
plugins.groupchat: Bump topic change handling up a bit
Kim Alvefur <zash@zash.se>
parents:
197
diff
changeset
|
101 end, 2000); |
197
7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents:
189
diff
changeset
|
102 local join_st = verse.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
|
103 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
|
104 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
|
105 self:event("groupchat/joining", room); |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 return room; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 stream:hook("presence-out", function(presence) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 if not presence.attr.to then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 for _, room in pairs(stream.rooms) do |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 room:send(presence); |
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 presence.attr.to = nil; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 end); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 function room_mt:send(stanza) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 if stanza.name == "message" and not stanza.attr.type then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 stanza.attr.type = "groupchat"; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 end |
187
7ad218bd5fde
plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents:
186
diff
changeset
|
123 if stanza.name == "presence" then |
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
|
124 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
|
125 end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 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
|
127 stanza.attr.to = self.jid; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 end |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 self.stream:send(stanza); |
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:send_message(text) |
197
7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents:
189
diff
changeset
|
136 self:send(verse.message():tag("body"):text(text)); |
182
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:set_subject(text) |
197
7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents:
189
diff
changeset
|
140 self:send(verse.message():tag("subject"):text(text)); |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 function room_mt:leave(message) |
189
033f1bd7420d
plugins.groupchat: Fix self reference when leaving rooms
Kim Alvefur <zash@zash.se>
parents:
187
diff
changeset
|
144 self.stream:event("groupchat/leaving", self); |
197
7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents:
189
diff
changeset
|
145 self:send(verse.presence({type="unavailable"})); |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 function room_mt:admin_set(nick, what, value, reason) |
197
7e98cf2c1d8d
plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents:
189
diff
changeset
|
149 self:send(verse.iq({type="set"}) |
182
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 :query(xmlns_muc .. "#admin") |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 :tag("item", {nick = nick, [what] = value}) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 :tag("reason"):text(reason or "")); |
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_role(nick, role, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 self:admin_set(nick, "role", role, 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:set_affiliation(nick, affiliation, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 self:admin_set(nick, "affiliation", affiliation, 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:kick(nick, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
164 self:set_role(nick, "none", 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:ban(nick, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
168 self:set_affiliation(nick, "outcast", reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
169 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
170 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
171 function room_mt:event(name, arg) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
172 self.stream:debug("Firing room event: %s", name); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
173 return self.events.fire_event(name, arg); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
174 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
175 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
176 function room_mt:hook(name, callback, priority) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
177 return self.events.add_handler(name, callback, priority); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
178 end |