Mercurial > prosody-modules
annotate mod_discoitems/mod_discoitems.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 | ae91c98b7e4c |
children |
rev | line source |
---|---|
78
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- mod_discoitems.lua |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- In the config, you can add: |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 -- |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- disco_items = { |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- {"proxy.eu.jabber.org", "Jabber.org SOCKS5 service"}; |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 -- {"conference.jabber.org", "The Jabber.org MUC"}; |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 -- }; |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 -- |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local st = require "util.stanza"; |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 local result_query = st.stanza("query", {xmlns="http://jabber.org/protocol/disco#items"}); |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 for _, item in ipairs(module:get_option("disco_items") or {}) do |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 result_query:tag("item", {jid=item[1], name=item[2]}):up(); |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 end |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 module:hook('iq/host/http://jabber.org/protocol/disco#items:query', function(event) |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 local stanza = event.stanza; |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 local query = stanza.tags[1]; |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 if stanza.attr.type == 'get' and not query.attr.node then |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 event.origin.send(st.reply(stanza):add_child(result_query)); |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 return true; |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 end |
ae91c98b7e4c
mod_discoitems: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 end, 100); |