mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-26 02:11:03 +00:00
修改模块名称和类名称
已经确认检查单上的内容检查完毕
This commit is contained in:
parent
6ed9960ed1
commit
cabf28d0aa
3
model/apihelper/__init__.py
Normal file
3
model/apihelper/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from .hyperion import *
|
||||||
|
from .hoyolab import *
|
||||||
|
from .gacha import *
|
@ -57,7 +57,7 @@ class ArtworkInfo:
|
|||||||
self.post_id = post_id
|
self.post_id = post_id
|
||||||
|
|
||||||
|
|
||||||
class MiHoYoBBSResponse:
|
class HyperionResponse:
|
||||||
def __init__(self, response=None, error_message: str = ""):
|
def __init__(self, response=None, error_message: str = ""):
|
||||||
if response is None:
|
if response is None:
|
||||||
self.error: bool = True
|
self.error: bool = True
|
||||||
@ -124,5 +124,5 @@ class MiHoYoBBSResponse:
|
|||||||
|
|
||||||
|
|
||||||
class ServiceEnum(Enum):
|
class ServiceEnum(Enum):
|
||||||
MIHOYO = 1
|
HYPERION = 1
|
||||||
HOYOLAB = 2
|
HOYOLAB = 2
|
@ -1,6 +1,6 @@
|
|||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from model.genshinhelper import BaseResponseData
|
from model.apihelper import BaseResponseData
|
||||||
|
|
||||||
|
|
||||||
class GachaInfo:
|
class GachaInfo:
|
@ -1,7 +1,7 @@
|
|||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
|
|
||||||
from model.genshinhelper import BaseResponseData
|
from model.apihelper import BaseResponseData
|
||||||
from model.genshinhelper.helpers import get_ds, get_device_id, recognize_server
|
from model.apihelper.helpers import get_ds, get_device_id, recognize_server
|
||||||
|
|
||||||
|
|
||||||
class Genshin:
|
class Genshin:
|
@ -3,11 +3,16 @@ import re
|
|||||||
from typing import List
|
from typing import List
|
||||||
import httpx
|
import httpx
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
from .base import MiHoYoBBSResponse, ArtworkImage, BaseResponseData
|
from .base import HyperionResponse, ArtworkImage, BaseResponseData
|
||||||
from .helpers import get_ds, get_device_id
|
from .helpers import get_ds, get_device_id
|
||||||
|
|
||||||
|
|
||||||
class Mihoyo:
|
class Hyperion:
|
||||||
|
"""
|
||||||
|
米忽悠bbs相关API请求
|
||||||
|
该名称来源于米忽悠的米游社包名结尾,考虑到大部分重要的功能都能是在移动端实现了
|
||||||
|
"""
|
||||||
|
|
||||||
POST_FULL_URL = "https://bbs-api.mihoyo.com/post/wapi/getPostFull"
|
POST_FULL_URL = "https://bbs-api.mihoyo.com/post/wapi/getPostFull"
|
||||||
POST_FULL_IN_COLLECTION_URL = "https://bbs-api.mihoyo.com/post/wapi/getPostFullInCollection"
|
POST_FULL_IN_COLLECTION_URL = "https://bbs-api.mihoyo.com/post/wapi/getPostFullInCollection"
|
||||||
GET_NEW_LIST_URL = "https://bbs-api.mihoyo.com/post/wapi/getNewsList"
|
GET_NEW_LIST_URL = "https://bbs-api.mihoyo.com/post/wapi/getNewsList"
|
||||||
@ -85,7 +90,7 @@ class Mihoyo:
|
|||||||
return BaseResponseData(error_message="请求错误")
|
return BaseResponseData(error_message="请求错误")
|
||||||
return BaseResponseData(response.json())
|
return BaseResponseData(response.json())
|
||||||
|
|
||||||
async def get_artwork_info(self, gids: int, post_id: int, read: int = 1) -> MiHoYoBBSResponse:
|
async def get_artwork_info(self, gids: int, post_id: int, read: int = 1) -> HyperionResponse:
|
||||||
params = {
|
params = {
|
||||||
"gids": gids,
|
"gids": gids,
|
||||||
"post_id": post_id,
|
"post_id": post_id,
|
||||||
@ -93,8 +98,8 @@ class Mihoyo:
|
|||||||
}
|
}
|
||||||
response = await self.client.get(self.POST_FULL_URL, params=params)
|
response = await self.client.get(self.POST_FULL_URL, params=params)
|
||||||
if response.is_error:
|
if response.is_error:
|
||||||
return MiHoYoBBSResponse(error_message="请求错误")
|
return HyperionResponse(error_message="请求错误")
|
||||||
return MiHoYoBBSResponse(response.json())
|
return HyperionResponse(response.json())
|
||||||
|
|
||||||
async def get_post_full_info(self, gids: int, post_id: int, read: int = 1) -> BaseResponseData:
|
async def get_post_full_info(self, gids: int, post_id: int, read: int = 1) -> BaseResponseData:
|
||||||
params = {
|
params = {
|
||||||
@ -161,7 +166,7 @@ class YuanShen:
|
|||||||
USER_AGENT = "Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
USER_AGENT = "Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
||||||
"Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0"
|
"Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0"
|
||||||
REFERER = "https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?" \
|
REFERER = "https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?" \
|
||||||
"bbs_auth_required=true&act_id=e202009291139501&utm_source=bbs&utm_medium=mys&utm_campaign=icon"
|
"bbs_auth_required=true&act_id=e202009291139501&utm_source=hyperion&utm_medium=mys&utm_campaign=icon"
|
||||||
ORIGIN = "https://webstatic.mihoyo.com"
|
ORIGIN = "https://webstatic.mihoyo.com"
|
||||||
|
|
||||||
ACT_ID = "e202009291139501"
|
ACT_ID = "e202009291139501"
|
@ -1,3 +0,0 @@
|
|||||||
from .mihoyo import *
|
|
||||||
from .hoyolab import *
|
|
||||||
from .gacha import *
|
|
@ -92,7 +92,7 @@ class Inline:
|
|||||||
InlineQueryResultPhoto(
|
InlineQueryResultPhoto(
|
||||||
id=str(uuid4()),
|
id=str(uuid4()),
|
||||||
photo_url=url + "?x-oss-process=format,jpg",
|
photo_url=url + "?x-oss-process=format,jpg",
|
||||||
thumb_url=url_add_params(url, self.service.get_game_info.mihoyo.get_images_params(
|
thumb_url=url_add_params(url, self.service.get_game_info.hyperion.get_images_params(
|
||||||
resize=300)),
|
resize=300)),
|
||||||
title=title,
|
title=title,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
|
@ -9,7 +9,7 @@ from telegram.helpers import escape_markdown
|
|||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
from logger import Log
|
from logger import Log
|
||||||
from model.genshinhelper import Mihoyo, ArtworkImage
|
from model.apihelper import Hyperion, ArtworkImage
|
||||||
from plugins.base import BasePlugins
|
from plugins.base import BasePlugins
|
||||||
from service import BaseService
|
from service import BaseService
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ class Post(BasePlugins):
|
|||||||
|
|
||||||
def __init__(self, service: BaseService):
|
def __init__(self, service: BaseService):
|
||||||
super().__init__(service)
|
super().__init__(service)
|
||||||
self.bbs = Mihoyo()
|
self.bbs = Hyperion()
|
||||||
|
|
||||||
async def command_start(self, update: Update, context: CallbackContext) -> int:
|
async def command_start(self, update: Update, context: CallbackContext) -> int:
|
||||||
user = update.effective_user
|
user = update.effective_user
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from model.genshinhelper import GachaInfo
|
from model.apihelper import GachaInfo
|
||||||
from service.repository import AsyncRepository
|
from service.repository import AsyncRepository
|
||||||
from service.cache import RedisCache
|
from service.cache import RedisCache
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from model.genshinhelper import Mihoyo
|
from model.apihelper import Hyperion
|
||||||
from service.repository import AsyncRepository
|
from service.repository import AsyncRepository
|
||||||
from service.cache import RedisCache
|
from service.cache import RedisCache
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ class GetGameInfo:
|
|||||||
def __init__(self, repository: AsyncRepository, cache: RedisCache):
|
def __init__(self, repository: AsyncRepository, cache: RedisCache):
|
||||||
self.repository = repository
|
self.repository = repository
|
||||||
self.cache = cache
|
self.cache = cache
|
||||||
self.mihoyo = Mihoyo()
|
self.hyperion = Hyperion()
|
||||||
|
|
||||||
async def get_characters_cultivation_atlas(self, character_name: str) -> str:
|
async def get_characters_cultivation_atlas(self, character_name: str) -> str:
|
||||||
qname = f"game:info:characters_cultivation_atlas:{character_name}"
|
qname = f"game:info:characters_cultivation_atlas:{character_name}"
|
||||||
@ -18,7 +18,7 @@ class GetGameInfo:
|
|||||||
return url_info[-1]
|
return url_info[-1]
|
||||||
|
|
||||||
async def get_post_id(collection_id: int) -> int:
|
async def get_post_id(collection_id: int) -> int:
|
||||||
post_full_in_collection = await self.mihoyo.get_post_full_in_collection(collection_id)
|
post_full_in_collection = await self.hyperion.get_post_full_in_collection(collection_id)
|
||||||
if post_full_in_collection.error:
|
if post_full_in_collection.error:
|
||||||
await self.cache.set_str_list(qname, [""], 3600)
|
await self.cache.set_str_list(qname, [""], 3600)
|
||||||
return -1
|
return -1
|
||||||
@ -41,6 +41,6 @@ class GetGameInfo:
|
|||||||
if post_id == -1:
|
if post_id == -1:
|
||||||
await self.cache.set_str_list(qname, [""], 3600)
|
await self.cache.set_str_list(qname, [""], 3600)
|
||||||
return ""
|
return ""
|
||||||
artwork_info = await self.mihoyo.get_artwork_info(2, post_id)
|
artwork_info = await self.hyperion.get_artwork_info(2, post_id)
|
||||||
await self.cache.set_str_list(qname, artwork_info.results.image_url_list, 3600)
|
await self.cache.set_str_list(qname, artwork_info.results.image_url_list, 3600)
|
||||||
return artwork_info.results.image_url_list[0]
|
return artwork_info.results.image_url_list[0]
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest import IsolatedAsyncioTestCase
|
from unittest import IsolatedAsyncioTestCase
|
||||||
|
|
||||||
from model.genshinhelper import Mihoyo
|
from model.apihelper import Hyperion
|
||||||
|
|
||||||
|
|
||||||
class TestGame(IsolatedAsyncioTestCase):
|
class TestGame(IsolatedAsyncioTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.mihoyo = Mihoyo()
|
self.hyperion = Hyperion()
|
||||||
|
|
||||||
async def test_get_strategy(self):
|
async def test_get_strategy(self):
|
||||||
test_collection_id_list = [839176, 839179, 839181]
|
test_collection_id_list = [839176, 839179, 839181]
|
||||||
test_result = ["温迪", "胡桃", "雷电将军"]
|
test_result = ["温迪", "胡桃", "雷电将军"]
|
||||||
|
|
||||||
async def get_post_id(_collection_id: int, character_name: str) -> str:
|
async def get_post_id(_collection_id: int, character_name: str) -> str:
|
||||||
post_full_in_collection = await self.mihoyo.get_post_full_in_collection(_collection_id)
|
post_full_in_collection = await self.hyperion.get_post_full_in_collection(_collection_id)
|
||||||
if post_full_in_collection.error:
|
if post_full_in_collection.error:
|
||||||
raise RuntimeError(f"获取收藏信息错误,错误信息为:{post_full_in_collection.message}")
|
raise RuntimeError(f"获取收藏信息错误,错误信息为:{post_full_in_collection.message}")
|
||||||
for post_data in post_full_in_collection.data["posts"]:
|
for post_data in post_full_in_collection.data["posts"]:
|
||||||
@ -30,7 +30,7 @@ class TestGame(IsolatedAsyncioTestCase):
|
|||||||
self.assertEqual(first, second)
|
self.assertEqual(first, second)
|
||||||
|
|
||||||
async def asyncTearDown(self) -> None:
|
async def asyncTearDown(self) -> None:
|
||||||
await self.mihoyo.close()
|
await self.hyperion.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user