Mercurial > prosody-modules
changeset 6498:4226e6aadbd8
mod_muc_auto_role: Add account age threshold
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 25 Mar 2026 10:45:20 +0000 |
| parents | 3b0cfef7fabe |
| children | 1213145e27fc |
| files | mod_muc_auto_role/mod_muc_auto_role.lua |
| diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_muc_auto_role/mod_muc_auto_role.lua Wed Mar 25 10:23:52 2026 +0000 +++ b/mod_muc_auto_role/mod_muc_auto_role.lua Wed Mar 25 10:45:20 2026 +0000 @@ -1,9 +1,11 @@ local jid = require "prosody.util.jid"; +local datetime = require "prosody.util.datetime"; local xmlns_aff = "urn:xmpp:raa:0"; local raa_servers = module:get_option_set("muc_auto_role_trusted_servers", {}); local trust_threshold = module:get_option_integer("muc_auto_role_trust_threshold", 51, 0, 100); +local age_threshold = module:get_option_period("muc_auto_role_age_threshold", "1d"); local untrusted_servers = module:get_option_set("muc_auto_role_untrusted_servers", {}); @@ -41,15 +43,17 @@ local aff = raa.attr.affiliation; local trust = tonumber(raa.attr.trust) or 50; + local since = raa.attr.since and datetime.parse(raa.attr.since); + local age = since and (os.time() - since); - if aff == "member" or aff == "admin" or trust >= trust_threshold then + if (aff == "member" or aff == "admin") or (trust >= trust_threshold and (not age or age >= age_threshold)) then event.occupant.role = "participant"; else event.occupant.role = "visitor"; end - module:log("debug", "Assigning <%s> role '%s' due to affiliation %s and trust score %d of <%s>", - event.occupant.nick, event.occupant.role, aff, trust, stanza.attr.from + module:log("debug", "Assigning <%s> role '%s' due to affiliation %s, trust score %d, age %d of <%s>", + event.occupant.nick, event.occupant.role, aff, trust, age or -1, stanza.attr.from ); end);
