Mercurial > prosody-modules
annotate mod_support_room/mod_support_room.lua @ 5173:460f78654864
mod_muc_rtbl: also filter messages
This was a bit tricky because we don't want to run the JIDs
through SHA256 on each message. Took a while to come up with this
simple plan of just caching the SHA256 of the JIDs on the
occupants.
This will leave some dirt in the occupants after unloading the
module, but that should be ok; once they cycle the room, the
hashes will be gone.
This is direly needed, otherwise, there is a tight race between
the moderation activities and the actors joining the room.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Tue, 21 Feb 2023 21:37:27 +0100 |
parents | f72aa8840042 |
children |
rev | line source |
---|---|
3426
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local mm = require "core.modulemanager"; |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local jid_host, jid_prep = import("util.jid", "host", "prep"); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local invite_to_room = assert(jid_prep(module:get_option_string(module.name)), |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 "The option " .. module.name .. " must be set"); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local inviter = module:get_option_string(module.name .. "_inviter", module.host); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local invite_reason = module:get_option_string(module.name .. "_reason"); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 module:hook("user-registered", function (event) |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local user_jid = event.username .. "@" .. event.host; |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local muc = mm.get_module(jid_host(invite_to_room), "muc"); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 if not muc then |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 module:log("error", "There is no MUC service '%s'", jid_host(invite_to_room)); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 return; |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 end |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local room = muc.get_room_from_jid(invite_to_room); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 if room then |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 room:set_affiliation(true, user_jid, "member", invite_reason, { reserved_nickname = event.username }); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 -- Invite them to the room too |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 module:send(st.message({ from = inviter, to = user_jid }) |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 :tag("x", { xmlns = "jabber:x:conference", jid = invite_to_room, reason = invite_reason }):up()); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 else |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 module:log("error", "The room %s does not exist, can't invite newly registered user", invite_to_room); |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
f72aa8840042
mod_support_room: Module that invites newly registered users to a room
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 end); |