Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sopel/irc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from __future__ import annotations

import abc
from collections import deque
from datetime import datetime
import logging
import os
Expand Down Expand Up @@ -798,7 +799,7 @@ def say(
with self.sending:
recipient_id = self.make_identifier(recipient)
recipient_stack = self.stack.setdefault(recipient_id, {
'messages': [],
'messages': deque(maxlen=10),
'flood_left': flood_burst_lines,
})

Expand Down Expand Up @@ -846,7 +847,7 @@ def say(

# Loop detection
if antiloop_threshold > 0 and elapsed < antiloop_window:
messages = [m[1] for m in recipient_stack['messages'][-10:]]
messages = [m[1] for m in recipient_stack['messages']]

# If what we're about to send repeated at least N times
# in the anti-looping window, replace it
Expand All @@ -858,11 +859,10 @@ def say(

self.backend.send_privmsg(recipient, text)

# update recipient meta-data
# update recipient metadata
flood_left = recipient_stack['flood_left'] - 1
recipient_stack['flood_left'] = max(0, flood_left)
recipient_stack['messages'].append((time.time(), safe(text)))
recipient_stack['messages'] = recipient_stack['messages'][-10:]

# Now that we've sent the first part, we need to send the rest if
# requested. Doing so recursively seems simpler than iteratively.
Expand Down