优化wiki,新增夜兰参考面板

This commit is contained in:
CMHopeSunshine 2022-05-31 18:27:47 +08:00
parent f09b398c13
commit d92913772c
6 changed files with 57 additions and 98 deletions

View File

@ -196,7 +196,7 @@ async def draw_player_card(data, chara_data, uid, nickname="旅行者"):
bg_draw = ImageDraw.Draw(bg_img) bg_draw = ImageDraw.Draw(bg_img)
# 头部名片 # 头部名片
name_id = random.choice(data['avatars'][0:8])['id'] name_id = random.choice(data['avatars'][0:8])['id']
name_card = load_image(os.path.join(res_path, 'name_card', f'{name_id}.png'), crop=(0, 40, 840, 360), size=(846, 352)) name_card = load_image(os.path.join(res_path, 'name_card', f'{name_id}.png'), crop=(0, 40, 840, 360), size=(846, 360))
avatar = load_image(os.path.join(res_path, 'role_profile', f'{name_id}.png'), size=(240, 240)) avatar = load_image(os.path.join(res_path, 'role_profile', f'{name_id}.png'), size=(240, 240))
bg_img.alpha_composite(name_card, (57, 27)) bg_img.alpha_composite(name_card, (57, 27))
bg_img.alpha_composite(avatar, (360, 25)) bg_img.alpha_composite(avatar, (360, 25))

View File

@ -8,9 +8,9 @@ from nonebot.params import RegexDict
from nonebot.typing import T_State from nonebot.typing import T_State
from utils.alias_handler import get_match_alias from utils.alias_handler import get_match_alias
from utils.file_handler import load_json_from_url
from utils.message_util import MessageBuild from utils.message_util import MessageBuild
from .abyss_rate_draw import draw_rate_rank, draw_teams_rate from .abyss_rate_draw import draw_rate_rank, draw_teams_rate
from .blue import get_blue_pic
__usage__ = ''' __usage__ = '''
1.[xx角色攻略]查看西风驿站出品的角色一图流攻略 1.[xx角色攻略]查看西风驿站出品的角色一图流攻略
@ -42,7 +42,12 @@ async def genshinAttribute(event: MessageEvent):
name = event.message.extract_plain_text().replace('参考面板', '').strip() name = event.message.extract_plain_text().replace('参考面板', '').strip()
realname = get_match_alias(name) realname = get_match_alias(name)
if realname: if realname:
img = await get_blue_pic(realname) blue = await load_json_from_url('https://static.cherishmoon.fun/LittlePaimon/blue/blue.json')
if realname in blue.keys():
img = await MessageBuild.StaticImage(url=f'LittlePaimon/blue/{blue[realname][0]}.jpg',
crop=(0, int(blue[realname][1][0]), 1080, int(blue[realname][1][1])))
else:
img = MessageBuild.Text(f'没有找到{name}的参考面板')
await attribute.finish(img) await attribute.finish(img)
else: else:
await attribute.finish(f'没有找到{name}的参考面板', at_sender=True) await attribute.finish(f'没有找到{name}的参考面板', at_sender=True)
@ -91,7 +96,7 @@ async def abyss_team_handler(event: MessageEvent, reGroup=RegexDict()):
await abyss_team.finish(abyss_img) await abyss_team.finish(abyss_img)
def create_choice_command(endswith: str, type_: str, url: str, exclude: list = []): def create_choice_command(endswith: str, type_: str, url: str, tips: str = None):
command = on_endswith(endswith, priority=6, block=True) command = on_endswith(endswith, priority=6, block=True)
@command.handle() @command.handle()
@ -108,12 +113,14 @@ def create_choice_command(endswith: str, type_: str, url: str, exclude: list = [
if name == 'q': if name == 'q':
await command.finish() await command.finish()
match_alias = get_match_alias(name, type_) match_alias = get_match_alias(name, type_)
if isinstance(match_alias, str) and match_alias not in exclude: if isinstance(match_alias, str):
await command.finish(await MessageBuild.StaticImage(url=url.format(match_alias))) await command.finish(
elif isinstance(match_alias, list) and len(match_alias) == 1 and match_alias[0] not in exclude: await MessageBuild.StaticImage(url=url.format(match_alias), tips=tips.format(match_alias)))
await command.finish(await MessageBuild.StaticImage(url=url.format(match_alias[0]))) elif isinstance(match_alias, list) and len(match_alias) == 1:
await command.finish(
await MessageBuild.StaticImage(url=url.format(match_alias[0]), tips=tips.format(match_alias[0])))
else: else:
if not match_alias or match_alias in exclude: if not match_alias:
await command.finish(f'没有{state["name"]}{endswith}哦~', at_sender=True) await command.finish(f'没有{state["name"]}{endswith}哦~', at_sender=True)
else: else:
if isinstance(match_alias, dict): if isinstance(match_alias, dict):
@ -133,7 +140,8 @@ def create_choice_command(endswith: str, type_: str, url: str, exclude: list = [
await command.finish() await command.finish()
if choice.isdigit() and (1 <= int(choice) <= len(match_alias)): if choice.isdigit() and (1 <= int(choice) <= len(match_alias)):
await command.finish( await command.finish(
await MessageBuild.StaticImage(url=url.format(match_alias[int(choice) - 1]))) await MessageBuild.StaticImage(url=url.format(match_alias[int(choice) - 1]),
tips=tips.format(match_alias[int(choice) - 1])))
if choice not in match_alias: if choice not in match_alias:
state['times'] = state['times'] + 1 if 'times' in state else 1 state['times'] = state['times'] + 1 if 'times' in state else 1
if state['times'] == 1: if state['times'] == 1:
@ -142,12 +150,11 @@ def create_choice_command(endswith: str, type_: str, url: str, exclude: list = [
await command.reject(f'别调戏派蒙啦,快选一个吧,不想问了请回答\"q\"', at_sender=True) await command.reject(f'别调戏派蒙啦,快选一个吧,不想问了请回答\"q\"', at_sender=True)
elif state['times'] >= 3: elif state['times'] >= 3:
await command.finish(f'看来旅行者您有点神志不清哦(,下次再问派蒙吧' + MessageSegment.face(146), at_sender=True) await command.finish(f'看来旅行者您有点神志不清哦(,下次再问派蒙吧' + MessageSegment.face(146), at_sender=True)
await command.finish(await MessageBuild.StaticImage(url=url.format(choice))) await command.finish(await MessageBuild.StaticImage(url=url.format(choice), tips=tips.format(choice)))
create_choice_command('原魔图鉴', 'monsters', 'LittlePaimon/MonsterMaps/{}.jpg') create_choice_command('原魔图鉴', 'monsters', 'LittlePaimon/MonsterMaps/{}.jpg', '暂时没有{}的原魔图鉴哦~')
create_choice_command('武器攻略', 'weapons', 'LittlePaimon/WeaponGuild/{}.png') create_choice_command('武器攻略', 'weapons', 'LittlePaimon/WeaponGuild/{}.png', '暂时没有{}的武器攻略哦~')
create_choice_command('角色攻略', 'roles', 'LittlePaimon/XFGuide/{}.jpg', ['夜兰', '久岐忍', '鹿野院平藏']) create_choice_command('角色攻略', 'roles', 'LittlePaimon/XFGuide/{}.jpg', '暂时没有{}的角色攻略哦~')
create_choice_command('角色材料', 'roles', 'LittlePaimon/RoleMaterials/{}材料.jpg') create_choice_command('角色材料', 'roles', 'LittlePaimon/RoleMaterials/{}材料.jpg', '暂时没有{}的角色材料哦~')
create_choice_command('收益曲线', 'roles', 'LittlePaimon/blue/{}.jpg', ['神里绫人', '夜兰', '久岐忍', '鹿野院平藏']) create_choice_command('收益曲线', 'roles', 'LittlePaimon/blue/{}.jpg', '暂时没有{}的收益曲线哦~')

View File

@ -1,63 +0,0 @@
from utils.message_util import MessageBuild
blue = {
'胡桃': ['', (0, 1886)],
'托马': ['', (1886, 2420)],
'宵宫': ['', (2420, 2955)],
'烟绯': ['', (2955, 3492)],
'可莉': ['', (3492, 4029)],
'迪卢克': ['', (4029, 4567)],
'辛焱': ['', (4567, 5511)],
'安柏': ['', (5511, 6047)],
'香菱': ['', (6047, 6982)],
'班尼特': ['', (6982, 7932)],
'神里绫人': ['', (0, 750)],
'珊瑚宫心海': ['', (750, 1700)],
'达达利亚': ['', (1700, 2424)],
'行秋': ['', (2424, 2920)],
'莫娜': ['', (2920, 3640)],
'芭芭拉': ['', (3640, 4396)],
'申鹤': ['', (0, 959)],
'神里绫华': ['', (959, 1496)],
'优菈': ['', (1496, 2231)],
'甘雨': ['', (2231, 3569)],
'凯亚': ['', (3569, 4102)],
'重云': ['', (4102, 4639)],
'七七': ['', (4639, 5374)],
'迪奥娜': ['', (5374, 5710)],
'罗莎莉亚': ['', (5710, 6044)],
'埃洛伊': ['', (6044, 6394)],
'八重神子': ['', (0, 947)],
'雷电将军': ['', (947, 1474)],
'九条裟罗': ['', (1474, 2001)],
'刻晴': ['', (2001, 2730)],
'雷泽': ['', (2730, 3258)],
'菲谢尔': ['', (3258, 3786)],
'丽莎': ['', (3786, 4310)],
'北斗': ['', (4310, 4838)],
'雷主': ['', (4838, 5177)],
'早柚': ['', (0, 553)],
'枫原万叶': ['', (553, 1078)],
'': ['', (1078, 1803)],
'温迪': ['', (1803, 2527)],
'': ['', (2527, 3252)],
'砂糖': ['', (3252, 3977)],
'风主': ['', (3977, 4311)],
'': ['', (3977, 4311)],
'': ['', (3977, 4311)],
'荒泷一斗': ['', (0, 741)],
'五郎': ['', (741, 1055)],
'阿贝多': ['', (1055, 1767)],
'钟离': ['', (1767, 2475)],
'诺艾尔': ['', (2475, 3188)],
'凝光': ['', (3188, 3900)],
'岩主': ['', (3900, 4608)],
'云堇': ['', (4608, 5325)]
}
async def get_blue_pic(name):
if name in blue.keys():
return await MessageBuild.StaticImage(url=f'LittlePaimon/blue/{blue[name][0]}.jpg',
crop=(0, int(blue[name][1][0]), 1080, int(blue[name][1][1])))
return None

View File

@ -90,7 +90,10 @@ async def get_img(url: str,
params=params, params=params,
timeout=timeout, timeout=timeout,
**kwargs) **kwargs)
img = Image.open(BytesIO(resp.read())) resp = resp.read()
if b'error' in resp:
return 'No Such File'
img = Image.open(BytesIO(resp))
if size: if size:
img = img.resize(size, Image.ANTIALIAS) img = img.resize(size, Image.ANTIALIAS)
if mode: if mode:
@ -110,7 +113,10 @@ async def get_img(url: str,
params=params, params=params,
timeout=timeout, timeout=timeout,
**kwargs) **kwargs)
img = Image.open(BytesIO(resp.read())) resp = resp.read()
if b'error' in resp:
return 'No Such File'
img = Image.open(BytesIO(resp))
if size: if size:
img = img.resize(size, Image.ANTIALIAS) img = img.resize(size, Image.ANTIALIAS)
if mode: if mode:

View File

@ -37,18 +37,12 @@ def load_json(file: str = None, path: Union[Path, str] = None, encoding: str = '
return json.load(path.open('r', encoding=encoding)) return json.load(path.open('r', encoding=encoding))
async def load_json_from_url(url: str, encoding: str = 'utf-8', refresh: bool = False): async def load_json_from_url(url: str):
if 'static.cherishmoon.fun' in url: try:
url_path = Path() / 'data' / url.split('static.cherishmoon.fun/')[1] resp = await aiorequests.get(url)
if refresh or not url_path.exists(): except SSLCertVerificationError:
try: resp = await aiorequests.get(url.replace('https', 'http'))
resp = await aiorequests.get(url) return resp.json()
except SSLCertVerificationError:
resp = await aiorequests.get(url.replace('https', 'http'))
save_json(resp.json(), path=url_path, encoding=encoding)
return resp.json()
else:
return load_json(path=url_path, encoding=encoding)
def save_json(data, file: str = None, path: Union[Path, str] = None, encoding: str = 'utf-8'): def save_json(data, file: str = None, path: Union[Path, str] = None, encoding: str = 'utf-8'):

View File

@ -1,5 +1,6 @@
import re import re
import base64 import base64
from time import time
from PIL import Image from PIL import Image
from pathlib import Path from pathlib import Path
@ -39,14 +40,17 @@ class MessageBuild:
size: Optional[Tuple[int, int]] = None, size: Optional[Tuple[int, int]] = None,
crop: Optional[Tuple[int, int, int, int]] = None, crop: Optional[Tuple[int, int, int, int]] = None,
quality: Optional[int] = 100, quality: Optional[int] = 100,
mode: Optional[str] = 'RGB' mode: Optional[str] = 'RGB',
tips: Optional[str] = None
): ):
path = Path() / 'data' / url path = Path() / 'data' / url
if not path.exists(): if path.exists() and not check_time(path.stat().st_mtime, 3):
img = Image.open(path)
else:
path.parent.mkdir(parents=True, exist_ok=True) path.parent.mkdir(parents=True, exist_ok=True)
img = await aiorequests.get_img(url='https://static.cherishmoon.fun/' + url, save_path=path) img = await aiorequests.get_img(url='https://static.cherishmoon.fun/' + url, save_path=path)
else: if img == 'No Such File':
img = Image.open(path) return MessageSegment.text(tips or '缺少该静态资源')
if size: if size:
img = img.resize(size) img = img.resize(size)
if crop: if crop:
@ -172,3 +176,14 @@ def transform_uid(msg):
if uid: if uid:
uid_list.append(uid.group('uid')) uid_list.append(uid.group('uid'))
return uid_list if len(uid_list) > 1 else uid_list[0] if uid_list else None return uid_list if len(uid_list) > 1 else uid_list[0] if uid_list else None
# 检查该时间戳和当前时间戳相差是否超过n天 超过则返回True
def check_time(time_stamp, n=1):
time_stamp = int(time_stamp)
now = int(time())
if (now - time_stamp) / 86400 > n:
return True
else:
return False