mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-25 18:04:10 +00:00
de24bda010
修复获取角色攻略的 `collection_id` 修复获取失败后缓存为空字串符时直接返回 修改 `plugins.inline` 的标注的转载信息
47 lines
1.9 KiB
Python
47 lines
1.9 KiB
Python
from model.genshinhelper import Mihoyo
|
|
from service.repository import AsyncRepository
|
|
from service.cache import RedisCache
|
|
|
|
|
|
class GetGameInfo:
|
|
def __init__(self, repository: AsyncRepository, cache: RedisCache):
|
|
self.repository = repository
|
|
self.cache = cache
|
|
self.mihoyo = Mihoyo()
|
|
|
|
async def get_characters_cultivation_atlas(self, character_name: str) -> str:
|
|
qname = f"game:info:characters_cultivation_atlas:{character_name}"
|
|
url_info = await self.cache.get_str_list(qname)
|
|
if len(url_info) >= 1:
|
|
url = url_info[-1]
|
|
if url != "":
|
|
return url_info[-1]
|
|
|
|
async def get_post_id(collection_id: int) -> int:
|
|
post_full_in_collection = await self.mihoyo.get_post_full_in_collection(collection_id) # 642956
|
|
if post_full_in_collection.error:
|
|
await self.cache.set_str_list(qname, [""], 3600)
|
|
return -1
|
|
_post_id: int = -1
|
|
for post_data in post_full_in_collection.data["posts"]:
|
|
topics = post_data["topics"]
|
|
for topic in topics:
|
|
if character_name == topic["name"]:
|
|
_post_id = int(post_data["post"]["post_id"])
|
|
break
|
|
if _post_id != -1:
|
|
break
|
|
return _post_id
|
|
|
|
post_id = await get_post_id(839176)
|
|
if post_id == -1:
|
|
post_id = await get_post_id(839179)
|
|
if post_id == -1:
|
|
post_id = await get_post_id(839181)
|
|
if post_id == -1:
|
|
await self.cache.set_str_list(qname, [""], 3600)
|
|
return ""
|
|
artwork_info = await self.mihoyo.get_artwork_info(2, post_id)
|
|
await self.cache.set_str_list(qname, artwork_info.results.image_url_list, 3600)
|
|
return artwork_info.results.image_url_list[0]
|