Avatars caching implemented
This commit is contained in:
parent
41eb6e46ee
commit
6b00f181f6
@ -37,6 +37,10 @@
|
|||||||
"sponsorships": {
|
"sponsorships": {
|
||||||
"time": 9,
|
"time": 9,
|
||||||
"enabled": true
|
"enabled": true
|
||||||
|
},
|
||||||
|
"cache_avatars": {
|
||||||
|
"interval": 6,
|
||||||
|
"enabled": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"locations": {
|
"locations": {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
from os import path, sep
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from app import app
|
from app import app
|
||||||
|
from pyrogram.enums.chat_members_filter import ChatMembersFilter
|
||||||
from modules.utils import configGet, locale, logWrite
|
from modules.utils import configGet, locale, logWrite
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from modules.database import col_applications
|
from modules.database import col_applications
|
||||||
@ -19,6 +21,21 @@ scheduler = AsyncIOScheduler()
|
|||||||
# except AttributeError:
|
# except AttributeError:
|
||||||
# continue
|
# 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"):
|
if configGet("enabled", "scheduler", "birthdays"):
|
||||||
@scheduler.scheduled_job(trigger="cron", hour=configGet("time", "scheduler", "birthdays"))
|
@scheduler.scheduled_job(trigger="cron", hour=configGet("time", "scheduler", "birthdays"))
|
||||||
async def check_birthdays():
|
async def check_birthdays():
|
||||||
|
Reference in New Issue
Block a user