Skip to content

Commit

Permalink
Move CLO back to hashsets
Browse files Browse the repository at this point in the history
  • Loading branch information
luk1337 committed Oct 30, 2024
1 parent 7b36927 commit 3473dbb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cogs/caf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import io
import json
import subprocess
import uuid

import discord
from discord.ext import commands, tasks
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -77,16 +78,16 @@ 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

@caf.command()
@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
Expand All @@ -102,15 +103,15 @@ 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()
@commands.has_role("Project Director")
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"))
Expand Down

0 comments on commit 3473dbb

Please sign in to comment.