Skip to content

Commit

Permalink
[#]修复ocr问题,bump version 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
benx1n committed Dec 6, 2023
1 parent c1ef535 commit 8e3da6d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hikari-bot"
version = "1.0.4"
version = "1.0.5"
description = "Nonebot2 HikariBot,支持战舰世界水表查询"
authors = ["benx1n <shirakamikanade@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/hikari_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
is_first_run = True
_nlmt = DailyNumberLimiter(_max)
_flmt = FreqLimiter(3)
__bot_version__ = '1.0.4'
__bot_version__ = '1.0.5'

bot_get_random_pic = on_fullmatch('wws 随机表情包', block=True, priority=5)
bot_update = on_fullmatch('wws 更新Hikari', priority=5, block=True, permission=SUPERUSER)
Expand Down
22 changes: 12 additions & 10 deletions src/plugins/hikari_bot/game/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import httpx
import orjson
from hikari_core.HttpClient_Pool import get_client_yuyuko
from httpx import TimeoutException
from nonebot.log import logger

Expand Down Expand Up @@ -62,16 +63,17 @@ async def upload_OcrResult(result_text, filename):
async def downlod_OcrResult():
try:
global ocr_filename_data
async with httpx.AsyncClient(headers=headers, timeout=10) as client:
resp = await client.get(download_url)
result = orjson.loads(resp.content)
with open(ocr_data_path, 'w', encoding='UTF-8') as f:
if result['code'] == 200 and result['data']:
f.write(orjson.dumps(result['data']).decode())
ocr_filename_data = result['data']
else:
with open(ocr_data_path, 'rb') as f: # noqa: PLW2901
ocr_filename_data = orjson.loads(f.read())
client = await get_client_yuyuko()
resp = await client.get(download_url)
result = orjson.loads(resp.content)
with open(ocr_data_path, 'w', encoding='UTF-8') as f:
if result['code'] == 200 and result['data']:
f.write(orjson.dumps(result['data']).decode())
ocr_filename_data = result['data']
else:
logger.error(result)
with open(ocr_data_path, 'rb') as f: # noqa: PLW2901
ocr_filename_data = orjson.loads(f.read())
return
except Exception:
logger.error('请检查token是否配置正确,如无问题请尝试重启,可能是网络波动或服务器原因')
Expand Down

0 comments on commit 8e3da6d

Please sign in to comment.