支持url和base64的导入抽卡记录 (#487)

This commit is contained in:
wuchangjun233 2023-04-05 19:49:08 +08:00 committed by GitHub
parent a22a3915ce
commit 1bc7bd9609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -22,7 +22,10 @@ async def send_import_gacha_info(bot: Bot, ev: Event):
if uid is None:
return await bot.send(UID_HINT)
if ev.file:
return await bot.send(await import_gachalogs(ev.file, uid))
await bot.send('正在尝试导入抽卡记录中,请耐心等待……')
return await bot.send(
await import_gachalogs(ev.file, ev.file_type, uid)
)
else:
return await bot.send('导入抽卡记录异常...')

View File

@ -1,4 +1,5 @@
import json
import base64
from datetime import datetime
from httpx import get
@ -15,8 +16,12 @@ INT_TO_TYPE = {
}
async def import_gachalogs(history_url: str, uid: str) -> str:
history_data: dict = json.loads(get(history_url).text)
async def import_gachalogs(history_url: str, type: str, uid: str) -> str:
if type == 'url':
history_data: dict = json.loads(get(history_url).text)
else:
data_bytes = base64.b64decode(history_url)
history_data = json.loads(data_bytes.decode('gbk'))
if 'info' in history_data and 'uid' in history_data['info']:
data_uid = history_data['info']['uid']
if data_uid != uid: