Mercurial > prosody-modules
comparison mod_muc_limits/mod_muc_limits.lua @ 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 |
| parents | f71d66bd87be |
| children | 6680a1f53353 |
comparison
equal
deleted
inserted
replaced
| 5566:f71d66bd87be | 5567:d52cc18f0aa8 |
|---|---|
| 12 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); | 12 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); |
| 13 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); | 13 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); |
| 14 | 14 |
| 15 local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods | 15 local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods |
| 16 local max_line_count = module:get_option_number("muc_max_line_count", 23); -- Default chosen through s/scientific methods/copy and paste/ | 16 local max_line_count = module:get_option_number("muc_max_line_count", 23); -- Default chosen through s/scientific methods/copy and paste/ |
| 17 local max_char_count = module:get_option_number("muc_max_char_count", 5664); -- Default chosen by multiplying a number by 23 | |
| 17 | 18 |
| 18 local join_only = module:get_option_boolean("muc_limit_joins_only", false); | 19 local join_only = module:get_option_boolean("muc_limit_joins_only", false); |
| 19 local dropped_count = 0; | 20 local dropped_count = 0; |
| 20 local dropped_jids; | 21 local dropped_jids; |
| 21 | 22 |
| 51 local cost = 1; | 52 local cost = 1; |
| 52 local body = stanza:get_child_text("body"); | 53 local body = stanza:get_child_text("body"); |
| 53 if body then | 54 if body then |
| 54 -- TODO calculate a text diagonal cross-section or some mathemagical | 55 -- TODO calculate a text diagonal cross-section or some mathemagical |
| 55 -- number, maybe some cost multipliers | 56 -- number, maybe some cost multipliers |
| 57 if #body > max_char_count then | |
| 58 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your message is too long, please write a shorter one") | |
| 59 :up():tag("x", { xmlns = xmlns_muc })); | |
| 60 return true; | |
| 61 end | |
| 56 local body_lines = select(2, body:gsub("\n[^\n]*", "")); | 62 local body_lines = select(2, body:gsub("\n[^\n]*", "")); |
| 57 if body_lines > max_line_count then | 63 if body_lines > max_line_count then |
| 58 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your message is too long, please write a shorter one"):up() | 64 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your message is too long, please write a shorter one"):up() |
| 59 :tag("x", { xmlns = xmlns_muc; })); | 65 :tag("x", { xmlns = xmlns_muc; })); |
| 60 return true; | 66 return true; |
