Mercurial > prosody-modules
annotate mod_muc_auto_hats/mod_muc_auto_hats.lua @ 6562:5da6fb562df9 default tip
mod_unified_push: Fix push error handling (fixes #2000)
Use the error object that send_iq() passes
as an argument to it's reject callback instead of attempting
and failing to do the parsing in the callback itself.
| author | kmq |
|---|---|
| date | Mon, 06 Jul 2026 14:23:57 +0200 |
| parents | f7158c0e2202 |
| children |
| rev | line source |
|---|---|
|
6500
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local jid = require "prosody.util.jid"; |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local sha256 = require "prosody.util.hashes".sha256; |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local st = require "prosody.util.stanza"; |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local host_hats = module:get_option("muc_auto_hats_by_host"); |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 for hat_host, hat_config in pairs(host_hats) do |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 if not hat_config.uri then |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 hat_config.uri = ("xmpp:%s/hats/%s"):format(module.host, sha256(hat_host..","..module.host, true)); |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 end |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 if not hat_config.title then |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 hat_config.title = hat_host; |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 end |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 module:hook("muc-build-occupant-presence", function (event) |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local pres = event.stanza; |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local bare_jid = event.occupant and event.occupant.bare_jid or event.bare_jid; |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local occ_host = jid.host(bare_jid); |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local host_hat = host_hats[occ_host]; |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 if not host_hat then |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 return; |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 local hats_el = pres:get_child("hats", "urn:xmpp:hats:0"); |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 if not hats_el then |
|
6501
f7158c0e2202
mod_muc_auto_hats: Fix stanza construction
Matthew Wild <mwild1@gmail.com>
parents:
6500
diff
changeset
|
30 hats_el = st.stanza("hats", { xmlns = "urn:xmpp:hats:0" }); |
|
6500
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 pres:add_direct_child(hats_el); |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 hats_el:text_tag("hat", nil, { uri = host_hat.uri, title = host_hat.title }); |
|
36b9d79e04b7
mod_muc_auto_hats: New module to dynamically assign hats based on config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 end); |
