🎨 Calendar Data Expire in next hour

This commit is contained in:
xtaodada 2023-02-16 17:38:43 +08:00
parent ea94583a5b
commit ced51c84cb
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -1,3 +1,4 @@
from datetime import datetime, timedelta
from typing import Dict
from telegram import Update
@ -38,7 +39,9 @@ class CalendarPlugin(Plugin, BasePlugin):
if data := await self.cache.get("plugin:calendar"):
return jsonlib.loads(data.decode("utf-8"))
data = await self.calendar.get_photo_data(self.assets_service)
await self.cache.set("plugin:calendar", jsonlib.dumps(data, default=lambda x: x.dict()), ex=1800)
now = datetime.now()
next_hour = (now + timedelta(hours=1)).replace(minute=0, second=0, microsecond=0)
await self.cache.set("plugin:calendar", jsonlib.dumps(data, default=lambda x: x.dict()), ex=next_hour - now)
return data
@handler.command("calendar", block=False)