Mercurial > prosody-modules
comparison mod_muc_limits/mod_muc_limits.lua @ 5566:f71d66bd87be
mod_muc_limits: Add a limit on number of lines per message
More vertical space -> more cost
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 24 Jun 2023 23:56:13 +0200 |
| parents | 731ba9400c10 |
| children | d52cc18f0aa8 |
comparison
equal
deleted
inserted
replaced
| 5565:b97ae1cd7813 | 5566:f71d66bd87be |
|---|---|
| 11 | 11 |
| 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/ | |
| 17 | |
| 16 local join_only = module:get_option_boolean("muc_limit_joins_only", false); | 18 local join_only = module:get_option_boolean("muc_limit_joins_only", false); |
| 17 local dropped_count = 0; | 19 local dropped_count = 0; |
| 18 local dropped_jids; | 20 local dropped_jids; |
| 19 | 21 |
| 20 local function log_dropped() | 22 local function log_dropped() |
| 50 local body = stanza:get_child_text("body"); | 52 local body = stanza:get_child_text("body"); |
| 51 if body then | 53 if body then |
| 52 -- TODO calculate a text diagonal cross-section or some mathemagical | 54 -- TODO calculate a text diagonal cross-section or some mathemagical |
| 53 -- number, maybe some cost multipliers | 55 -- number, maybe some cost multipliers |
| 54 local body_lines = select(2, body:gsub("\n[^\n]*", "")); | 56 local body_lines = select(2, body:gsub("\n[^\n]*", "")); |
| 57 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() | |
| 59 :tag("x", { xmlns = xmlns_muc; })); | |
| 60 return true; | |
| 61 end | |
| 55 cost = cost + body_lines; | 62 cost = cost + body_lines; |
| 56 end | 63 end |
| 57 if not throttle:poll(cost) then | 64 if not throttle:poll(cost) then |
| 58 module:log("debug", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid); | 65 module:log("debug", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid); |
| 59 if not dropped_jids then | 66 if not dropped_jids then |
