mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
🐛 深渊登场率
api改动,暂不可用
This commit is contained in:
parent
9c17172627
commit
416edc5609
@ -9,7 +9,7 @@ from nonebot.plugin import PluginMetadata
|
||||
from nonebot.typing import T_State
|
||||
|
||||
from LittlePaimon.utils.alias import get_match_alias
|
||||
from .abyss_rate_draw import draw_rate_rank, draw_teams_rate
|
||||
# from .abyss_rate_draw import draw_rate_rank, draw_teams_rate
|
||||
|
||||
__paimon_help__ = {
|
||||
'type': '原神Wiki',
|
||||
@ -21,10 +21,8 @@ help_msg = """"1.[xx角色攻略]查看西风驿站出品的角色一图流攻
|
||||
"3.[xx参考面板]查看blue菌hehe出品的参考面板攻略\n"
|
||||
"4.[xx收益曲线]查看blue菌hehe出品的收益曲线攻略\n"
|
||||
"5.[今日/明日/周x材料]查看每日角色天赋材料和武器突破材料表\n"
|
||||
"6.[深渊登场率]查看2.6深渊角色登场率\n"
|
||||
"7.[深渊上半/下半阵容出场率]查看2.6深渊阵容出场率\n"
|
||||
"8.[xx武器攻略]查看武器攻略\n"
|
||||
"9.[xx原魔图鉴]查看原魔图鉴\n"
|
||||
"6.[xx武器攻略]查看武器攻略\n"
|
||||
"7.[xx原魔图鉴]查看原魔图鉴\n"
|
||||
"""
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
@ -44,18 +42,18 @@ daily_material = on_regex(r'(?P<day>现在|(今|明|后)(天|日)|周(一|二|
|
||||
'pm_usage': '<今天|周几>材料',
|
||||
'pm_priority': 8
|
||||
})
|
||||
abyss_rate = on_command('syrate', aliases={'深渊登场率', '深境螺旋登场率', '深渊登场率排行', '深渊排行'}, priority=11, block=True, state={
|
||||
'pm_name': '深渊登场率排行',
|
||||
'pm_description': '查看本期深渊的角色登场率排行',
|
||||
'pm_usage': '深渊登场率',
|
||||
'pm_priority': 9,
|
||||
})
|
||||
abyss_team = on_regex(r'^(深渊|深境螺旋)(?P<floor>上半|下半)阵容(排行|出场率)?$', priority=11, block=True, state={
|
||||
'pm_name': '深渊阵容出场率排行',
|
||||
'pm_description': '查看本期深渊的阵容出场率排行',
|
||||
'pm_usage': '深渊<上半|下半>阵容排行',
|
||||
'pm_priority': 10,
|
||||
})
|
||||
# abyss_rate = on_command('syrate', aliases={'深渊登场率', '深境螺旋登场率', '深渊登场率排行', '深渊排行'}, priority=11, block=True, state={
|
||||
# 'pm_name': '深渊登场率排行',
|
||||
# 'pm_description': '查看本期深渊的角色登场率排行',
|
||||
# 'pm_usage': '深渊登场率',
|
||||
# 'pm_priority': 9,
|
||||
# })
|
||||
# abyss_team = on_regex(r'^(深渊|深境螺旋)(?P<floor>上半|下半)阵容(排行|出场率)?$', priority=11, block=True, state={
|
||||
# 'pm_name': '深渊阵容出场率排行',
|
||||
# 'pm_description': '查看本期深渊的阵容出场率排行',
|
||||
# 'pm_usage': '深渊<上半|下半>阵容排行',
|
||||
# 'pm_priority': 10,
|
||||
# })
|
||||
|
||||
|
||||
@daily_material.handle()
|
||||
@ -87,16 +85,16 @@ async def _(event: MessageEvent, regex_dict: dict = RegexDict()):
|
||||
MessageSegment.image(file='https://static.cherishmoon.fun/LittlePaimon/DailyMaterials/周三周六.jpg'))
|
||||
|
||||
|
||||
@abyss_rate.handle()
|
||||
async def abyss_rate_handler(event: MessageEvent):
|
||||
abyss_img = await draw_rate_rank()
|
||||
await abyss_rate.finish(abyss_img)
|
||||
# @abyss_rate.handle()
|
||||
# async def abyss_rate_handler(event: MessageEvent):
|
||||
# abyss_img = await draw_rate_rank()
|
||||
# await abyss_rate.finish(abyss_img)
|
||||
|
||||
|
||||
@abyss_team.handle()
|
||||
async def abyss_team_handler(event: MessageEvent, reGroup=RegexDict()):
|
||||
abyss_img = await draw_teams_rate(reGroup['floor'])
|
||||
await abyss_team.finish(abyss_img)
|
||||
# @abyss_team.handle()
|
||||
# async def abyss_team_handler(event: MessageEvent, reGroup=RegexDict()):
|
||||
# abyss_img = await draw_teams_rate(reGroup['floor'])
|
||||
# await abyss_team.finish(abyss_img)
|
||||
|
||||
|
||||
def create_wiki_matcher(pattern: str, help_fun: str, help_name: str):
|
||||
|
@ -13,7 +13,7 @@ headers = {
|
||||
async def get_rate(type: str = 'role'):
|
||||
url = f'https://www.youchuang.fun/gamerole/{type}Rate'
|
||||
json_data = {
|
||||
"version": "2.8"
|
||||
"version": "3.0"
|
||||
}
|
||||
res = await aiorequests.post(url=url, headers=headers, json=json_data)
|
||||
return res.json()
|
||||
@ -22,7 +22,7 @@ async def get_rate(type: str = 'role'):
|
||||
async def get_formation_rate(layer: int = 1):
|
||||
url = 'https://www.youchuang.fun/gamerole/formationRate'
|
||||
json_data = {
|
||||
"version": "2.8",
|
||||
"version": "3.0",
|
||||
"layer": layer
|
||||
}
|
||||
res = await aiorequests.post(url=url, headers=headers, json=json_data)
|
||||
@ -33,7 +33,7 @@ async def get_teammates_rate(name: str):
|
||||
url = 'https://www.youchuang.fun/gamerole/teammatesRate'
|
||||
json_data = {
|
||||
"name": name,
|
||||
"version": "2.8"
|
||||
"version": "3.0"
|
||||
}
|
||||
res = await aiorequests.post(url=url, headers=headers, json=json_data)
|
||||
return res.json()
|
||||
@ -43,7 +43,7 @@ async def get_weapon_rate(name: str):
|
||||
url = 'https://www.youchuang.fun/gamerole/getWeaponByName'
|
||||
json_data = {
|
||||
"name": name,
|
||||
"version": "2.8"
|
||||
"version": "3.9"
|
||||
}
|
||||
res = await aiorequests.post(url=url, headers=headers, json=json_data)
|
||||
return res.json()
|
||||
|
@ -1,78 +1,79 @@
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
from LittlePaimon.utils.alias import get_id_by_name
|
||||
from LittlePaimon.utils.files import load_image
|
||||
from LittlePaimon.utils.image import PMImage, font_manager as fm
|
||||
from LittlePaimon.utils.alias import get_icon
|
||||
from LittlePaimon.utils.message import MessageBuild
|
||||
from LittlePaimon.config import RESOURCE_BASE_PATH
|
||||
from .abyss_rate_data import get_rate, get_formation_rate
|
||||
|
||||
res_path = Path() / 'resources' / 'LittlePaimon'
|
||||
|
||||
|
||||
def get_font(size, font_type='msyh.ttc'):
|
||||
return ImageFont.truetype(str(res_path / font_type), size)
|
||||
|
||||
|
||||
async def draw_rate_rank(type: str = 'role', mode: str = 'used'):
|
||||
async def draw_rate_rank(type: str = 'role'):
|
||||
data = await get_rate(type)
|
||||
if not data or data['code'] != '200':
|
||||
return '获取工坊数据失败,请稍后再试'
|
||||
col = int(len(data['result']['rateList']) / 5) if len(data['result']['rateList']) % 5 == 0 else int(len(data['result']['rateList']) / 5) + 1
|
||||
top_img = Image.open(res_path / 'player_card' / '卡片顶部无字.png').resize((1080, 316))
|
||||
body_img = Image.open(res_path / 'player_card' / '卡片身体.png').resize((1080, 226))
|
||||
bottom_img = Image.open(res_path / 'player_card' / '卡片底部.png').resize((1080, 72))
|
||||
bg_img = Image.new('RGBA', (1080, top_img.height + col * 220 + bottom_img.height + 50))
|
||||
bg_img.paste(top_img, (0, 0))
|
||||
bg_draw = ImageDraw.Draw(bg_img)
|
||||
bg_draw.text((70, 55), '2.8深境螺旋登场率排行榜', fill='black', font=get_font(40, 'msyhbd.ttc'))
|
||||
bg_draw.text((70, 110), f'当前共{data["result"]["userCount"]}份样本数据', fill='black', font=get_font(35))
|
||||
for i in range(0, col + 1):
|
||||
bg_img.paste(body_img, (0, top_img.height + i * body_img.height))
|
||||
bg_img.paste(bottom_img, (0, top_img.height + col * 220 + 50))
|
||||
bg_draw.text((130, bg_img.height - 86), 'Created by LittlePaimon | Data from 原神创意工坊', fill='black', font=get_font(35))
|
||||
n = 0
|
||||
for role in data['result']['rateList']:
|
||||
role_img = Image.open(res_path / 'role_card' / f'{get_id_by_name(role["name"])}.png').resize((160, 200))
|
||||
role_draw = ImageDraw.Draw(role_img)
|
||||
role_draw.text((28 if len(role['rate']) == 6 else 38, 158), role['rate'], font=get_font(30), fill='black')
|
||||
bg_img.alpha_composite(role_img, (50 + 204 * (n % 5), 180 + 240 * int(n / 5)))
|
||||
n += 1
|
||||
col = len(data['result']['rateList']) // 5 if len(data['result']['rateList']) % 5 == 0 else len(
|
||||
data['result']['rateList']) // 5 + 1
|
||||
|
||||
top_img = await load_image(RESOURCE_BASE_PATH / 'general' / '卡片顶部无字.png', size=(1080, 316))
|
||||
body_img = await load_image(RESOURCE_BASE_PATH / 'general' / '卡片身体.png', size=(1080, 226))
|
||||
bottom_img = await load_image(RESOURCE_BASE_PATH / 'general' / '卡片底部.png', size=(1080, 72))
|
||||
bg_img = PMImage(size=(1080, top_img.height + col * 220 + bottom_img.height + 50), mode='RGBA')
|
||||
await bg_img.paste(top_img, (0, 0))
|
||||
await bg_img.text('3.0深境螺旋登场率排行榜', 70, 55, color='black', font=fm.get('msyhbd.ttc', 40))
|
||||
await bg_img.text(f'当前共{data["result"]["userCount"]}份样本数据', 70, 110, color='black', font=fm.get('msyh.ttc', 35))
|
||||
for i in range(col + 1):
|
||||
await bg_img.paste(body_img, (0, top_img.height + i * body_img.height))
|
||||
await bg_img.paste(bottom_img, (0, top_img.height + col * 220 + 50))
|
||||
await bg_img.text('Created by LittlePaimon | Data from 原神创意工坊', 130, bg_img.height - 86, color='black',
|
||||
font=fm.get('msyh.ttc', 35))
|
||||
for n, role in enumerate(data['result']['rateList']):
|
||||
role_card = PMImage(size=(160, 200), color=(200, 200, 200, 255), mode='RGBA')
|
||||
role_img = await load_image(RESOURCE_BASE_PATH / 'avatar_card' / f'{get_icon(name=role["name"], icon_type="card")}.png', size=(160, 160))
|
||||
await role_card.paste(role_img, (0, 0))
|
||||
await role_card.text((28 if len(role['rate']) == 6 else 38, 158), role['rate'], font=fm.get('msyh.ttc', 30),
|
||||
color='black')
|
||||
await bg_img.paste(role_card, (50 + 204 * (n % 5), 180 + 240 * int(n / 5)))
|
||||
return MessageBuild.Image(bg_img, quality=75)
|
||||
|
||||
|
||||
async def draw_teams_rate(floor='上半半'):
|
||||
data = await get_formation_rate(1 if floor == '上半' else 2)
|
||||
if not data or data['code'] != '200':
|
||||
return '获取工坊数据失败,请稍后再试'
|
||||
rateList = data['result']['rateList'][0:10]
|
||||
top_img = Image.open(res_path / 'player_card' / '卡片顶部无字.png').resize((1080, 316))
|
||||
body_img = Image.open(res_path / 'player_card' / '卡片身体.png').resize((1080, 240))
|
||||
bottom_img = Image.open(res_path / 'player_card' / '卡片底部.png').resize((1080, 72))
|
||||
bg_img = Image.new('RGBA', (1080, top_img.height + 10 * body_img.height + bottom_img.height - 130))
|
||||
bg_img.paste(top_img, (0, 0))
|
||||
bg_draw = ImageDraw.Draw(bg_img)
|
||||
bg_draw.text((70, 55), f'2.8深境螺旋阵容出场率 | {floor}', fill='black', font=get_font(40, 'msyhbd.ttc'))
|
||||
bg_draw.text((70, 110), f'当前共{data["result"]["userCount"]}份样本数据', fill='black', font=get_font(35))
|
||||
for i in range(0, 10):
|
||||
bg_img.paste(body_img, (0, top_img.height + i * body_img.height))
|
||||
bg_img.paste(bottom_img, (0, top_img.height + 10 * 240 - 130))
|
||||
bg_draw.text((130, bg_img.height - 86), 'Created by LittlePaimon | Data from 原神创意工坊', fill='black', font=get_font(35))
|
||||
n = 0
|
||||
for team in rateList:
|
||||
bg_draw.text((48, 240 + 240 * n), '排名', fill='grey', font=get_font(30))
|
||||
bg_draw.text((65 if n != 9 else 55, 275 + 240 * n), str(n + 1), fill='black', font=get_font(35))
|
||||
bg_draw.text((934, 240 + 240 * n), '出场率', fill='grey', font=get_font(30))
|
||||
bg_draw.text((930, 275 + 240 * n), team['rate'], fill='black', font=get_font(35))
|
||||
r = 0
|
||||
for role in team['formation']:
|
||||
role_img = Image.open(
|
||||
res_path / 'role_card' / f'{get_id_by_name(role["name"])}.png').resize((160, 200))
|
||||
role_draw = ImageDraw.Draw(role_img)
|
||||
role_draw.text((80 - 15 * len(role['name']), 158), role['name'], font=get_font(30), fill='black')
|
||||
bg_img.alpha_composite(role_img, (130 + 204 * r, 180 + 240 * n))
|
||||
r += 1
|
||||
n += 1
|
||||
|
||||
return MessageBuild.Image(bg_img, quality=75)
|
||||
|
||||
# async def draw_teams_rate(floor='上半半'):
|
||||
# data = await get_formation_rate(1 if floor == '上半' else 2)
|
||||
# if not data or data['code'] != '200':
|
||||
# return '获取工坊数据失败,请稍后再试'
|
||||
# rateList = data['result']['rateList'][:10]
|
||||
# top_img = Image.open(RESOURCE_BASE_PATH / 'general' / '卡片顶部无字.png').resize((1080, 316))
|
||||
#
|
||||
# body_img = Image.open(RESOURCE_BASE_PATH / 'general' / '卡片身体.png').resize((1080, 240))
|
||||
#
|
||||
# bottom_img = Image.open(RESOURCE_BASE_PATH / 'general' / '卡片底部.png').resize((1080, 72))
|
||||
#
|
||||
# bg_img = Image.new('RGBA', (1080, top_img.height + 10 * body_img.height + bottom_img.height - 130))
|
||||
#
|
||||
# bg_img.paste(top_img, (0, 0))
|
||||
# bg_draw = ImageDraw.Draw(bg_img)
|
||||
# bg_draw.text((70, 55), f'3.0深境螺旋阵容出场率 | {floor}', fill='black', font=fm.get('msyhbd.ttc', 40))
|
||||
#
|
||||
# bg_draw.text((70, 110), f'当前共{data["result"]["userCount"]}份样本数据', fill='black', font=fm.get('msyh.ttc', 35))
|
||||
#
|
||||
# for i in range(10):
|
||||
# bg_img.paste(body_img, (0, top_img.height + i * body_img.height))
|
||||
# bg_img.paste(bottom_img, (0, top_img.height + 10 * 240 - 130))
|
||||
# bg_draw.text((130, bg_img.height - 86), 'Created by LittlePaimon | Data from 原神创意工坊', fill='black',
|
||||
# font=fm.get('msyh.ttc', 35))
|
||||
#
|
||||
# for n, team in enumerate(rateList):
|
||||
# bg_draw.text((48, 240 + 240 * n), '排名', fill='grey', font=get_font(30))
|
||||
# bg_draw.text((65 if n != 9 else 55, 275 + 240 * n), str(n + 1), fill='black', font=fm.get('msyh.ttc', 35))
|
||||
#
|
||||
# bg_draw.text((934, 240 + 240 * n), '出场率', fill='grey', font=get_font(30))
|
||||
# bg_draw.text((930, 275 + 240 * n), team['rate'], fill='black', font=fm.get('msyh.ttc', 35))
|
||||
#
|
||||
# for r, role in enumerate(team['formation']):
|
||||
# role_img = Image.open(CARD / f'{get_icon(name=role["name"], icon_type="card")}.png').resize((160, 200))
|
||||
#
|
||||
# role_draw = ImageDraw.Draw(role_img)
|
||||
# role_draw.text((80 - 15 * len(role['name']), 158), role['name'], font=get_font(30), fill='black')
|
||||
#
|
||||
# bg_img.alpha_composite(role_img, (130 + 204 * r, 180 + 240 * n))
|
||||
# return MessageBuild.Image(bg_img, quality=75)
|
||||
|
Loading…
Reference in New Issue
Block a user