Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
更详细的详细查询
Browse files Browse the repository at this point in the history
  • Loading branch information
CYDXDianXian committed Feb 15, 2022
1 parent 8f012ee commit c0eb4d9
Showing 1 changed file with 69 additions and 30 deletions.
99 changes: 69 additions & 30 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from json import load, dump
from tkinter.messagebox import NO
from nonebot import get_bot, on_command
from hoshino import priv
from hoshino.typing import NoticeSession
Expand All @@ -10,10 +9,12 @@
from traceback import format_exc
from .safeservice import SafeService
from .playerpref import decryptxml
from ..priconne import chara
import time

sv_help = '''
注意:下方uid格式样例:[3cx(原uid)]
(其中3为服务器编号,支持1或2或3或4)
[竞技场绑定 uid] 绑定竞技场排名变动推送,默认双场均启用,仅排名降低时推送
[竞技场查询 (uid)] 查询竞技场简要信息
[停止竞技场订阅] 停止战斗竞技场排名变动推送
Expand All @@ -22,7 +23,7 @@
[启用公主竞技场订阅] 启用公主竞技场排名变动推送
[删除竞技场订阅] 删除竞技场排名变动推送绑定
[竞技场订阅状态] 查看排名变动推送绑定状态
[详细查询 (uid)] 查询账号详细信息
[详细查询 (uid)] 查询账号详细状态
[查询群数] 查询bot所在群的数目
[查询竞技场订阅数] 查询绑定账号的总数量
[清空竞技场订阅] 清空所有绑定的账号(仅限主人)
Expand Down Expand Up @@ -50,6 +51,10 @@ async def group_num(bot, ev):

cache = {}
client = None
client_1cx = None
client_2cx = None
client_3cx = None
client_4cx = None
lck = Lock()

if exists(config):
Expand All @@ -63,13 +68,28 @@ async def group_num(bot, ev):
with open(join(curpath, 'account.json')) as fp:
pinfo = load(fp)

acinfo = decryptxml(join(curpath, 'tw.sonet.princessconnect.v2.playerprefs.xml'))

client = pcrclient(acinfo['UDID'], acinfo['SHORT_UDID'], acinfo['VIEWER_ID'], acinfo['TW_SERVER_ID'], pinfo['proxy'])
if exists(join(curpath, '1cx_tw.sonet.princessconnect.v2.playerprefs.xml')):
acinfo_1cx = decryptxml(join(curpath, '1cx_tw.sonet.princessconnect.v2.playerprefs.xml'))
client_1cx = pcrclient(acinfo_1cx['UDID'], acinfo_1cx['SHORT_UDID'], acinfo_1cx['VIEWER_ID'], acinfo_1cx['TW_SERVER_ID'], pinfo['proxy'])
if exists(join(curpath, '2cx_tw.sonet.princessconnect.v2.playerprefs.xml')):
acinfo_2cx = decryptxml(join(curpath, '2cx_tw.sonet.princessconnect.v2.playerprefs.xml'))
client_2cx = pcrclient(acinfo_2cx['UDID'], acinfo_2cx['SHORT_UDID'], acinfo_2cx['VIEWER_ID'], acinfo_2cx['TW_SERVER_ID'], pinfo['proxy'])
if exists(join(curpath, '3cx_tw.sonet.princessconnect.v2.playerprefs.xml')):
acinfo_3cx = decryptxml(join(curpath, '3cx_tw.sonet.princessconnect.v2.playerprefs.xml'))
client_3cx = pcrclient(acinfo_3cx['UDID'], acinfo_3cx['SHORT_UDID'], acinfo_3cx['VIEWER_ID'], acinfo_3cx['TW_SERVER_ID'], pinfo['proxy'])
if exists(join(curpath, '4cx_tw.sonet.princessconnect.v2.playerprefs.xml')):
acinfo_4cx = decryptxml(join(curpath, '4cx_tw.sonet.princessconnect.v2.playerprefs.xml'))
client_4cx = pcrclient(acinfo_4cx['UDID'], acinfo_4cx['SHORT_UDID'], acinfo_4cx['VIEWER_ID'], acinfo_4cx['TW_SERVER_ID'], pinfo['proxy'])

qlck = Lock()

async def query(id: str):
async def query(cx:str, id: str):
if cx == '1': client = client_1cx
elif cx == '2': client = client_2cx
elif cx == '3': client = client_3cx
else: client = client_4cx
if client == None:
return 'lack shareprefs'
async with qlck:
while client.shouldLogin:
await client.login()
Expand Down Expand Up @@ -103,16 +123,21 @@ async def pcrjjc_del(bot, ev):
save_binds()
await bot.send(ev, f'已清空全部【{num}】个已订阅账号!')

@sv.on_rex(r'^竞技场绑定 ?(\d{9})$')
@sv.on_rex(r'^竞技场绑定 ?(\d{1})cx(\d{9})$')
async def on_arena_bind(bot, ev):
global binds, lck

if ev['match'].group(1) != '1' and ev['match'].group(1) != '2' and \
ev['match'].group(1) != '3' and ev['match'].group(1) != '4':
await bot.send(ev, '服务器选择错误!支持的服务器有1/2/3/4')
return
async with lck:
uid = str(ev['user_id'])
last = binds[uid] if uid in binds else None

binds[uid] = {
'id': ev['match'].group(1),
'cx': ev['match'].group(1),
'id': ev['match'].group(2),
'uid': uid,
'gid': str(ev['group_id']),
'arena_on': last is None or last['arena_on'],
Expand All @@ -122,54 +147,63 @@ async def on_arena_bind(bot, ev):

await bot.finish(ev, '竞技场绑定成功', at_sender=True)

@sv.on_rex(r'^竞技场查询 ?(\d{9})?$')
@sv.on_rex(r'^竞技场查询 ?(\d{1})?(cx)?(\d{9})?$')
async def on_query_arena(bot, ev):
global binds, lck

robj = ev['match']
id = robj.group(1)
cx = robj.group(1)
id = robj.group(3)

async with lck:
if id == None:
if id == None and cx == None:
uid = str(ev['user_id'])
if not uid in binds:
await bot.finish(ev, '您还未绑定竞技场', at_sender=True)
return
else:
id = binds[uid]['id']
cx = binds[uid]['cx']
try:
res = await query(id)
res = await query(cx, id)

if res == 'lack shareprefs':
await bot.finish(ev, f'查询出错,缺少该服的配置文件', at_sender=True)
return
last_login_time = int (res['user_info']['last_login_time'])
last_login_date = time.localtime(last_login_time)
last_login_str = time.strftime('%Y-%m-%d %H:%M:%S',last_login_date)

await bot.finish(ev,
f'''昵称:{res['user_info']["user_name"]}
jjc排名:{res['user_info']["arena_rank"]}
pjjc排名:{res['user_info']["grand_arena_rank"]}
最后登录:{last_login_str}
''', at_sender=False)
jjc:{res['user_info']["arena_rank"]}
pjjc:{res['user_info']["grand_arena_rank"]}
最后登录:{last_login_str}''', at_sender=False)
except ApiException as e:
await bot.finish(ev, f'查询出错,{e}', at_sender=True)

@sv.on_rex(r'^详细查询 ?(\d{9})?$')
@sv.on_rex(r'^详细查询 ?(\d{1})?(cx)?(\d{9})?$')
async def on_query_arena_all(bot, ev):
global binds, lck

robj = ev['match']
id = robj.group(1)
cx = robj.group(1)
id = robj.group(3)

async with lck:
if id == None:
if id == None and cx == None:
uid = str(ev['user_id'])
if not uid in binds:
await bot.finish(ev, '您还未绑定竞技场', at_sender=True)
return
else:
id = binds[uid]['id']
cx = binds[uid]['cx']
try:
res = await query(id)
res = await query(cx, id)
if res == 'lack shareprefs':
await bot.finish(ev, f'查询出错,缺少该服的配置文件', at_sender=True)
return
arena_time = int (res['user_info']['arena_time'])
arena_date = time.localtime(arena_time)
arena_str = time.strftime('%Y-%m-%d',arena_date)
Expand All @@ -181,7 +215,7 @@ async def on_query_arena_all(bot, ev):
last_login_time = int (res['user_info']['last_login_time'])
last_login_date = time.localtime(last_login_time)
last_login_str = time.strftime('%Y-%m-%d %H:%M:%S',last_login_date)

# 获取支援角色信息,若玩家未设置则留空
try:
id_favorite = int(str(res['favorite_unit']['id'])[0:4]) # 截取第1位到第4位的字符
Expand Down Expand Up @@ -268,10 +302,11 @@ async def change_arena_sub(bot, ev):
save_binds()
await bot.finish(ev, f'{ev["match"].group(0)}成功', at_sender=True)

# @on_command('/pcrval') # 台服建议注释掉该命令,以防止与b服的验证码输入产生冲突,导致验证码输入无响应。
# @on_command('/pcrval')
async def validate(session):
global binds, lck, validate
if session.ctx['user_id'] == acinfo['admin']:
if session.ctx['user_id'] == acinfo_1cx['admin'] or session.ctx['user_id'] == acinfo_2cx['admin'] \
or session.ctx['user_id'] == acinfo_3cx['admin'] or session.ctx['user_id'] == acinfo_4cx['admin']:
validate = session.ctx['message'].extract_plain_text().strip()[8:]
captcha_lck.release()

Expand Down Expand Up @@ -317,7 +352,7 @@ async def send_arena_sub_status(bot,ev):
公主竞技场订阅:{'开启' if info['grand_arena_on'] else '关闭'}''',at_sender=True)


@sv.scheduled_job('interval', minutes=3) # minutes是刷新频率,可按自身服务器性能输入其他数值,可支持整数、小数
@sv.scheduled_job('interval', minutes=2)
async def on_arena_schedule():
global cache, binds, lck
bot = get_bot()
Expand All @@ -331,8 +366,12 @@ async def on_arena_schedule():
for user in bind_cache:
info = bind_cache[user]
try:
sv.logger.info(f'querying {info["id"]} for {info["uid"]}')
res = await query(info['id'])
sv.logger.info(f'querying server[ {info["cx"]} ]: {info["id"]} for {info["uid"]}')
res = await query(info["cx"], info['id'])
if res == 'lack shareprefs':
sv.logger.info(f'由于缺少该服配置文件,已停止')
# 直接返回吧
return
res = (res['user_info']['arena_rank'], res['user_info']['grand_arena_rank'])

if user not in cache:
Expand All @@ -354,15 +393,15 @@ async def on_arena_schedule():
message = f'[CQ:at,qq={info["uid"]}]pjjc:{last[1]}->{res[1]}{res[1]-last[1]}'
)
except ApiException as e:
sv.logger.info(f'{info["id"]}的检查出错\n{format_exc()}')
sv.logger.info(f'对台服{info["cx"]}服的{info["id"]}的检查出错\n{format_exc()}')
if e.code == 6:

async with lck:
binds.pop(user)
save_binds()
sv.logger.info(f'已经自动删除错误的uid={info["id"]}')
except:
sv.logger.info(f'{info["id"]}的检查出错\n{format_exc()}')
sv.logger.info(f'对台服{info["cx"]}服的{info["id"]}的检查出错\n{format_exc()}')

@sv.on_notice('group_decrease.leave')
async def leave_notice(session: NoticeSession):
Expand All @@ -372,4 +411,4 @@ async def leave_notice(session: NoticeSession):
async with lck:
if uid in binds:
binds.pop(uid)
save_binds()
save_binds()

0 comments on commit c0eb4d9

Please sign in to comment.