Skip to content

Commit

Permalink
加入圣遗物评分
Browse files Browse the repository at this point in the history
顺便更新下宵宫池子
  • Loading branch information
1shin-7 committed Aug 14, 2021
1 parent 928e983 commit 9e5eabf
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@

## 更新记录

### 2021-8-14

* 加入 [圣遗物评分](https://github.com/H-K-Y/Genshin_Impact_bot/issues/31)
* 更新卡池

### 2021-7-27

* 对资源查询的代码逻辑进行调整,防止资源查询时出现killed
* 加入新命令 更新原神地图 用于爬取大地图文件

### 2021-6-2
* 加入抽签功能
* 更新README.md
* 部分代码依照PEP标准进行格式化


Expand Down
52 changes: 52 additions & 0 deletions artifact_rate/__init__.py
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)
47 changes: 47 additions & 0 deletions artifact_rate/artifact_eval.py
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)))
8 changes: 4 additions & 4 deletions gacha/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"注释": "4星和5星常驻角色武器是不包括UP的 需要4星或5星所有物品角色随机时程序会自己拼接列表去除重复",
"5星up角色": ["神里绫华"],
"4星up角色": ["凝光","重云","烟绯"],
"5星up武器": ["雾切之回光","天空之脊"],
"4星up武器": ["西风剑","祭礼大剑","西风长枪","西风秘典","绝弦"],
"5星up角色": ["宵宫"],
"4星up角色": ["早柚","辛焱","迪奥娜"],
"5星up武器": ["飞雷之弦振","天空之刃"],
"4星up武器": ["祭礼剑","雨裁","匣里灭辰","祭礼残章","西风猎弓"],
"5星常驻角色": ["莫娜","七七","迪卢克","","刻晴"],
"4星常驻角色": ["雷泽","菲谢尔","砂糖","诺艾尔","北斗","迪奥娜","辛焱","芭芭拉","凝光","班尼特","行秋","香菱","重云","罗莎莉亚","烟绯"],
"4星白给角色": ["安柏","凯亚","丽莎"],
Expand Down
Binary file added gacha/icon/角色图鉴/宵宫.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gacha/icon/角色图鉴/早柚.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9e5eabf

Please sign in to comment.