mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-21 22:58:05 +00:00
🐛 Fix post code regex
This commit is contained in:
parent
8c8fa8ea99
commit
62891670c0
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user