feat: deduplikacja wpisów w historii odtwarzania (każde nagranie widoczne tylko raz)
This commit is contained in:
1 file changed
+10
-1
@@ -34,7 +34,15 @@ class MusicBot(commands.Cog):
|
|||||||
import json
|
import json
|
||||||
with open(config_path, "r") as f:
|
with open(config_path, "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
self.history[guild_id] = data.get(str(guild_id), [])
|
raw_history = data.get(str(guild_id), [])
|
||||||
|
unique_history = []
|
||||||
|
seen = set()
|
||||||
|
for item in raw_history:
|
||||||
|
key = (item.get("title", ""), item.get("url", ""))
|
||||||
|
if key not in seen:
|
||||||
|
seen.add(key)
|
||||||
|
unique_history.append(item)
|
||||||
|
self.history[guild_id] = unique_history
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error loading history: {e}")
|
print(f"Error loading history: {e}")
|
||||||
self.history[guild_id] = []
|
self.history[guild_id] = []
|
||||||
@@ -69,6 +77,7 @@ class MusicBot(commands.Cog):
|
|||||||
"is_local": player.data.get("is_local", False),
|
"is_local": player.data.get("is_local", False),
|
||||||
"filepath": player.data.get("filepath")
|
"filepath": player.data.get("filepath")
|
||||||
}
|
}
|
||||||
|
history = [h for h in history if h.get("title") != entry["title"] and (not entry.get("url") or h.get("url") != entry["url"])]
|
||||||
history.insert(0, entry)
|
history.insert(0, entry)
|
||||||
self.history[guild_id] = history[:50]
|
self.history[guild_id] = history[:50]
|
||||||
self.save_history(guild_id)
|
self.save_history(guild_id)
|
||||||
|
|||||||
Reference in new issue
Block a user