Software /
code /
prosody-modules
Annotate
mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua @ 4916:3dc8e329d233
mod_rest: Move most of XEP-0432 handling into JSON mapping schema
The pre- and post-processing is still needed to encode/decode the JSON
since util.datamapper can't (currently) do this.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 07 Apr 2022 15:39:57 +0200 |
parent | 4772:85d4ab318d66 |
child | 4950:c83bc703825d |
rev | line source |
---|---|
4772
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local jid = require "util.jid"; |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local set = require "util.set"; |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local active_affiliations = set.new({ "member", "admin", "owner" }); |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 module:hook("muc-occupant-joined", function (event) |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local room, occupant = event.room, event.occupant; |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local user_jid = occupant.bare_jid; |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local user_affiliation = room:get_affiliation(user_jid); |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 if not active_affiliations:contains(user_affiliation) then |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 return; |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 end |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local aff_data = event.room:get_affiliation_data(user_jid); |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 if not aff_data then |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local reserved_nick = jid.resource(occupant.nick); |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 module:log("debug", "Automatically reserving nickname '%s' for <%s>", reserved_nick, user_jid); |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 room:set_affiliation_data(user_jid, "reserved_nickname", reserved_nick); |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end |
85d4ab318d66
mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 end); |