临时屏蔽掉输错身份码的请求

This commit is contained in:
John Smith 2023-09-12 22:12:27 +08:00
parent 5dd56210d7
commit 8bfceb4b32

View File

@ -6,6 +6,7 @@ import hmac
import json
import logging
import random
import re
from typing import *
import aiohttp
@ -63,6 +64,10 @@ async def _request_open_live(url, body: dict) -> dict:
cfg = config.get_config()
assert cfg.is_open_live_configured
# 输错身份码的人太多了临时处理屏蔽请求不然要被B站下架了
if url == START_GAME_OPEN_LIVE_URL:
_validate_auth_code(body.get('code', ''))
body_bytes = json.dumps(body).encode('utf-8')
headers = {
'x-bili-accesskeyid': cfg.open_live_access_key_id,
@ -109,6 +114,19 @@ async def _read_response(req_ctx_mgr: AsyncContextManager[aiohttp.ClientResponse
raise TransportError(f'{type(e).__name__}: {e}')
def _validate_auth_code(auth_code):
if re.fullmatch(r'[0-9A-Z]{11,16}', auth_code):
return
logger.warning('Auth code error! auth_code=%s', auth_code)
raise BusinessError({
'code': 7007,
'message': '身份码错误',
'data': {},
'request_id': '0'
})
class _OpenLiveHandlerBase(api.base.ApiHandler):
def prepare(self):
super().prepare()