Skip to content

Commit

Permalink
<jx3>[feat]UID
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkar-Suki committed Aug 4, 2024
1 parent f116aa7 commit 94fd832
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ src/plugins/book/
src/tools/order.json
src/plugins/firework/
src/assets/music/
src/plugins/jx3/bind/uid.py

affections.json

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/jx3/achievement/v1_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def achi_v2(server: str = None, name: str = None, achievement: str = None,
server = server_mapping(server, group_id)
if not server:
return [PROMPT.ServerNotExist]
personal_data_request = getPlayerLocalData(roleName=name, serverName=server)
personal_data_request = await getPlayerLocalData(roleName=name, serverName=server)
personal_data = personal_data_request.format_jx3api()
if personal_data["code"] != 200:
guid = ""
Expand Down Expand Up @@ -120,7 +120,7 @@ async def zone_achi(server: str = None, name: str = None, zone: str = None, mode
mode = mode_mapping(mode)
if zone is False or mode is False:
return ["唔……难度或名称输入有误。"]
personal_data_request = getPlayerLocalData(roleName=name, serverName=server)
personal_data_request = await getPlayerLocalData(roleName=name, serverName=server)
personal_data = personal_data_request.format_jx3api()
if personal_data["code"] != 200:
guid = ""
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/jx3/affection/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def checkUinStatus(uin: int):
return False

async def getSchool(name: str, server: str):
data = getPlayerLocalData(roleName=name, serverName=server)
data = await getPlayerLocalData(roleName=name, serverName=server)
data = data.format_jx3api()
if data["code"] != 200:
return False
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/jx3/attributes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def addritube_(server: str = None, name: str = None, group_id: str = None)

async def get_uid(server, id):
token = Config.jx3.api.token
data = getPlayerLocalData(roleName=id, serverName=server)
data = await getPlayerLocalData(roleName=id, serverName=server)
data = data.format_jx3api()
if data["code"] != 200:
return False
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/jx3/attributes/v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</tr>"""

async def get_basic_info(server: str, name: str):
data = getPlayerLocalData(roleName=name, serverName=server)
data = await getPlayerLocalData(roleName=name, serverName=server)
data = data.format_jx3api()
if data["code"] != 200:
return 404
Expand Down
16 changes: 14 additions & 2 deletions src/plugins/jx3/bind/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
from src.tools.basic.data_server import server_mapping, Zone_mapping
from src.tools.data import group_db, RoleData

try:
from .uid import get_uid
# 如果有能够获取UID的方法,请在这里提供
except:
pass

import json

ticket = Config.jx3.api.ticket
Expand Down Expand Up @@ -70,10 +76,16 @@ def format_jx3api(self):
if self.__dict__ == {}:
return {"code": 404, "data": None}
return {"code": 200, "data": self.__dict__}

from src.tools.utils.request import get_api

def getPlayerLocalData(roleName: str = "", roleId: str = "", serverName: str = None):
async def getPlayerLocalData(roleName: str = "", roleId: str = "", serverName: str = None):
player_data = group_db.where_one(RoleData(), "roleName = ? OR roleId = ? AND serverName = ?", roleName, roleId, serverName, default=None)
if player_data is None:
return Player()
uid = await get_uid(roleName=roleName, serverName=serverName)
if uid == None:
return Player()
await getRoleData(uid, serverName)
return await getPlayerLocalData(roleName=roleName, roleId=uid)
else:
return Player(**player_data.dump())
4 changes: 2 additions & 2 deletions src/plugins/jx3/detail/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def get_tuilan_data(url: str, params: Union[dict, None] = None):


async def get_guid(server: str, name: str):
data = getPlayerLocalData(roleName=name, serverName=server)
data = await getPlayerLocalData(roleName=name, serverName=server)
data = data.format_jx3api()
if data["code"] != 200:
return False
Expand Down Expand Up @@ -185,7 +185,7 @@ async def generate_zd_image(server: str, id: str):
"""

async def get_personal_guid(server: str, id: str):
data = getPlayerLocalData(roleName=name, serverName=server)
data = await getPlayerLocalData(roleName=name, serverName=server)
data = data.format_jx3api()
if data["code"] != 200:
return False
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/jx3/dungeon/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ async def generater(map, mode, boss):

async def zone_v2(server, id):
server = server_mapping(server)
data = getPlayerLocalData(roleName=id, serverName=server)
data = await getPlayerLocalData(roleName=id, serverName=server)
details_data = data.format_jx3api()
if details_data["code"] != 200:
guid = ""
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/jx3/serendipity/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from .without_jx3api import *

import os

token = Config.jx3.api.token
ticket = Config.jx3.api.ticket
bot_name = Config.bot_basic.bot_name_argument
Expand All @@ -37,7 +39,7 @@ async def getImage_v2(server: str, name: str, group_id: str, type: bool):
server = server_mapping(server, group_id)
if not server:
return [PROMPT.ServerNotExist]
role_data = getPlayerLocalData(roleName=name, serverName=server)
role_data = await getPlayerLocalData(roleName=name, serverName=server)
if role_data.format_jx3api()["code"] != 200:
return [PROMPT.PlayerNotExist]
serendipity_data = await Serendipity.integration(server, name)
Expand All @@ -54,6 +56,8 @@ async def getImage_v2(server: str, name: str, group_id: str, type: bool):
serendity_name = i["name"]
flag = ASSETS + "/serendipity/vector/peerless.png" if i["level"] == 2 else ""
icon = ASSETS + "/serendipity/serendipity/" + serendity_name + ".png"
if not os.path.exists(icon):
continue
if i["time"] != 0:
timeGet = convert_time(i["time"], format="%Y-%m-%d %H:%M:%S")
timeGet_int = int(i["time"])
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/jx3/serendipity/without_jx3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_serendipity_level(self, serendipity_name: str) -> int:
return serendipity_level

async def get_tuilan_data(self, server: str, name: str):
role: Player = getPlayerLocalData(roleName=name, serverName=server)
role: Player = await getPlayerLocalData(roleName=name, serverName=server)
data = role.format_jx3api()
if data["code"] != 200:
return False
Expand Down Expand Up @@ -83,7 +83,11 @@ async def get_my_data(self, server: str, name: str):
final_url = f"https://pull.j3cx.com/api/serendipity?server={server}&role={name}&pageSize=50"
data = await get_api(final_url)
serendipities = []
for serendipity in data["data"]["data"]:
data = data["data"]["data"]
if data == None:
self.my = serendipities
return
for serendipity in data:
serendipity_name = serendipity["serendipity"]
serendipity_level = self.get_serendipity_level(serendipity_name)
new = {
Expand Down
10 changes: 5 additions & 5 deletions src/tools/utils/request.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import httpx

async def get_url(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
resp = await client.get(url, **kwargs)
result = resp.text
return result

async def get_content(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
resp = await client.get(url, **kwargs)
result = resp.content
return result

async def get_status(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
resp = await client.get(url, **kwargs)
result = resp.status_code
return result

async def get_api(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
resp = await client.get(url, **kwargs)
result = resp.json()
return result

async def post_url(url, **kwargs):
async with httpx.AsyncClient(follow_redirects=True) as client:
async with httpx.AsyncClient(follow_redirects=True, verify=False) as client:
resp = await client.post(url, **kwargs)
result = resp.text
return result

0 comments on commit 94fd832

Please sign in to comment.