mirror of
https://github.com/PaiGramTeam/PamGram.git
synced 2024-11-16 03:55:26 +00:00
♻ ServiceEnum
更名为 RegionEnum
并修改相关 region
判断
This commit is contained in:
parent
1152bd94ad
commit
f735bd6fd7
@ -1,11 +1,11 @@
|
||||
from model.base import ServiceEnum
|
||||
from model.base import RegionEnum
|
||||
from model.baseobject import BaseObject
|
||||
|
||||
|
||||
class User(BaseObject):
|
||||
def __init__(self, user_id: int = 0, yuanshen_game_uid: int = 0, genshin_game_uid: int = 0,
|
||||
default_service: ServiceEnum = ServiceEnum.NULL):
|
||||
region: RegionEnum = RegionEnum.NULL):
|
||||
self.user_id = user_id
|
||||
self.yuanshen_game_uid = yuanshen_game_uid
|
||||
self.genshin_game_uid = genshin_game_uid
|
||||
self.default_service = default_service
|
||||
self.region = region
|
||||
|
@ -41,13 +41,17 @@ class ArtworkImage:
|
||||
self.page = page
|
||||
|
||||
|
||||
class ServiceEnum(Enum):
|
||||
"""
|
||||
该名称来源于米忽悠的安卓BBS包名结尾,考虑到大部分重要的功能确实是在移动端实现了
|
||||
"""
|
||||
class RegionEnum(Enum):
|
||||
"""注册服务器的列举型别
|
||||
|
||||
HYPERION名称来源于米忽悠BBS的安卓端包名结尾
|
||||
|
||||
查了一下确实有点意思 考虑到大部分重要的功能确实是在移动端实现了
|
||||
|
||||
干脆用这个还好听 )"""
|
||||
NULL = None
|
||||
HYPERION = 1 # 米忽悠国服
|
||||
HOYOLAB = 2 # 米忽悠国际服
|
||||
HYPERION = 1 # 米忽悠国服 hyperion
|
||||
HOYOLAB = 2 # 米忽悠国际服 hoyolab
|
||||
|
||||
|
||||
class GameItem(BaseObject):
|
||||
|
@ -1,6 +1,6 @@
|
||||
import hashlib
|
||||
import os
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
import aiofiles
|
||||
import genshin
|
||||
@ -11,7 +11,7 @@ from httpx import UnsupportedProtocol
|
||||
from app.cookies.service import CookiesService
|
||||
from app.user import UserService
|
||||
from logger import Log
|
||||
from model.base import ServiceEnum
|
||||
from model.base import RegionEnum
|
||||
|
||||
USER_AGENT: str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
||||
"Chrome/90.0.4430.72 Safari/537.36"
|
||||
@ -21,14 +21,14 @@ cache_dir = os.path.join(current_dir, "cache")
|
||||
if not os.path.exists(cache_dir):
|
||||
os.mkdir(cache_dir)
|
||||
|
||||
SERVICE_MAP = {
|
||||
"1": ServiceEnum.HYPERION,
|
||||
"2": ServiceEnum.HYPERION,
|
||||
"5": ServiceEnum.HYPERION,
|
||||
"6": ServiceEnum.HOYOLAB,
|
||||
"7": ServiceEnum.HOYOLAB,
|
||||
"8": ServiceEnum.HOYOLAB,
|
||||
"9": ServiceEnum.HOYOLAB,
|
||||
REGION_MAP = {
|
||||
"1": RegionEnum.HYPERION,
|
||||
"2": RegionEnum.HYPERION,
|
||||
"5": RegionEnum.HYPERION,
|
||||
"6": RegionEnum.HOYOLAB,
|
||||
"7": RegionEnum.HOYOLAB,
|
||||
"8": RegionEnum.HOYOLAB,
|
||||
"9": RegionEnum.HOYOLAB,
|
||||
}
|
||||
|
||||
|
||||
@ -61,24 +61,31 @@ async def url_to_file(url: str, prefix: str = "file://") -> str:
|
||||
|
||||
|
||||
async def get_genshin_client(user_id: int, user_service: UserService, cookies_service: CookiesService,
|
||||
game_service: Optional[ServiceEnum] = None) -> Client:
|
||||
region: RegionEnum = RegionEnum.NULL) -> Client:
|
||||
user = await user_service.get_user_by_id(user_id)
|
||||
cookies = await cookies_service.read_cookies(user_id, game_service)
|
||||
if game_service is None:
|
||||
game_service = user.default_service
|
||||
if game_service == ServiceEnum.HYPERION:
|
||||
cookies = await cookies_service.get_cookies(user_id, region)
|
||||
if region is None:
|
||||
region = user.region
|
||||
if region == RegionEnum.HYPERION:
|
||||
uid = user.yuanshen_game_uid
|
||||
client = genshin.Client(cookies=cookies, game=types.Game.GENSHIN, region=types.Region.CHINESE, uid=uid)
|
||||
else:
|
||||
elif region == RegionEnum.HOYOLAB:
|
||||
uid = user.genshin_game_uid
|
||||
client = genshin.Client(cookies=cookies,
|
||||
game=types.Game.GENSHIN, region=types.Region.OVERSEAS, lang="zh-cn", uid=uid)
|
||||
else:
|
||||
raise TypeError(f"region is not RegionEnum.NULL")
|
||||
return client
|
||||
|
||||
|
||||
def get_server(uid: int) -> ServiceEnum:
|
||||
server = SERVICE_MAP.get(str(uid)[0])
|
||||
if server:
|
||||
return server
|
||||
def region_server(uid: Union[int, str]) -> RegionEnum:
|
||||
if isinstance(uid, int):
|
||||
region = REGION_MAP.get(str(uid)[0])
|
||||
elif isinstance(uid, str):
|
||||
region = REGION_MAP.get(str(uid)[0])
|
||||
else:
|
||||
raise TypeError(f"UID {uid} isn't associated with any server")
|
||||
raise TypeError(f"UID variable type error")
|
||||
if region:
|
||||
return region
|
||||
else:
|
||||
raise TypeError(f"UID {uid} isn't associated with any region")
|
||||
|
Loading…
Reference in New Issue
Block a user