Software /
code /
prosody-modules
Annotate
mod_muc_intercom/mod_muc_intercom.lua @ 276:27c652363874
mod_ircd: Updated to use events instead of componentmanager.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 10 Nov 2010 21:18:21 +0500 |
parent | 253:7410d1005fea |
child | 280:6d72c5172c74 |
rev | line source |
---|---|
247
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Relay messages between rooms |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 -- By Kim Alvefur <zash@zash.se> |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local host_session = prosody.hosts[module.host]; |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local st_msg = require "util.stanza".message; |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local jid = require "util.jid"; |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 function check_message(data) |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local origin, stanza = data.origin, data.stanza; |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local muc_rooms = host_session.muc and host_session.muc.rooms; |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 if not muc_rooms then return; end |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local this_room = muc_rooms[stanza.attr.to]; |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 if not this_room then return; end -- no such room |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local from_room_jid = this_room._jid_nick[stanza.attr.from]; |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 if not from_room_jid then return; end -- no such nick |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local from_room, from_host, from_nick = jid.split(from_room_jid); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 local body = stanza:get_child("body"); |
253
7410d1005fea
mod_muc_intercom: Fix traceback on topic changes
Kim Alvefur <zash@zash.se>
parents:
247
diff
changeset
|
22 if not body then return; end -- No body, like topic changes |
247
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 body = body and body:get_text(); -- I feel like I want to do `or ""` there :/ |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local target_room, message = body:match("^@([^:]+):(.*)"); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 if not target_room or not message then return; end |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 if target_room == from_room then return; end -- don't route to itself |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 module:log("debug", "target room is %s", target_room); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 local bare_room = jid.join(target_room, from_host); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 if not muc_rooms[bare_room] then return; end -- TODO send a error |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 module:log("info", "message from %s in %s to %s", from_nick, from_room, target_room); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 local sender = jid.join(target_room, module.host, from_room .. "/" .. from_nick); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 local forward_stanza = st_msg({from = sender, to = bare_room, type = "groupchat"}, message); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 module:log("debug", "broadcasting message to target room"); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 muc_rooms[bare_room]:broadcast_message(forward_stanza); |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 end |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 |
fbddb9db1c82
adds mod_muc_intercom; forwards messages between rooms on a muc host
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 module:hook("message/bare", check_message); |