Avatars caching implemented

This commit is contained in:
Profitroll 2022-12-17 23:25:53 +01:00
parent 41eb6e46ee
commit 6b00f181f6
2 changed files with 22 additions and 1 deletions

View File

@ -37,6 +37,10 @@
"sponsorships": {
"time": 9,
"enabled": true
},
"cache_avatars": {
"interval": 6,
"enabled": true
}
},
"locations": {

View File

@ -1,6 +1,8 @@
from os import path, sep
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from datetime import datetime
from datetime import datetime, timedelta
from app import app
from pyrogram.enums.chat_members_filter import ChatMembersFilter
from modules.utils import configGet, locale, logWrite
from dateutil.relativedelta import relativedelta
from modules.database import col_applications
@ -19,6 +21,21 @@ scheduler = AsyncIOScheduler()
# except AttributeError:
# continue
if configGet("enabled", "scheduler", "cache_avatars"):
@scheduler.scheduled_job(trigger="date", run_date=datetime.now()+timedelta(seconds=10))
@scheduler.scheduled_job(trigger="interval", hours=configGet("interval", "scheduler", "cache_avatars"))
async def cache_avatars():
list_of_users = []
async for member in app.get_chat_members(configGet("destination_group"), filter=ChatMembersFilter.SEARCH, query=""):
list_of_users.append(member.user)
for user in list_of_users:
if user.photo != None:
if not path.exists(f'{configGet("cache", "locations")}{sep}avatars{sep}{user.photo.big_file_id}'):
print(f'Pre-cached avatar {user.photo.big_file_id} of {user.id}', flush=True)
await app.download_media(user.photo.big_file_id, file_name=f'{configGet("cache", "locations")}{sep}avatars{sep}{user.photo.big_file_id}')
logWrite("Avatars caching performed")
if configGet("enabled", "scheduler", "birthdays"):
@scheduler.scheduled_job(trigger="cron", hour=configGet("time", "scheduler", "birthdays"))
async def check_birthdays():