Software /
code /
prosody-modules
Changeset
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 | 4689:ecfffbbcbf42 |
children | 4691:1f1dbf652b37 |
files | mod_muc_require_tos/README.markdown mod_muc_require_tos/mod_muc_require_tos.lua |
diffstat | 2 files changed, 78 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_muc_require_tos/README.markdown Thu Sep 16 20:41:14 2021 +0200 @@ -0,0 +1,31 @@ +--- +labels: +- 'Stage-Alpha' +summary: Require visitors to accept something before being allowed in a room +... + +# Introduction + +This module sends a message to visitors of a room, prompting them to accept or reject it. + +They get kicked if they reject it, and become members if they accept it. + +# Setup + +```lua +Component "rooms.example.org" "muc" + modules_enabled = { + "muc_require_tos"; + } + tos_welcome_message = "Please read and accept the TOS of this service: https://lurk.org/TOS.txt" + tos_yes_message = "Thanks, and welcome here!" + tos_no_message = "Too bad." +``` + +Compatibility +============= + + ----- ----- + trunk Works + ----- ----- +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_muc_require_tos/mod_muc_require_tos.lua Thu Sep 16 20:41:14 2021 +0200 @@ -0,0 +1,47 @@ +local jid = require "util.jid"; +local st = require "util.stanza"; + +local quick_response_ns = "urn:xmpp:tmp:quick-response"; +local welcome_message = module:get_option_string("tos_welcome_message"); +local yes_message = module:get_option_string("tos_yes_message"); +local no_message = module:get_option_string("tos_no_message"); + +module:hook("muc-occupant-joined", function(event) + local origin = event.origin; + local room = event.room; + local occupant = event.occupant; + local nick = occupant.nick; + module:log("debug", "%s joined %s (%s)", nick, room, origin); + if occupant.role == "visitor" then + local message = st.message({ + type = "groupchat", + to = occupant.nick, + from = room.jid, + id = "foo", + ["xml:lang"] = "en", + }, welcome_message) + :tag("response", { xmlns = quick_response_ns, value = "yes", label = "I accept." }):up() + :tag("response", { xmlns = quick_response_ns, value = "no", label = "I decline." }):up(); + origin.send(message); + end +end); + +module:hook("muc-occupant-groupchat", function(event) + local occupant = event.occupant; + if occupant.role ~= "visitor" then + return; + end + local origin = event.origin; + local room = event.room; + local stanza = event.stanza; + -- Namespace must be nil instead of "jabber:client" here. + local body = stanza:get_child_text("body", nil); + module:log("debug", "%s replied %s", occupant.nick, body); + if body == "yes" then + room:set_affiliation(true, occupant.bare_jid, "member", "Agreed to the TOS."); + origin.send(st.reply(stanza):body(yes_message, { ["xml:lang"] = "en" })); + elseif body == "no" then + origin.send(st.reply(stanza):body(no_message, { ["xml:lang"] = "en" })); + room:set_role(true, occupant.nick, "none", "Declined the TOS."); + end +end, 51); -- Priority must be > 50, <forbidden/> is sent at this priority.