Mercurial > prosody-modules
annotate mod_muc_require_tos/mod_muc_require_tos.lua @ 4690:82dabfffaddf
mod_muc_require_tos: Add this new module
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 16 Sep 2021 20:41:14 +0200 |
parents | |
children | 1f1dbf652b37 |
rev | line source |
---|---|
4690
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 local jid = require "util.jid"; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 local quick_response_ns = "urn:xmpp:tmp:quick-response"; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 local welcome_message = module:get_option_string("tos_welcome_message"); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 local yes_message = module:get_option_string("tos_yes_message"); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 local no_message = module:get_option_string("tos_no_message"); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 module:hook("muc-occupant-joined", function(event) |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 local origin = event.origin; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 local room = event.room; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 local occupant = event.occupant; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 local nick = occupant.nick; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 module:log("debug", "%s joined %s (%s)", nick, room, origin); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 if occupant.role == "visitor" then |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 local message = st.message({ |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 type = "groupchat", |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 to = occupant.nick, |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 from = room.jid, |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 id = "foo", |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 ["xml:lang"] = "en", |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 }, welcome_message) |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 :tag("response", { xmlns = quick_response_ns, value = "yes", label = "I accept." }):up() |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 :tag("response", { xmlns = quick_response_ns, value = "no", label = "I decline." }):up(); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 origin.send(message); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 end |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 end); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 module:hook("muc-occupant-groupchat", function(event) |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 local occupant = event.occupant; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 if occupant.role ~= "visitor" then |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 return; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 end |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 local origin = event.origin; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 local room = event.room; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 local stanza = event.stanza; |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 -- Namespace must be nil instead of "jabber:client" here. |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 local body = stanza:get_child_text("body", nil); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 module:log("debug", "%s replied %s", occupant.nick, body); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 if body == "yes" then |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 room:set_affiliation(true, occupant.bare_jid, "member", "Agreed to the TOS."); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 origin.send(st.reply(stanza):body(yes_message, { ["xml:lang"] = "en" })); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 elseif body == "no" then |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 origin.send(st.reply(stanza):body(no_message, { ["xml:lang"] = "en" })); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 room:set_role(true, occupant.nick, "none", "Declined the TOS."); |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 end |
82dabfffaddf
mod_muc_require_tos: Add this new module
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 end, 51); -- Priority must be > 50, <forbidden/> is sent at this priority. |