Annotate

plugins/groupchat.lua @ 185:4f897d0e01c4

plugins.groupchat: Trying to get subject to behave properly
author Kim Alvefur <zash@zash.se>
date Wed, 19 Jan 2011 20:37:12 +0100
parent 184:8173e57522bf
child 186:bb34b8bc00ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 local room = stream.rooms[room_jid]
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 if room then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local nick = select(3, jid.split(stanza.attr.from));
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local body = stanza:get_child("body");
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local delay = stanza:get_child("delay", xmlns_delay);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 local event = {
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 room_jid = room_jid;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 room = room;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 sender = room.occupants[nick];
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 nick = nick;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 body = (body and body:get_text()) or nil;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 stanza = stanza;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 delay = (delay and delay.attr.stamp);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 };
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 local ret = room:event(stanza.name, event);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 return ret or (stanza.name == "message") or nil;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 end, 500);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 function stream:join_room(jid, nick)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 if not nick then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 return false, "no nickname supplied"
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 local room = setmetatable({
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 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
41 subject = nil,
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 occupants = {},
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 events = events.new()
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 }, room_mt);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 self.rooms[jid] = room;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 local occupants = room.occupants;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 room:hook("presence", function (presence)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 local nick = presence.nick or nick;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 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
50 occupants[nick] = {
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 nick = nick;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 jid = presence.stanza.attr.from;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 presence = presence.stanza;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 };
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 local x = presence.stanza:get_child("x", xmlns_muc .. "#user");
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 if x then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 local x_item = x:get_child("item");
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 if x_item and x_item.attr then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 occupants[nick].real_jid = x_item.attr.jid;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 occupants[nick].affiliation = x_item.attr.affiliation;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 occupants[nick].role = x_item.attr.role;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 --TODO Check for status 100?
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 if nick == room.nick then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 room.stream:event("groupchat/joined", room);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 else
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 room:event("occupant-joined", occupants[nick]);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 elseif occupants[nick] and presence.stanza.attr.type == "unavailable" then
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/left", room);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 self.rooms[room.jid] = nil;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 else
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 occupants[nick].presence = presence.stanza;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 room:event("occupant-left", occupants[nick]);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 occupants[nick] = nil;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 end
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 end);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 room:hook("message", function(msg)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 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
83 subject = subject and subject:get_text();
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 if subject then
185
4f897d0e01c4 plugins.groupchat: Trying to get subject to behave properly
Kim Alvefur <zash@zash.se>
parents: 184
diff changeset
85 room.subject = #subject > 0 and subject or nil;
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 end);
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
88 local join_st = st.presence({to = jid.."/"..nick})
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 :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
90 self:event("pre-groupchat/joining", join_st);
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
91 self:send(join_st)
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
92 self:event("groupchat/joining", room);
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 return room;
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
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 stream:hook("presence-out", function(presence)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 if not presence.attr.to then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 for _, room in pairs(stream.rooms) do
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 room:send(presence);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 presence.attr.to = nil;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 end
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 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 function room_mt:send(stanza)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 if stanza.name == "message" and not stanza.attr.type then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 stanza.attr.type = "groupchat";
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 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
111 stanza.attr.to = self.jid;
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 self.stream:send(stanza);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 function room_mt:send_message(text)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 self:send(st.message():tag("body"):text(text));
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 function room_mt:set_subject(text)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 self:send(st.message():tag("subject"):text(text));
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 function room_mt:leave(message)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 self.stream:event("groupchat/leaving", room);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 self:send(st.presence({type="unavailable"}));
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 function room_mt:admin_set(nick, what, value, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 self:send(st.iq({type="set"})
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 :query(xmlns_muc .. "#admin")
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 :tag("item", {nick = nick, [what] = value})
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 :tag("reason"):text(reason or ""));
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 function room_mt:set_role(nick, role, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 self:admin_set(nick, "role", role, reason);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 function room_mt:set_affiliation(nick, affiliation, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 self:admin_set(nick, "affiliation", affiliation, reason);
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:kick(nick, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 self:set_role(nick, "none", reason);
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:ban(nick, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 self:set_affiliation(nick, "outcast", reason);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 function room_mt:event(name, arg)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 self.stream:debug("Firing room event: %s", name);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 return self.events.fire_event(name, arg);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 function room_mt:hook(name, callback, priority)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 return self.events.add_handler(name, callback, priority);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 end