From b1311ea71adbc3c4c5568363aa971a08f21b2522 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sat, 18 Jul 2020 13:46:10 +0200 Subject: Make the cache more convenient to access. Instead of just dumping the JSON response from the site, we'll build a data structure that it will be convenient to access from our new cog, and from the Filtering cog. --- bot/bot.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bot/bot.py b/bot/bot.py index b170be6d3..6c02e72a7 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -51,7 +51,19 @@ class Bot(commands.Bot): async def _cache_allow_deny_list_data(self) -> None: """Cache all the data in the AllowDenyList on the site.""" - self.allow_deny_list_cache = await self.api_client.get('bot/allow_deny_lists') + full_cache = await self.api_client.get('bot/allow_deny_lists') + self.allow_deny_list_cache = {} + + for item in full_cache: + type_ = item.get("type") + allowed = item.get("allowed") + metadata = { + "content": item.get("content"), + "id": item.get("id"), + "created_at": item.get("created_at"), + "updated_at": item.get("updated_at"), + } + self.allow_deny_list_cache.setdefault(f"{type_}.{allowed}", []).append(metadata) async def _create_redis_session(self) -> None: """ -- cgit v1.2.3