Mercurial > prosody-modules
annotate mod_stats39/mod_stats39.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 | bac3dae031ee |
children |
rev | line source |
---|---|
3839
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local statsman = require "core.statsmanager"; |
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
3846
3941768916f1
mod_stats39: Format numbers with a bit more precision
Kim Alvefur <zash@zash.se>
parents:
3840
diff
changeset
|
3 local s_format = string.format; |
3839
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
4595
bac3dae031ee
Add note of incompatibility with trunk since 5f15ab7c6ae5
Kim Alvefur <zash@zash.se>
parents:
3847
diff
changeset
|
5 assert(statsman.get_stats, "not compatible with trunk based on openmetrics"); |
bac3dae031ee
Add note of incompatibility with trunk since 5f15ab7c6ae5
Kim Alvefur <zash@zash.se>
parents:
3847
diff
changeset
|
6 |
3847
ffc64d285a96
mod_stats39: Advertise namespace as feature (not part of the XEP?)
Kim Alvefur <zash@zash.se>
parents:
3846
diff
changeset
|
7 module:add_feature("http://jabber.org/protocol/stats"); |
ffc64d285a96
mod_stats39: Advertise namespace as feature (not part of the XEP?)
Kim Alvefur <zash@zash.se>
parents:
3846
diff
changeset
|
8 |
3839
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 module:hook("iq/host/http://jabber.org/protocol/stats:query", function (event) |
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local origin, stanza = event.origin, event.stanza; |
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local stats, _, extra = statsman.get_stats(); |
3840
054898e84a04
mod_stats39: Use a more local reference (silence luacheck warning)
Kim Alvefur <zash@zash.se>
parents:
3839
diff
changeset
|
12 local reply = st.reply(stanza); |
3839
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 reply:tag("query", { xmlns = "http://jabber.org/protocol/stats" }); |
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 for stat, value in pairs(stats) do |
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local unit = extra[stat] and extra[stat].units; |
3846
3941768916f1
mod_stats39: Format numbers with a bit more precision
Kim Alvefur <zash@zash.se>
parents:
3840
diff
changeset
|
16 reply:tag("stat", { name = stat, unit = unit, value = s_format("%.12g", value) }):up(); |
3839
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 end |
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 origin.send(reply); |
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 return true; |
a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end) |