diff options
| author | david <[email protected]> | 2026-10-20 15:49:53 -0300 |
|---|---|---|
| committer | david <[email protected]> | 2026-10-20 15:49:53 -0300 |
| commit | d70458154894f432f45b96fe7139fe31af3f8124 (patch) | |
| tree | e44c21e9d47ad63ffb3d800dc36f3d2c40f2c903 | |
| parent | 7958daa50debe471830aecf2c43af5054d682101 (diff) | |
| download | faggot-chan-d70458154894f432f45b96fe7139fe31af3f8124.tar.gz faggot-chan-d70458154894f432f45b96fe7139fe31af3f8124.zip | |
autocleanup of manually deleted images from media
| -rw-r--r-- | bot.py | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -254,12 +254,15 @@ vector_db_ready = False # gets set to True after first rebuild so we don't keep saved_media = set() # file names inside MEDIA_DIR +kept_media_lines = [] with MEDIA_FILE.open("r", encoding="utf-8") as f: for line in f: if "saved media:" in line: name = line.split("saved media:", 1)[1].strip() if (MEDIA_DIR / name).is_file(): # old entries were urls (those expire), they don't match a file so they get dropped saved_media.add(name) + kept_media_lines.append(line) +MEDIA_FILE.write_text("".join(kept_media_lines), encoding="utf-8") # rewritten without the entries of deleted files async def steal_media(url: str, name: str): # discord cdn links are signed and die after a day or so, so we keep our own copy @@ -428,6 +431,9 @@ def sync_reactions(guild): if n not in data[key]: data[key][n] = "" changed = True + for n in [n for n in data["media"] if n not in saved_media]: # file got deleted, drop its entry too + del data["media"][n] + changed = True if changed: REACTIONS_FILE.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8") |
