-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
顺便更新下宵宫池子
- Loading branch information
Showing
6 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from .artifact_eval import * | ||
from hoshino import Service | ||
import requests | ||
|
||
from base64 import b64encode | ||
from io import BytesIO | ||
|
||
sv = Service("原神圣遗物评分") | ||
|
||
|
||
def get_format_sub_item(artifact_attr): | ||
msg = "" | ||
for i in artifact_attr["sub_item"]: | ||
msg += f'{i["name"]:\u3000<6} | {i["value"]}\n' | ||
return msg | ||
|
||
|
||
@sv.on_prefix(("圣遗物评分", "-rate")) | ||
async def artifact_rate(bot, ev): | ||
if '[CQ:image' not in ev["raw_message"]: | ||
await bot.send(ev, "图呢?\n*请将-rate指令与截图一起发送", at_sender=True) | ||
return | ||
if len(ev["message"]) > 1: | ||
await bot.send(ev, "只能上传一张截图哦", at_sender=True) | ||
return | ||
for i in ev["message"]: | ||
if i["type"] == 'image': | ||
image_url = i.data["url"] | ||
break | ||
continue | ||
await bot.send(ev, f"图片收到啦~\n正在识图中...") | ||
image_content = BytesIO(requests.get(image_url).content) | ||
image_b64 = b64encode(image_content.read()).decode() | ||
try: | ||
artifact_attr = await get_artifact_attr(image_b64) | ||
except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout): | ||
await bot.send(ev, f"连接超时", at_sender=True) | ||
return | ||
if 'err' in artifact_attr.keys(): | ||
err_msg = artifact_attr["full"]["message"] | ||
await bot.send(ev, f"发生了点小错误:\n{err_msg}", at_sender=True) | ||
return | ||
await bot.send(ev, f"识图成功!\n正在评分中...", at_sender=True) | ||
rate_result = await rate_artifact(artifact_attr) | ||
if 'err' in rate_result.keys(): | ||
err_msg = rate_result["full"]["message"] | ||
await bot.send(ev, f"发生了点小错误:\n{err_msg}\n*注:将在下版本加入属性修改", at_sender=True) | ||
return | ||
format_result = f'圣遗物评分结果:\n主属性:{artifact_attr["main_item"]["name"]}\n{get_format_sub_item(artifact_attr)}'\ | ||
f'------------------------------\n总分:{rate_result["total_percent"]}\n'\ | ||
f'主词条:{rate_result["main_percent"]}\n副词条:{rate_result["sub_percent"]}\n评分、识图均来自genshin.pub' | ||
await bot.send(ev, format_result, at_sender=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import requests | ||
|
||
import json | ||
|
||
ocr_url = "https://api.genshin.pub/api/v1/app/ocr" | ||
rate_url = "https://api.genshin.pub/api/v1/relic/rate" | ||
head = { | ||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " | ||
"Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67 ", | ||
"Content-Type": "application/json; charset=UTF-8", | ||
"Connection": "close" | ||
} | ||
|
||
|
||
async def get_artifact_attr(b64_str): | ||
upload_json = json.dumps( | ||
{ | ||
"image": b64_str | ||
} | ||
) | ||
try: | ||
req = requests.post(ocr_url, data=upload_json, headers=head, timeout=8) | ||
except requests.exceptions.RequestException as e: | ||
raise e | ||
data = json.loads(req.text) | ||
if req.status_code != 200: | ||
return {"err": "未知错误", "full": data} | ||
return data | ||
|
||
|
||
async def rate_artifact(artifact_attr: dict): | ||
upload_json_str = json.dumps(artifact_attr, ensure_ascii=False).encode('utf-8') | ||
try: | ||
req = requests.post(rate_url, data=upload_json_str, headers=head, timeout=8) | ||
except requests.exceptions.RequestException as e: | ||
raise e | ||
data = json.loads(req.text) | ||
if req.status_code != 200: | ||
return {"err": "未知错误", "full": data} | ||
return data | ||
|
||
|
||
if __name__ == "__main__": | ||
from base64 import b64encode | ||
with open('78.42.png', 'rb') as f: | ||
b64 = b64encode(f.read()).decode() | ||
print(rate_artifact(get_artifact_attr(b64))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.