From ace71fd6be52e1ae871931f2fd1c5ce436135777 Mon Sep 17 00:00:00 2001 From: profitroll Date: Mon, 2 Jan 2023 10:48:55 +0100 Subject: [PATCH] Members/admins caching is now configurable --- config_example.json | 8 ++++++++ modules/scheduled.py | 30 ++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/config_example.json b/config_example.json index 937d212..55bbd79 100644 --- a/config_example.json +++ b/config_example.json @@ -42,6 +42,14 @@ "cache_avatars": { "interval": 6, "enabled": true + }, + "cache_members": { + "interval": 30, + "enabled": true + }, + "cache_admins": { + "interval": 120, + "enabled": true } }, "locations": { diff --git a/modules/scheduled.py b/modules/scheduled.py index 601ee5a..979c964 100644 --- a/modules/scheduled.py +++ b/modules/scheduled.py @@ -12,21 +12,23 @@ from modules.database import col_applications, col_sponsorships scheduler = AsyncIOScheduler() -@scheduler.scheduled_job(trigger="interval", seconds=20) -async def cache_group_members(): - list_of_users = [] - async for member in app.get_chat_members(configGet("destination_group")): - list_of_users.append(member.user.id) - makedirs("cache", exist_ok=True) - jsonSave(list_of_users, f"cache{sep}group_members") +if configGet("enabled", "scheduler", "cache_members"): + @scheduler.scheduled_job(trigger="interval", seconds=configGet("interval", "scheduler", "cache_members")) + async def cache_group_members(): + list_of_users = [] + async for member in app.get_chat_members(configGet("destination_group")): + list_of_users.append(member.user.id) + makedirs("cache", exist_ok=True) + jsonSave(list_of_users, f"cache{sep}group_members") -@scheduler.scheduled_job(trigger="interval", seconds=40) -async def cache_admins(): - list_of_users = [] - async for member in app.get_chat_members(configGet("admin_group")): - list_of_users.append(member.user.id) - makedirs("cache", exist_ok=True) - jsonSave(list_of_users, f"cache{sep}admins") +if configGet("enabled", "scheduler", "cache_admins"): + @scheduler.scheduled_job(trigger="interval", seconds=configGet("interval", "scheduler", "cache_admins")) + async def cache_admins(): + list_of_users = [] + async for member in app.get_chat_members(configGet("admin_group")): + list_of_users.append(member.user.id) + makedirs("cache", exist_ok=True) + jsonSave(list_of_users, f"cache{sep}admins") # Cache the avatars of group members if configGet("enabled", "scheduler", "cache_avatars"):