From 3473dbbb773d3a1c9d3e5b86d037d945b9fddc8d Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Wed, 30 Oct 2024 07:36:59 +0100 Subject: [PATCH] Move CLO back to hashsets --- cogs/caf.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cogs/caf.py b/cogs/caf.py index 4caa3d2..fde5235 100644 --- a/cogs/caf.py +++ b/cogs/caf.py @@ -1,6 +1,7 @@ import io import json import subprocess +import uuid import discord from discord.ext import commands, tasks @@ -47,7 +48,7 @@ async def fetch_tags(self): embed.add_field(name="URL", value=value["url"], inline=False) await self.channel.send(embed=embed) - self.redis.lset("caf-fetch:tracked", key, json.dumps({ + self.redis.hset("caf-fetch:tracked", key, json.dumps({ "url": value["url"], "prefix": value["prefix"], "tag": new_tag @@ -77,8 +78,8 @@ def _get_tags(url): def _tracked(self): tracked = {} - for key, value in enumerate(self.redis.lrange("caf-fetch:tracked", 0, -1)): - tracked[key] = json.loads(value) + for key, value in self.redis.hscan_iter("caf-fetch:tracked"): + tracked[key.decode()] = json.loads(value) return tracked @@ -86,7 +87,7 @@ def _tracked(self): @commands.has_role("Project Director") async def track(self, ctx, url, prefix): assert url.startswith(self.CLO_URL_PREFIX), "Invalid URL" - self.redis.lpush("caf-fetch:tracked", json.dumps({ + self.redis.hset("caf-fetch:tracked", str(uuid.uuid4()), json.dumps({ "url": url, "prefix": prefix, "tag": None @@ -102,7 +103,7 @@ async def untrack(self, ctx, url, prefix=None): continue if prefix and value["prefix"] != prefix: continue - self.redis.lrem("caf-fetch:tracked", 0, json.dumps(value)) + self.redis.hdel("caf-fetch:tracked", key) await ctx.message.add_reaction("👍") @caf.command() @@ -110,7 +111,7 @@ async def untrack(self, ctx, url, prefix=None): async def tracked(self, ctx): response = [] - for value in self._tracked().values(): + for _, value in self._tracked().items(): response.append(f"{value['url']} {value['prefix']} {value['tag']}") await ctx.reply(file=discord.File(io.StringIO("\n".join(sorted(response))), filename="tracked.txt"))