Software /
code /
verse
Annotate
plugins/groupchat.lua @ 182:51c0baa2bd19
plugins.groupchat: Adapt from Riddim
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 11 Jan 2011 23:14:30 +0100 |
child | 184:8173e57522bf |
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, |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 subject = "", |
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"); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 if subject then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 room.subject = subject and subject:get_text() or ""; |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 end |
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 local join_st = presence({to = jid.."/"..nick}) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 :tag("x",{xmlns = xmlns_muc}):reset(); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 -- Is this a good API for adding stuff etc? |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 local ok, err = self:event("pre-groupchat/joining", join_st); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 if ok then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 self:send(join_st) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 self:event("groupchat/joining", 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 return room; |
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 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 stream:hook("presence-out", function(presence) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 if not presence.attr.to then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 for _, room in pairs(stream.rooms) do |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 room:send(presence); |
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 presence.attr.to = nil; |
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 end); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 function room_mt:send(stanza) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 if stanza.name == "message" and not stanza.attr.type then |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 stanza.attr.type = "groupchat"; |
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 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
|
113 stanza.attr.to = self.jid; |
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 self.stream:send(stanza); |
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 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 function room_mt:send_message(text) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 self:send(st.message():tag("body"):text(text)); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 function room_mt:set_subject(text) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 self:send(st.message():tag("subject"):text(text)); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 function room_mt:leave(message) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 self.stream:event("groupchat/leaving", room); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 self:send(st.presence({type="unavailable"})); |
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:admin_set(nick, what, value, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 self:send(st.iq({type="set"}) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 :query(xmlns_muc .. "#admin") |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 :tag("item", {nick = nick, [what] = value}) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 :tag("reason"):text(reason or "")); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 function room_mt:set_role(nick, role, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 self:admin_set(nick, "role", role, reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 function room_mt:set_affiliation(nick, affiliation, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 self:admin_set(nick, "affiliation", affiliation, reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 function room_mt:kick(nick, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 self:set_role(nick, "none", reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 function room_mt:ban(nick, reason) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 self:set_affiliation(nick, "outcast", reason); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 end |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 function room_mt:event(name, arg) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 self.stream:debug("Firing room event: %s", name); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 return self.events.fire_event(name, arg); |
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:hook(name, callback, priority) |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 return self.events.add_handler(name, callback, priority); |
51c0baa2bd19
plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
161 end |