@@ -253,15 +253,26 @@ Flood Prevention
253253----------------
254254
255255In order to avoid flooding the server, Sopel has a built-in flood prevention
256- mechanism. It can be controlled with several directives:
256+ mechanism. The flood burst limit can be controlled with these directives:
257257
258258* :attr: `~CoreSection.flood_burst_lines `: the number of messages
259259 that can be sent before triggering the throttle mechanism.
260- * :attr: `~CoreSection.flood_empty_wait `: time to wait once burst limit has been
261- reached before sending a new message.
262260* :attr: `~CoreSection.flood_refill_rate `: how much time (in seconds) must be
263261 spent before recovering flood limit.
264262
263+ The wait time when the flood limit is reached can be controlled with these:
264+
265+ * :attr: `~CoreSection.flood_empty_wait `: time to wait once burst limit has been
266+ reached before sending a new message.
267+ * :attr: `~CoreSection.flood_max_wait `: absolute maximum time to wait before
268+ sending a new message once the burst limit has been reached.
269+
270+ And the extra wait penalty for longer messages can be controlled with these:
271+
272+ * :attr: `~CoreSection.flood_text_length `: maximum size of messages before they
273+ start getting an extra wait penalty.
274+ * :attr: `~CoreSection.flood_penalty_ratio `: ratio used to compute said penalty.
275+
265276For example this configuration::
266277
267278 [core]
@@ -273,15 +284,50 @@ will allow 10 messages at once before triggering the throttle mechanism, then
273284it'll wait 0.5s before sending a new message, and refill the burst limit every
2742852 seconds.
275286
287+ The wait time **cannot be longer ** than :attr: `~CoreSection.flood_max_wait ` (2s
288+ by default). This maximum wait time includes any potential extra penalty for
289+ longer messages.
290+
291+ Messages that are longer than :attr: `~CoreSection.flood_text_length ` get an
292+ extra wait penalty. The penalty is computed using a penalty ratio (controlled
293+ by :attr: `~CoreSection.flood_penalty_ratio `, which is 1.4 by default)::
294+
295+ length_overflow = max(0, (len(text) - flood_text_length))
296+ extra_penalty = length_overflow / (flood_text_length * flood_penalty_ratio)
297+
298+ For example with a message of 80 characters, the added extra penalty will be::
299+
300+ length_overflow = max(0, 80 - 50) # == 30
301+ extra_penalty = 30 / (50 * 1.4) # == 0.428s (approximately)
302+
303+ With the default configuration, it means a minimum wait time of 0.928s before
304+ sending any new message (0.5s + 0.428s).
305+
306+ You can **deactivate ** this extra wait penalty by setting
307+ :attr: `~CoreSection.flood_penalty_ratio ` to 0.
308+
276309The default configuration works fine with most tested networks, but individual
277310bots' owners are invited to tweak as necessary to respect their network's flood
278311policy.
279312
280313.. versionadded :: 7.0
281314
282- Flood prevention has been modified in Sopel 7.0 and these configuration
283- options have been added: ``flood_burst_lines ``, ``flood_empty_wait ``, and
284- ``flood_refill_rate ``.
315+ Additional configuration options: ``flood_burst_lines ``, ``flood_empty_wait ``,
316+ and ``flood_refill_rate ``.
317+
318+ .. versionadded :: 7.1
319+
320+ Even more additional configuration options: ``flood_max_wait ``,
321+ ``flood_text_length ``, and ``flood_penalty_ratio ``.
322+
323+ It is now possible to deactivate the extra penalty for longer messages by
324+ setting ``flood_penalty_ratio `` to 0.
325+
326+ .. note ::
327+
328+ ``@dgw `` said once about Sopel's flood protection logic:
329+
330+ *"It's some arcane magic from AT LEAST a decade ago." *
285331
286332Perform commands on connect
287333---------------------------
0 commit comments