From d621b38ccaf7797f94197975e882f5362f0d7592 Mon Sep 17 00:00:00 2001 From: NekoRabi <1215791340@qq.com> Date: Fri, 16 Jun 2023 18:23:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=9B=80=E9=AD=82=E6=9C=88?= =?UTF-8?q?=E6=8A=A5=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=9A=E5=A4=9A=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E4=B8=A4=E5=BC=A0=E5=9B=BE=EF=BC=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?doc.md=20=E4=B8=BA=E5=A4=A9=E5=87=A4=E6=9C=88=E6=8A=A5=E7=9A=84?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=81=9A=E4=BC=8F=E7=AC=94(=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E5=AE=9A=E7=9C=9F=E4=BC=9A=E6=9B=B4=E6=96=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/MajSoulInfo/doc.md | 27 ++++++++++++- plugin/MajSoulInfo/file_init.py | 5 +-- plugin/MajSoulInfo/majsoulinfo.py | 60 +++++++++++++++++++++++++--- plugin/TenHouPlugin/ptcalculation.py | 1 + 4 files changed, 83 insertions(+), 10 deletions(-) diff --git a/plugin/MajSoulInfo/doc.md b/plugin/MajSoulInfo/doc.md index dd4b78d..fd581ed 100644 --- a/plugin/MajSoulInfo/doc.md +++ b/plugin/MajSoulInfo/doc.md @@ -18,6 +18,8 @@ link_updatetime: "2:33" # 节点更新时间,采用的是根据 “:" 进行 silence_CLI: false # 启用时减少控制台的信息输出 broadcast: "image" # 广播类型,发送图片还是文本,或者是混合 #可选参数 'image','img','str','txt','text','mix','mixed' +echarts: true # qhyb的同时是否输出额外信息(影响性能 +ignore_history: true # 启动时机器人时不会自动播报以前的对局(忽略已经发送的对局) # 分别在在某群禁用 相关功能 disptgroup: - 0 @@ -196,6 +198,29 @@ qhyb / 雀魂月报 [玩家名] ({3/4}) ([YYYY-m]) 当只有玩家名作为参数时,可以不需要空格,如 `qhybxyshu` +--- +***2023.6.16更新*** + +现在还会输出玩家月间PT变化图,该功能会阻塞进程,对性能有需要可以通过设置config `echarts=false` 来关闭该功能 + +此外,为减少不必要的性能压力,对战时小于10同样不会生成该图 + +美观起见,对战数大于40时会隐藏数值,仅显示最值 + +未知原因,每次查询都会在控制台发送 'Devtools xxxx' 的消息,不清楚如何关闭 + +--- + +``` +qhbind XXX +``` + +将QQ号与雀魂账号绑定 + +``` +qhmXX 在绑定自己后,可以省略对象,快捷查询自己的数据 +``` +例如: qhmpt 3 输出自己3麻的PT ``` qhdisable/enable qhpt/qhsl/qhyb ...... @@ -251,4 +276,4 @@ qhfreshlink *私聊指令* 自动选择当前最好的牌谱屋链路 ---- \ No newline at end of file +--- diff --git a/plugin/MajSoulInfo/file_init.py b/plugin/MajSoulInfo/file_init.py index d723ed2..18dec64 100644 --- a/plugin/MajSoulInfo/file_init.py +++ b/plugin/MajSoulInfo/file_init.py @@ -15,9 +15,8 @@ print('未检测到雀魂配置文件,生成初始文件中...') cfg = dict(qhpt=True, qhinfo=True, qhsl=True, qhyb=True, qhpaipu=True, broadcast='image', query_limit=10, linknum=1, link_update=True, ignore_history=True, link_freshtime='2:33', autoquery=True, dailydrawcount=3, - disptgroup=[0], - authenticationgroup=[0], disinfogroup=[0], disslgroup=[0], disybgroup=[0], disautoquerygroup=[0], - dispaipugroup=[0]) + echarts=True, disptgroup=[0], authenticationgroup=[0], disinfogroup=[0], disslgroup=[0], disybgroup=[0], + disautoquerygroup=[0], dispaipugroup=[0]) write_file(content=cfg, path=r"./config/MajSoulInfo/config.yml") print('雀魂配置文件生成完毕') diff --git a/plugin/MajSoulInfo/majsoulinfo.py b/plugin/MajSoulInfo/majsoulinfo.py index 22fe417..b2e21bc 100644 --- a/plugin/MajSoulInfo/majsoulinfo.py +++ b/plugin/MajSoulInfo/majsoulinfo.py @@ -24,6 +24,7 @@ from utils.MessageChainBuilder import messagechain_builder from utils.cfg_loader import read_file from utils.text_to_img import text_to_image +from utils.echarts import * fontsize = 36 @@ -88,7 +89,7 @@ _template = read_file(r"./config/MajSoulInfo/template.yml") _config = read_file(r"./config/MajSoulInfo/config.yml") _query_limit = _config.get('query_limit', 10) - +_echarts_enable = _config.get('echarts', True) if _query_limit < 1: print('同时最大请求数量已自动调整为10') _query_limit = 10 @@ -623,7 +624,7 @@ async def getmonthreport(playername: str, selecttype: str = None, year: str = No Returns: 包含结果的Mirai消息链 """ - + stop_general_echarts = False ptchange = 0 msg = "" getrecent = False @@ -632,11 +633,15 @@ async def getmonthreport(playername: str, selecttype: str = None, year: str = No if not year or not month: year, month = time.strftime("%Y-%m", time.localtime()).split('-') paipumsg = f"{playername} 最近一个月 的对局报告\n" + chart_title = f"{playername} 最近一个月 的 " + timecross = "最近一个月" getrecent = True else: if 1 > int(month) or int(month) > 12: return await messagechain_builder(text="请输入正确的时间") paipumsg = f"{playername} {year}-{month} 的对局报告\n" + timecross = f"{year}-{month}" + chart_title = f"{playername} {year}-{month} 的 " selectmonth = f"{year}-{month}" rankdict = {"1": 0, "2": 0, "3": 0, "4": 0, "fly": 0} playerslist = [] @@ -671,10 +676,13 @@ async def getmonthreport(playername: str, selecttype: str = None, year: str = No if len(paipuresponse) == 0: return await messagechain_builder(text='该玩家这个月似乎没有进行过该类型的对局呢') paipumsg += f"总对局数: {len(paipuresponse)}\n其中" + if len(paipuresponse) < 10: + stop_general_echarts = True for players in paipuresponse: temp = players['players'] temp.sort(key=getrank) playerslist.append(temp) + y_data = [] for playerrank in playerslist: if selecttype == "4": rank = 4 @@ -683,6 +691,7 @@ async def getmonthreport(playername: str, selecttype: str = None, year: str = No for player in playerrank: if player['nickname'] == playername: ptchange += player['gradingScore'] + y_data.append(player['gradingScore']) rankdict[f"{rank}"] += 1 if player['score'] < 0: rankdict['fly'] += 1 @@ -692,6 +701,7 @@ async def getmonthreport(playername: str, selecttype: str = None, year: str = No rankdict['3'] * 3 + rankdict['4'] * 4) / len(paipuresponse) if rankdict['1'] + rankdict['2'] + rankdict['3'] + rankdict['4'] < len(paipuresponse): paipumsg += f"玩家名疑似输入有误,分析顺位失败,请检查大小写\n" + stop_general_echarts = True else: if selecttype == "4": paipumsg += f"{rankdict['1']}次①位,{rankdict['2']}次②位,{rankdict['3']}次③位,{rankdict['4']}次④位" @@ -718,9 +728,21 @@ async def getmonthreport(playername: str, selecttype: str = None, year: str = No print(f"发生了意外的错误,类别为aiohttp.client.ClientConnectorError,可能的原因是连接达到上限,可以尝试关闭代理:\n{_e}") return await messagechain_builder(text="查询超时,请稍后再试") _broadcast_type = _config.get('broadcast', 'image').lower() - if _broadcast_type in ['txt', 'text', 'str']: - return await messagechain_builder(text=msg) - return await messagechain_builder(imgbase64=text_to_image(fontsize=36, text=msg, needtobase64=True)) + if stop_general_echarts or not _echarts_enable: + if _broadcast_type in ['txt', 'text', 'str']: + return await messagechain_builder(text=msg) + return await messagechain_builder(imgbase64=text_to_image(fontsize=36, text=msg, needtobase64=True)) + else: + majsoul_bar(filename=f'{chart_title}PT得失图', x_data=[f'{i + 1}' for i in range(len(paipuresponse))], + y1_data=y_data, timecross=timecross) + majsoul_line(filename=f'{chart_title}PT变化图', x_data=[f'{i + 1}' for i in range(len(paipuresponse))], + y1_data=y_data, timecross=timecross) + if _broadcast_type in ['txt', 'text', 'str']: + return await messagechain_builder(text=msg, imgpath=[f"images/MajSoulInfo/{chart_title}PT得失图.png", + f"images/MajSoulInfo/{chart_title}PT变化图.png"]) + return await messagechain_builder(imgbase64=text_to_image(fontsize=36, text=msg, needtobase64=True), + imgpath=[f"images/MajSoulInfo/{chart_title}PT得失图.png", + f"images/MajSoulInfo/{chart_title}PT变化图.png"]) @staticmethod def removewatch(playername: str, groupid: int, isadmin=True) -> str: @@ -1815,6 +1837,8 @@ async def get_monthreport_byid(player_info: dict, selecttype: Union[str, int] = if not month: nextmontht = int(time.time() * 1000) month = "最近一个月" + chart_title = f"{playername} 最近一个月 的 " + timecross = "最近一个月" paipumsg = f"{playername} {matchtype} {month} 月报:\n" else: if re.match(r"\d{2,4}-\d{1,2}", month): @@ -1822,6 +1846,8 @@ async def get_monthreport_byid(player_info: dict, selecttype: Union[str, int] = if 1 > int(_m) or int(_m) > 12: return await messagechain_builder(text="请输入正确的时间") paipumsg = f"{playername} {matchtype} {month} 月报:\n" + timecross = f"{month} {matchtype}" + chart_title = f"{playername} {month} {matchtype} 的 " if _m == "12": month = f"{int(_y) + 1}-1" else: @@ -1854,7 +1880,9 @@ async def get_monthreport_byid(player_info: dict, selecttype: Union[str, int] = except asyncio.exceptions.TimeoutError: return await messagechain_builder(at=qq, text="查询超时, 请稍后再试") paipumsg += f"总对局数: {len(paipuresponse)}\n其中" + stop_general_echarts = True if len(paipuresponse) < 10 else False ptchange = 0 + y_data = [] for players in paipuresponse: temp = players['players'] temp.sort(key=getrank) @@ -1864,6 +1892,7 @@ async def get_monthreport_byid(player_info: dict, selecttype: Union[str, int] = for player in playerrank: if player['nickname'] == playername: ptchange += player['gradingScore'] + y_data.append(player['gradingScore']) rankdict[f"{rank}"] += 1 if player['score'] < 0: rankdict['fly'] += 1 @@ -1873,6 +1902,7 @@ async def get_monthreport_byid(player_info: dict, selecttype: Union[str, int] = rankdict['3'] * 3 + rankdict['4'] * 4) / len(paipuresponse) if rankdict['1'] + rankdict['2'] + rankdict['3'] + rankdict['4'] < len(paipuresponse): paipumsg += f"玩家名绑定的玩家名似乎输入有误,请尝试用qhpt 3/4 绑定正确的玩家名\n" + stop_general_echarts = True else: if selecttype == "4": paipumsg += f"{rankdict['1']}次①位,{rankdict['2']}次②位,{rankdict['3']}次③位,{rankdict['4']}次④位" @@ -1892,7 +1922,25 @@ async def get_monthreport_byid(player_info: dict, selecttype: Union[str, int] = infomsg += '\t' infomsg += f" 平均打点: {inforesponse.get('平均打点') if inforesponse.get('平均打点') else 0}\t 平均铳点 : {inforesponse.get('平均铳点') if inforesponse.get('平均铳点') else 0}" msg += infomsg - return await messagechain_builder(imgbase64=text_to_image(fontsize=36, text=msg, needtobase64=True)) + + if stop_general_echarts or not _echarts_enable: + _broadcast_type = _config.get('broadcast', 'image').lower() + if _broadcast_type in ['txt', 'text', 'str']: + return await messagechain_builder(text=msg) + return await messagechain_builder(imgbase64=text_to_image(fontsize=36, text=msg, needtobase64=True)) + else: + majsoul_bar(filename=f'{chart_title}PT得失图', x_data=[f'{i + 1}' for i in range(len(paipuresponse))], + y1_data=y_data, timecross=timecross) + majsoul_line(filename=f'{chart_title}PT变化图', x_data=[f'{i + 1}' for i in range(len(paipuresponse))], + y1_data=y_data, timecross=timecross) + + _broadcast_type = _config.get('broadcast', 'image').lower() + if _broadcast_type in ['txt', 'text', 'str']: + return await messagechain_builder(text=msg, imgpath=[f"images/MajSoulInfo/{chart_title}PT得失图.png", + f"images/MajSoulInfo/{chart_title}PT变化图.png"]) + return await messagechain_builder(imgbase64=text_to_image(fontsize=36, text=msg, needtobase64=True), + imgpath=[f"images/MajSoulInfo/{chart_title}PT得失图.png", + f"images/MajSoulInfo/{chart_title}PT变化图.png"]) async def get_playerinfo_byid(player_info: dict, selecttype: Union[str, int] = 4, model=None, diff --git a/plugin/TenHouPlugin/ptcalculation.py b/plugin/TenHouPlugin/ptcalculation.py index c626357..d0bea71 100644 --- a/plugin/TenHouPlugin/ptcalculation.py +++ b/plugin/TenHouPlugin/ptcalculation.py @@ -387,6 +387,7 @@ async def get_tenhou_month_report(playername: str, selecttype=None, year=None, m deadtime = 86400 * 180 matchcount = 0 score_change_sum = 0 + y_data = [] for item in records.get('list'): starttime = int(item['starttime']) if starttime - ps.lastplaytime > deadtime: # 超过180天未打则重置