mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-22 15:37:21 +00:00
🐛 修复提前抽取卡池
This commit is contained in:
parent
1a40ffd75c
commit
f77c6528d2
@ -8,6 +8,8 @@ from genshin import Client, InvalidCookies
|
|||||||
from genshin.utility.ds import generate_dynamic_secret
|
from genshin.utility.ds import generate_dynamic_secret
|
||||||
from genshin.utility.uid import recognize_genshin_server
|
from genshin.utility.uid import recognize_genshin_server
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
|
from pydantic import BaseModel, validator
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from modules.apihelper.base import ArtworkImage, PostInfo
|
from modules.apihelper.base import ArtworkImage, PostInfo
|
||||||
from modules.apihelper.helpers import get_device_id
|
from modules.apihelper.helpers import get_device_id
|
||||||
@ -61,7 +63,7 @@ class Hyperion:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_list_url_params(forum_id: int, is_good: bool = False, is_hot: bool = False, page_size: int = 20) -> dict:
|
def get_list_url_params(forum_id: int, is_good: bool = False, is_hot: bool = False, page_size: int = 20) -> dict:
|
||||||
params = {
|
return {
|
||||||
"forum_id": forum_id,
|
"forum_id": forum_id,
|
||||||
"gids": 2,
|
"gids": 2,
|
||||||
"is_good": is_good,
|
"is_good": is_good,
|
||||||
@ -70,8 +72,6 @@ class Hyperion:
|
|||||||
"sort_type": 1,
|
"sort_type": 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
return params
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_images_params(
|
def get_images_params(
|
||||||
resize: int = 600, quality: int = 80, auto_orient: int = 0, interlace: int = 1, images_format: str = "jpg"
|
resize: int = 600, quality: int = 80, auto_orient: int = 0, interlace: int = 1, images_format: str = "jpg"
|
||||||
@ -141,6 +141,18 @@ class Hyperion:
|
|||||||
await self.client.shutdown()
|
await self.client.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
class GachaInfoObject(BaseModel):
|
||||||
|
begin_time: datetime
|
||||||
|
end_time: datetime
|
||||||
|
gacha_id: str
|
||||||
|
gacha_name: str
|
||||||
|
gacha_type: int
|
||||||
|
|
||||||
|
@validator("begin_time", "end_time", pre=True, allow_reuse=True)
|
||||||
|
def validate_time(cls, v):
|
||||||
|
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
class GachaInfo:
|
class GachaInfo:
|
||||||
GACHA_LIST_URL = "https://webstatic.mihoyo.com/hk4e/gacha_info/cn_gf01/gacha/list.json"
|
GACHA_LIST_URL = "https://webstatic.mihoyo.com/hk4e/gacha_info/cn_gf01/gacha/list.json"
|
||||||
GACHA_INFO_URL = "https://webstatic.mihoyo.com/hk4e/gacha_info/cn_gf01/%s/zh-cn.json"
|
GACHA_INFO_URL = "https://webstatic.mihoyo.com/hk4e/gacha_info/cn_gf01/%s/zh-cn.json"
|
||||||
@ -158,16 +170,17 @@ class GachaInfo:
|
|||||||
self.cache = {}
|
self.cache = {}
|
||||||
self.cache_ttl = 600
|
self.cache_ttl = 600
|
||||||
|
|
||||||
async def get_gacha_list_info(self) -> dict:
|
async def get_gacha_list_info(self) -> List[GachaInfoObject]:
|
||||||
if self.cache.get("time", 0) + self.cache_ttl < time.time():
|
if self.cache.get("time", 0) + self.cache_ttl < time.time():
|
||||||
self.cache.clear()
|
self.cache.clear()
|
||||||
cache = self.cache.get("gacha_list_info")
|
cache = self.cache.get("gacha_list_info")
|
||||||
if cache is not None:
|
if cache is not None:
|
||||||
return cache
|
return cache
|
||||||
req = await self.client.get(self.GACHA_LIST_URL)
|
req = await self.client.get(self.GACHA_LIST_URL)
|
||||||
self.cache["gacha_list_info"] = req
|
data = [GachaInfoObject(**i) for i in req["list"]]
|
||||||
|
self.cache["gacha_list_info"] = data
|
||||||
self.cache["time"] = time.time()
|
self.cache["time"] = time.time()
|
||||||
return req
|
return data
|
||||||
|
|
||||||
async def get_gacha_info(self, gacha_id: str) -> dict:
|
async def get_gacha_info(self, gacha_id: str) -> dict:
|
||||||
cache = self.cache.get(gacha_id)
|
cache = self.cache.get(gacha_id)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from datetime import datetime
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@ -41,12 +42,13 @@ class Gacha(Plugin, BasePlugin):
|
|||||||
async def gacha_info(self, gacha_name: str = "角色活动", default: bool = False):
|
async def gacha_info(self, gacha_name: str = "角色活动", default: bool = False):
|
||||||
gacha_list_info = await self.gacha.get_gacha_list_info()
|
gacha_list_info = await self.gacha.get_gacha_list_info()
|
||||||
gacha_id = ""
|
gacha_id = ""
|
||||||
for gacha in gacha_list_info["list"]:
|
now = datetime.now()
|
||||||
if gacha["gacha_name"] == gacha_name:
|
for gacha in gacha_list_info:
|
||||||
gacha_id = gacha["gacha_id"]
|
if gacha.gacha_name == gacha_name and gacha.begin_time <= now <= gacha.end_time:
|
||||||
|
gacha_id = gacha.gacha_id
|
||||||
if gacha_id == "":
|
if gacha_id == "":
|
||||||
if default and len(gacha_list_info["list"]) > 0:
|
if default and len(gacha_list_info) > 0:
|
||||||
gacha_id = gacha_list_info["list"][0]["gacha_id"]
|
gacha_id = gacha_list_info[0].gacha_id
|
||||||
else:
|
else:
|
||||||
raise GachaNotFound(gacha_name)
|
raise GachaNotFound(gacha_name)
|
||||||
gacha_info = await self.gacha.get_gacha_info(gacha_id)
|
gacha_info = await self.gacha.get_gacha_info(gacha_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user