Software /
code /
prosody-modules
Annotate
mod_muc_gc10/mod_muc_gc10.lua @ 4971:bc78424968b2
luacheck: Update with changes from Prosody 0.12
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 05 Jul 2022 16:02:22 +0200 |
parent | 3548:8a15a9b13881 |
rev | line source |
---|---|
2940
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local jid_bare = require "util.jid".bare; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
3548
8a15a9b13881
mod_muc_gc10: Abort on Prosody 0.11
Kim Alvefur <zash@zash.se>
parents:
2944
diff
changeset
|
4 local rooms = assert(module:depends"muc".rooms, "This module is not needed with Prosody >=0.11"); |
2940
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
2944
37ec4c2f319a
mod_muc_gc10: Catch joins correctly (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
2940
diff
changeset
|
6 module:hook("presence/full", function (event) |
2940
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local stanza, origin = event.stanza, event.origin; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 if stanza.attr.type ~= nil then return end |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc"); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local room_jid = jid_bare(stanza.attr.to); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local room = rooms[room_jid]; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 if not room then |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 if muc_x then |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 -- Normal MUC creation |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 else |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 module:log("info", "GC 1.0 room creation from %s", stanza.attr.from); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version")); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 return; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local current_nick = room._jid_nick[stanza.attr.from]; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 if current_nick then |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 -- present |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 if muc_x then |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 module:log("info", "MUC desync with %s", stanza.attr.from); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version")); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 else |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 -- normal presence update |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 end |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 else |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 -- joining |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 if muc_x then |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 -- normal join |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 else |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 module:log("info", "GC 1.0 join from %s", stanza.attr.from); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 module:send(st.iq({type="get",id=module.name,from=module.host,to=stanza.attr.from}):query("jabber:iq:version")); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 end |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 end |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 end); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 module:hook("iq-result/host/"..module.name, function (event) |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 local stanza, origin = event.stanza, event.origin; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 local version = stanza:get_child("query", "jabber:iq:version"); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 if not version then |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 module:log("info", "%s replied with an invalid version reply: %s", stanza.attr.from, tostring(stanza)); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 return true; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 end |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 module:log("info", "%s is running: %s %s", stanza.attr.from, version:get_child_text("name"), version:get_child_text("version")); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 end); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 module:hook("iq-error/host/"..module.name, function (event) |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 local stanza, origin = event.stanza, event.origin; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 module:log("info", "%s replied with an error: %s %s", stanza.attr.from, stanza:get_error()); |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 return true; |
0167a102ed35
mod_muc_gc10: Gather statistics on use of the Groupchat 1.0 protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 end); |