Skip to content

Commit

Permalink
Make crosspost message attachment cache limit to 100 entries in 'anti…
Browse files Browse the repository at this point in the history
…_crosspost' extension
  • Loading branch information
Mega-JC committed Jul 28, 2024
1 parent e2b9427 commit 0a109da
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pcbot/exts/anti_crosspost.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

logger = logging.getLogger(__name__)

fetched_attachments: dict[int, bytes] = {}
fetched_attachments: OrderedDict[int, bytes] = OrderedDict()


def hamming_distance_padded(str1, str2):
Expand All @@ -44,6 +44,10 @@ async def fetch_attachment(attachment: discord.Attachment, cache: bool = True) -
if cache:
fetched_attachments[attachment.id] = data
logger.debug(f"Fetched attachment from source: {attachment.id}")

if len(fetched_attachments) > 100:
fetched_attachments.popitem(last=False)

return data


Expand Down

0 comments on commit 0a109da

Please sign in to comment.