From 36754303904ce2588aa0914fce9caa0dceaa5493 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 29 Nov 2025 23:10:11 +0000 Subject: [PATCH] Discount any history times older than 6 months --- matchy/state.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/matchy/state.py b/matchy/state.py index 5af6096..0dbed7a 100644 --- a/matchy/state.py +++ b/matchy/state.py @@ -1,6 +1,6 @@ """Store bot state""" import os -from datetime import datetime +from datetime import datetime, timedelta from schema import Schema, Use, Optional from collections.abc import Generator from typing import Protocol @@ -243,18 +243,20 @@ class _State(): def get_history_timestamps(self, users: list[Member]) -> list[datetime]: """Grab all timestamps in the history""" - others = [m.id for m in users] + ids = [int(m.id) for m in users] # Fetch all the interaction times in history # But only for interactions in the given user group times = set() - for data in (data for id, data in self._users.items() if int(id) in others): + for data in (data for id, data in self._users.items() if id in ids): matches = data.get(_Key.MATCHES, {}) - for ts in (ts for id, ts in matches.items() if int(id) in others): + for ts in (ts for id, ts in matches.items() if id in ids): times.add(ts) # Convert to datetimes and sort datetimes = [ts_to_datetime(ts) for ts in times] + # Remove any entries older than 6 months ago + datetimes = [t for t in datetimes if t >= datetime.now() - timedelta(months=3)] datetimes.sort() return datetimes