From ced51c84cb211ede8677d11d645ca67630cc725e Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 16 Feb 2023 17:38:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Calendar=20Data=20Expire=20in=20?= =?UTF-8?q?next=20hour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/calendar.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/genshin/calendar.py b/plugins/genshin/calendar.py index 77be2a4..19176ad 100644 --- a/plugins/genshin/calendar.py +++ b/plugins/genshin/calendar.py @@ -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)