aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-07-18 13:46:10 +0200
committerGravatar Leon Sandøy <[email protected]>2020-07-18 13:46:10 +0200
commitb1311ea71adbc3c4c5568363aa971a08f21b2522 (patch)
treeb19207287ccf6cd5b19afebcaf0cd30d8b3a21dd
parentBulletlist with valid file types in converter. (diff)
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.
-rw-r--r--bot/bot.py14
1 files changed, 13 insertions, 1 deletions
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:
"""