# HG changeset patch # User Kim Alvefur # Date 1687643491 -7200 # Node ID 731ba9400c10c2bb48cd77f66dca33b01afd46d5 # Parent a1f8cc591b669853b7645caa096956c9d95baa44 mod_muc_limits: Raise cost for multi-line messages diff -r a1f8cc591b66 -r 731ba9400c10 mod_muc_limits/mod_muc_limits.lua --- a/mod_muc_limits/mod_muc_limits.lua Thu Jun 22 22:00:51 2023 +0200 +++ b/mod_muc_limits/mod_muc_limits.lua Sat Jun 24 23:51:31 2023 +0200 @@ -46,7 +46,15 @@ throttle = new_throttle(period*burst, burst); room.throttle = throttle; end - if not throttle:poll(1) then + local cost = 1; + local body = stanza:get_child_text("body"); + if body then + -- TODO calculate a text diagonal cross-section or some mathemagical + -- number, maybe some cost multipliers + local body_lines = select(2, body:gsub("\n[^\n]*", "")); + cost = cost + body_lines; + end + if not throttle:poll(cost) then module:log("debug", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid); if not dropped_jids then dropped_jids = { [from_jid] = true, from_jid }; @@ -60,7 +68,6 @@ return true; end local reply = st.error_reply(stanza, "wait", "policy-violation", "The room is currently overactive, please try again later"); - local body = stanza:get_child_text("body"); if body then reply:up():tag("body"):text(body):up(); end