pepperbot/apps/riic_report_analysis.py

104 lines
3.8 KiB
Python

from pepperbot.core.message.chain import MessageChain, Image, Text, At
from rapidocr_onnxruntime import RapidOCR
import os
import asyncio
import functools
import re
from typing import Dict
rapid_ocr = None
if not rapid_ocr:
rapid_ocr = RapidOCR("rapid_ocr.yml")
class RIICReportAnalysis:
async def group_message(self, chain: MessageChain, raw_event: Dict):
if len(chain) != 1 or len(chain.images) != 1:
return
img_seg: Image = chain[0]
img_path = await img_seg.download()
loop = asyncio.get_running_loop()
result, elapse = await loop.run_in_executor(
None, functools.partial(rapid_ocr, img_path)
)
os.remove(img_path)
if not result or not "副手简报" in [i[1] for i in result]:
return
card = raw_event["sender"]["card"]
err_msg = "请修改群昵称(群名片),标注基建布局。若使用2电站布局,请额外标注贸易站等级。\n"
err_msg += "如:\n"
err_msg += "EE0000 252 11贸\n"
err_msg += "教捐 252(33贸易站)\n"
err_msg += "千梵 243烟火 单推狮蝎\n"
err_msg += "琉璃 243-153"
if not card:
await chain.onebot_reply(Text(err_msg))
return
elif "153" in card or "243" in card:
await chain.onebot_reply(Text("3电站,龙舌兰"))
elif "252" in card:
if m := re.search(r"([1-3][1-3])贸", card):
await chain.onebot_reply(Text(f"252,贸易站等级是{m.group(1)}"))
else:
await chain.onebot_reply(Text(err_msg))
return
elif "342" in card:
if m := re.search(r"([1-3][1-3][1-3])贸", card):
await chain.onebot_reply(Text(f"342,贸易站等级是{m.group(1)}"))
else:
await chain.onebot_reply(Text(err_msg))
return
else:
await chain.onebot_reply(Text(err_msg))
return
lmb_height = 0
lmb_list = []
date_list = []
exp_list = []
gold_list = []
for i in result:
if i[1] == "龙门币":
lmb_height = i[0][0][1]
break
for i in result:
if m := re.search(r"([0-9]+\.[0-9]+)", i[1]):
if float(i[2]) < 0.6:
continue
date_list.append([int(i[0][0][0]), m.group(1)])
continue
if m := re.search(r"EXP([0-9]+)的作战记录", i[1]):
exp_list.append([int(i[0][0][0]), m.group(1)])
continue
if m := re.search(r"([0-9]+)的贵金属", i[1]):
gold_list.append([int(i[0][0][0]), m.group(1)])
continue
if lmb_height - 20 < i[0][0][1] < lmb_height + 20:
if m := re.search(r"([0-9]+)", i[1]):
lmb_list.append([int(i[0][0][0]), m.group(1)])
lmb_list.sort(key=lambda x: x[0])
gold_list.sort(key=lambda x: x[0])
exp_list.sort(key=lambda x: x[0])
output = ""
try:
for i in range(len(date_list)):
output += f"{date_list[i][1]}\n"
output += f"💵 {lmb_list[2 * i][1]}订单({lmb_list[2 * i + 1][1]})\n"
output += f"🧈 {gold_list[i][1]}赤金\n"
output += f"📼 {exp_list[i][1]}经验\n\n"
await chain.onebot_reply(Text(output.strip()))
except:
err_msg = "出错啦!\n"
err_msg += f"date_list = {date_list}\n"
err_msg += f"lmb_list = {lmb_list}\n"
err_msg += f"gold_list = {gold_list}\n"
err_msg += f"exp_list = {exp_list}"
await chain.onebot_reply(Text(err_msg), At("1040110848"))