Mercurial > prosody-modules
annotate mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua @ 4791:b86282953663
mod_s2s_status: Module to track status of s2s connections by domain
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 26 Nov 2021 10:10:02 +0000 |
parents | 85d4ab318d66 |
children | 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); |