fix抽卡记录导出

This commit is contained in:
CMHopeSunshine 2022-05-04 20:39:12 +08:00
parent 60a665362a
commit da334ddda2
4 changed files with 14 additions and 15 deletions

View File

@ -53,16 +53,19 @@ async def ckjl(bot: Bot, event: Union[MessageEvent, GroupMessageEvent], msg: Mes
@gacha_log_update.handle() @gacha_log_update.handle()
async def update_ckjl(event: MessageEvent, msg: Message = CommandArg()): async def update_ckjl(event: MessageEvent, msg: Message = CommandArg()):
url = None
if msg:
msg = str(msg)
match = re.search(r'(https://webstatic.mihoyo.com/.*#/log)', msg)
if match:
url = match.group(1)
msg = msg.replace(url, '')
uid, msg, user_id, use_cache = await get_uid_in_msg(event, msg) uid, msg, user_id, use_cache = await get_uid_in_msg(event, msg)
if not uid: if not uid:
await gacha_log_update.finish('请把uid给派蒙哦比如获取抽卡记录100000001 链接', at_sender=True) await gacha_log_update.finish('请把uid给派蒙哦比如获取抽卡记录100000001 链接', at_sender=True)
if msg: if msg and not url:
match = re.search(r'(https://webstatic.mihoyo.com/.*#/log)', msg)
if match:
url = str(match.group(1))
else:
await gacha_log_update.finish('你这个抽卡链接不对哦应该是以https://开头、#/log结尾的', at_sender=True) await gacha_log_update.finish('你这个抽卡链接不对哦应该是以https://开头、#/log结尾的', at_sender=True)
else: if not msg and not url:
with open(os.path.join(data_path, 'user_gacha_log.json'), 'r', encoding="utf-8") as f: with open(os.path.join(data_path, 'user_gacha_log.json'), 'r', encoding="utf-8") as f:
user_data = json.load(f) user_data = json.load(f)
if user_id in user_data and uid in user_data[user_id]: if user_id in user_data and uid in user_data[user_id]:

View File

@ -32,14 +32,12 @@ async def checkApi(url):
try: try:
async with ClientSession() as session: async with ClientSession() as session:
r = await session.get(url) r = await session.get(url)
s = (await r.read()).decode("utf-8") j = await r.json()
j = json.loads(s)
except Exception as e: except Exception as e:
# print("API请求解析出错\n", traceback.format_exc())
return f'API请求解析出错{e}' return f'API请求解析出错{e}'
if not j["data"]: if not j["data"]:
if j["message"] == "authkey valid error": if j["message"] == "authkey error":
return "authkey错误请重新获取链接给派蒙" return "authkey错误请重新获取链接给派蒙"
elif j["message"] == "authkey timeout": elif j["message"] == "authkey timeout":
return "authkey已过期请重新获取链接给派蒙" return "authkey已过期请重新获取链接给派蒙"

View File

@ -18,8 +18,7 @@ async def getGachaLogs(url, gachaTypeId):
api = getApi(url, gachaTypeId, size, page, end_id) api = getApi(url, gachaTypeId, size, page, end_id)
async with ClientSession() as session: async with ClientSession() as session:
r = await session.get(api) r = await session.get(api)
s = (await r.read()).decode("utf-8") j = await r.json()
j = json.loads(s)
gacha = j["data"]["list"] gacha = j["data"]["list"]
if not len(gacha): if not len(gacha):
break break
@ -53,7 +52,6 @@ def mergeDataFunc(localData, gachaData):
if flaglist[i] == 0: if flaglist[i] == 0:
gachaGet = bannerGet[i] gachaGet = bannerGet[i]
tempData.insert(0, gachaGet) tempData.insert(0, gachaGet)
# print("追加", len(tempData), "条记录", flush=True)
for i in tempData: for i in tempData:
localData["gachaLog"][banner].insert(0, i) localData["gachaLog"][banner].insert(0, i)

View File

@ -39,7 +39,7 @@ chat_lmt = FreqLimiter2(60)
def create_matcher(chat_word: str, pattern: str, cooldown: int, pro: float, responses): def create_matcher(chat_word: str, pattern: str, cooldown: int, pro: float, responses):
hammer = on_regex(pattern, priority=14, temp=True) hammer = on_regex(pattern, priority=10)
@hammer.handle() @hammer.handle()
async def handler(event: GroupMessageEvent): async def handler(event: GroupMessageEvent):