Mercurial > prosody-modules
changeset 5567:d52cc18f0aa8
mod_muc_limits: Add a limit on number of bytes in a message body
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 25 Jun 2023 00:00:02 +0200 (18 months ago) |
parents | f71d66bd87be |
children | 540beba5b75b |
files | mod_muc_limits/README.markdown mod_muc_limits/mod_muc_limits.lua |
diffstat | 2 files changed, 7 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_muc_limits/README.markdown Sat Jun 24 23:56:13 2023 +0200 +++ b/mod_muc_limits/README.markdown Sun Jun 25 00:00:02 2023 +0200 @@ -40,6 +40,7 @@ muc_event_rate 0.5 The maximum number of events per second. muc_burst_factor 6 Allow temporary bursts of this multiple. muc_max_nick_length 23 The maximum allowed length of user nicknames + muc_max_char_count 5664 The maximum allowed number of bytes in a message muc_max_line_count 23 The maximum allowed number of lines in a message For more understanding of how these values are used, see the algorithm
--- a/mod_muc_limits/mod_muc_limits.lua Sat Jun 24 23:56:13 2023 +0200 +++ b/mod_muc_limits/mod_muc_limits.lua Sun Jun 25 00:00:02 2023 +0200 @@ -14,6 +14,7 @@ local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods local max_line_count = module:get_option_number("muc_max_line_count", 23); -- Default chosen through s/scientific methods/copy and paste/ +local max_char_count = module:get_option_number("muc_max_char_count", 5664); -- Default chosen by multiplying a number by 23 local join_only = module:get_option_boolean("muc_limit_joins_only", false); local dropped_count = 0; @@ -53,6 +54,11 @@ if body then -- TODO calculate a text diagonal cross-section or some mathemagical -- number, maybe some cost multipliers + if #body > max_char_count then + origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your message is too long, please write a shorter one") + :up():tag("x", { xmlns = xmlns_muc })); + return true; + end local body_lines = select(2, body:gsub("\n[^\n]*", "")); if body_lines > max_line_count then origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your message is too long, please write a shorter one"):up()