From 62891670c0577795078ea78001b25124534f7f3b Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 16 Mar 2024 18:45:57 +0800 Subject: [PATCH] :bug: Fix post code regex --- modules/apihelper/client/components/hyperion.py | 3 +++ modules/apihelper/models/genshin/hyperion.py | 6 +++++- plugins/admin/post_code.py | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/apihelper/client/components/hyperion.py b/modules/apihelper/client/components/hyperion.py index 4fc3d503..cee6f50b 100644 --- a/modules/apihelper/client/components/hyperion.py +++ b/modules/apihelper/client/components/hyperion.py @@ -174,11 +174,14 @@ class Hyperion: } codes = [] response = await self.client.get(url=self.LIVE_CODE_HOYO_URL, headers=headers, params=params) + guess_offline_at = LiveCodeHoYo.guess_offline_at() for module in response.get("modules", []): if exchange_group := module.get("exchange_group"): for code_data in exchange_group.get("bonuses", []): codes.append(LiveCodeHoYo(**code_data)) break + for _ in range(len(codes), 3): + codes.append(LiveCodeHoYo(exchange_code="", offline_at=guess_offline_at)) return codes async def close(self): diff --git a/modules/apihelper/models/genshin/hyperion.py b/modules/apihelper/models/genshin/hyperion.py index eefa4875..3f307dc7 100644 --- a/modules/apihelper/models/genshin/hyperion.py +++ b/modules/apihelper/models/genshin/hyperion.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timedelta from io import BytesIO from typing import Any, List, Optional @@ -121,3 +121,7 @@ class LiveCodeHoYo(BaseModel): @property def text(self) -> str: return self.exchange_code if self.exchange_code else "XXXXXXXXXXXX" + + @staticmethod + def guess_offline_at() -> datetime: + return datetime.now().replace(hour=12, minute=0, second=0, microsecond=0) + timedelta(days=1) diff --git a/plugins/admin/post_code.py b/plugins/admin/post_code.py index ed6c119e..ad15c8eb 100644 --- a/plugins/admin/post_code.py +++ b/plugins/admin/post_code.py @@ -141,9 +141,9 @@ class PostCode(Plugin.Conversation): continue if not (subject := post.get("subject")): continue - if not (match := self.SUBJECT_RE.match(subject)): + if not (match := self.SUBJECT_RE.findall(subject)): continue - return match.group(1), post + return match[0], post return None, None def init_act_id(self, post: Dict) -> Optional[str]: @@ -179,7 +179,7 @@ class PostCode(Plugin.Conversation): post_code_handler_data.ver_code = ver_code post_code_handler_data.mys_code = await client.get_live_code(act_id, ver_code) post_code_handler_data.hoyo_code = await client.get_live_code_hoyo(self.gids) - if len(post_code_handler_data.mys_code) != 3 or len(post_code_handler_data.hoyo_code) != 3: + if len(post_code_handler_data.mys_code) != 3: raise ValueError("获取兑换码数据成功,但是数量不对") return True finally: @@ -312,7 +312,7 @@ class PostCode(Plugin.Conversation): try: mys_code = await client.get_live_code(act_id, ver_code) hoyo_code = await client.get_live_code_hoyo(self.gids) - if len(post_code_handler_data.mys_code) != 3 or len(post_code_handler_data.hoyo_code) != 3: + if len(post_code_handler_data.mys_code) != 3: raise ValueError("获取兑换码数据成功,但是数量不对") if post_code_handler_data.have_changes(mys_code, hoyo_code): post_code_handler_data.mys_code = mys_code