✨ 支持查食物
的图片版 (#500)
@ -2,6 +2,7 @@ import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Union
|
||||
|
||||
import aiofiles
|
||||
from gsuid_core.logger import logger
|
||||
|
||||
from .abyss_history import history_data
|
||||
@ -10,10 +11,10 @@ from ..gsuid_utils.api.hhw.request import (
|
||||
get_abyss_review_raw,
|
||||
)
|
||||
|
||||
REVIEW_PATH = Path(__file__).parent / "review.json"
|
||||
REVIEW_PATH = Path(__file__).parent / 'review.json'
|
||||
|
||||
|
||||
async def generate_data():
|
||||
async def _generate_data():
|
||||
raw_data = await get_abyss_review_raw()
|
||||
result = {}
|
||||
for version in history_data:
|
||||
@ -30,6 +31,16 @@ async def generate_data():
|
||||
logger.info('[深渊预览] 数据已刷新!')
|
||||
|
||||
|
||||
async def generate_data():
|
||||
if REVIEW_PATH.exists():
|
||||
async with aiofiles.open(REVIEW_PATH, 'r', encoding='UTF-8') as file:
|
||||
data: Dict = json.loads(await file.read())
|
||||
if list(data.keys())[0] != list(history_data.keys())[0]:
|
||||
await _generate_data()
|
||||
else:
|
||||
await _generate_data()
|
||||
|
||||
|
||||
async def get_review(version: Union[str, float]) -> Union[List, str]:
|
||||
if not REVIEW_PATH.exists():
|
||||
return '请等待数据加载完成...'
|
||||
|
@ -5,6 +5,7 @@ from gsuid_core.bot import Bot
|
||||
from gsuid_core.models import Event
|
||||
from gsuid_core.segment import MessageSegment
|
||||
|
||||
from .get_foods_pic import get_foods_wiki_img
|
||||
from .get_weapons_pic import get_weapons_wiki_img
|
||||
from ..genshinuid_config.gs_config import gsconfig
|
||||
from .get_artifacts_pic import get_artifacts_wiki_img
|
||||
@ -32,7 +33,11 @@ async def send_enemies(bot: Bot, ev: Event):
|
||||
|
||||
@sv_wiki_text.on_prefix(('食物介绍', '食物资料', '查食物'))
|
||||
async def send_food(bot: Bot, ev: Event):
|
||||
await bot.send(await foods_wiki(ev.text))
|
||||
if gsconfig.get_config('PicWiki').data:
|
||||
im = await get_foods_wiki_img(ev.text)
|
||||
else:
|
||||
im = await foods_wiki(ev.text)
|
||||
await bot.send(im)
|
||||
|
||||
|
||||
@sv_wiki_text.on_prefix(('圣遗物介绍', '圣遗物资料', '查圣遗物'))
|
||||
|
129
GenshinUID/genshinuid_wikitext/get_foods_pic.py
Normal file
@ -0,0 +1,129 @@
|
||||
from typing import List, Union
|
||||
|
||||
import aiofiles
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from .path import TEXT_PATH
|
||||
from ..utils.colors import white_color
|
||||
from ..utils.error_reply import get_error
|
||||
from ..gsuid_utils.api.minigg.models import Food
|
||||
from ..utils.get_assets import get_assets_from_ambr
|
||||
from ..utils.resource.RESOURCE_PATH import WIKI_FOOD_PATH
|
||||
from ..utils.image.convert import convert_img, get_str_size
|
||||
from ..gsuid_utils.api.minigg.request import get_others_info
|
||||
from ..utils.image.image_tools import (
|
||||
get_star_png,
|
||||
get_simple_bg,
|
||||
get_unknown_png,
|
||||
)
|
||||
from ..utils.fonts.genshin_fonts import (
|
||||
gs_font_18,
|
||||
gs_font_22,
|
||||
gs_font_36,
|
||||
gs_font_44,
|
||||
)
|
||||
|
||||
|
||||
async def get_foods_wiki_img(name: str) -> Union[str, bytes]:
|
||||
data = await get_others_info('foods', name)
|
||||
if isinstance(data, int):
|
||||
return get_error(data)
|
||||
elif isinstance(data, List):
|
||||
return get_error(-400)
|
||||
else:
|
||||
food_name = data['name']
|
||||
path = WIKI_FOOD_PATH / f'{food_name}.jpg'
|
||||
if path.exists():
|
||||
async with aiofiles.open(path, 'rb') as f:
|
||||
return await f.read()
|
||||
img = await draw_foods_wiki_img(data)
|
||||
return img
|
||||
|
||||
|
||||
async def draw_foods_wiki_img(data: Food):
|
||||
gray_color = (230, 230, 230)
|
||||
img_test = Image.new('RGBA', (1, 1))
|
||||
img_test_draw = ImageDraw.Draw(img_test)
|
||||
effect = data['effect']
|
||||
desc = data['description']
|
||||
|
||||
effect = get_str_size(effect, gs_font_22, 440)
|
||||
desc = get_str_size(desc, gs_font_22, 440)
|
||||
|
||||
_, _, _, y1 = img_test_draw.textbbox((0, 0), effect, gs_font_22)
|
||||
_, _, _, y2 = img_test_draw.textbbox((0, 0), desc, gs_font_22)
|
||||
w, h = 600, 750 + y1 + y2
|
||||
|
||||
star_pic = get_star_png(data['rarity'])
|
||||
path = TEXT_PATH / f'UI_Buff_Item_{data["foodcategory"]}.png'
|
||||
if path.exists():
|
||||
type_pic = Image.open(path)
|
||||
else:
|
||||
type_pic = await get_assets_from_ambr(
|
||||
f'UI_Buff_Item_{data["foodcategory"]}'
|
||||
)
|
||||
if type_pic is None:
|
||||
type_pic = get_unknown_png()
|
||||
type_pic = type_pic.convert('RGBA').resize((40, 40))
|
||||
|
||||
food_pic = await get_assets_from_ambr(data['images']['nameicon'])
|
||||
if food_pic is None:
|
||||
food_pic = Image.new('RGBA', (320, 320))
|
||||
else:
|
||||
food_pic = food_pic.resize((320, 320))
|
||||
|
||||
bg = Image.open(TEXT_PATH / 'wiki_weapon_bg.jpg')
|
||||
img = await get_simple_bg(w, h, bg)
|
||||
img_draw = ImageDraw.Draw(img)
|
||||
|
||||
img.paste(type_pic, (49, 38), type_pic)
|
||||
img_draw.text((105, 59), data['name'], white_color, gs_font_44, 'lm')
|
||||
img.paste(star_pic, (45, 83), star_pic)
|
||||
|
||||
btag = Image.open(TEXT_PATH / 'btag.png')
|
||||
img.paste(btag, (50, 29), btag)
|
||||
|
||||
img.paste(food_pic, (140, 119), food_pic)
|
||||
img_draw.text((45, 465), '食物类型', gray_color, gs_font_18, 'lm')
|
||||
img_draw.text((45, 500), data['foodfilter'], white_color, gs_font_36, 'lm')
|
||||
|
||||
wiki_cost_tag = Image.open(TEXT_PATH / 'cost_tag.png')
|
||||
img.paste(wiki_cost_tag, (25, 550), wiki_cost_tag)
|
||||
|
||||
wiki_desc_tag = Image.open(TEXT_PATH / 'desc_tag.png')
|
||||
img.paste(wiki_desc_tag, (25, 570 + y1), wiki_desc_tag)
|
||||
|
||||
img_draw.text((90, 560), effect, gray_color, gs_font_22)
|
||||
img_draw.text((90, 580 + y1), desc, gray_color, gs_font_22)
|
||||
|
||||
wiki_cost_bg = Image.open(TEXT_PATH / 'wiki_weapon_cost.png')
|
||||
wiki_cost_draw = ImageDraw.Draw(wiki_cost_bg)
|
||||
|
||||
for index, cost in enumerate(data['ingredients']):
|
||||
cost_name = cost['name']
|
||||
material = await get_others_info('materials', cost_name)
|
||||
if isinstance(material, int):
|
||||
cost_pic = get_unknown_png()
|
||||
else:
|
||||
name_icon = material['images']['nameicon']
|
||||
_cost_pic = await get_assets_from_ambr(name_icon)
|
||||
if _cost_pic is None:
|
||||
cost_pic = get_unknown_png()
|
||||
else:
|
||||
cost_pic = _cost_pic.resize((64, 64))
|
||||
|
||||
t = 100 * index
|
||||
wiki_cost_bg.paste(cost_pic, (67 + t, 46), cost_pic)
|
||||
val = str(cost['count'])
|
||||
wiki_cost_draw.text((99 + t, 123), val, white_color, gs_font_18, 'mm')
|
||||
|
||||
img.paste(wiki_cost_bg, (0, 580 + y1 + y2), wiki_cost_bg)
|
||||
|
||||
img = img.convert('RGB')
|
||||
img.save(
|
||||
WIKI_FOOD_PATH / '{}.jpg'.format(data['name']),
|
||||
format='JPEG',
|
||||
quality=100,
|
||||
subsampling=0,
|
||||
)
|
||||
return await convert_img(img)
|
@ -57,6 +57,7 @@ async def get_weapons_wiki_img(name: str) -> Union[str, bytes]:
|
||||
|
||||
|
||||
async def draw_weapons_wiki_img(data: Weapon, stats: WeaponStats):
|
||||
spec_rank = ['孢囊晶尘', '荧光孢粉', '蕈兽孢子']
|
||||
gray_color = (214, 214, 214)
|
||||
img_test = Image.new('RGBA', (1, 1))
|
||||
img_test_draw = ImageDraw.Draw(img_test)
|
||||
@ -153,8 +154,17 @@ async def draw_weapons_wiki_img(data: Weapon, stats: WeaponStats):
|
||||
_i = name_temp[k].index(j['name'])
|
||||
temp[k][_i] += j['count']
|
||||
break
|
||||
elif j['name'] in spec_rank:
|
||||
if spec_rank[0] in temp:
|
||||
if j['name'] not in name_temp[spec_rank[0]]:
|
||||
name_temp[spec_rank[0]].append(j['name'])
|
||||
temp[spec_rank[0]].append(j['count'])
|
||||
else:
|
||||
_i = name_temp[spec_rank[0]].index(j['name'])
|
||||
temp[spec_rank[0]][_i] += j['count']
|
||||
break
|
||||
else:
|
||||
name_temp[j['name']] = [j['count']]
|
||||
name_temp[j['name']] = [j['name']]
|
||||
temp[j['name']] = [j['count']]
|
||||
|
||||
if data['rarity'] == '5':
|
||||
|
After Width: | Height: | Size: 852 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 871 B |
After Width: | Height: | Size: 750 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.6 KiB |
BIN
GenshinUID/genshinuid_wikitext/texture2D/btag.png
Normal file
After Width: | Height: | Size: 116 KiB |
BIN
GenshinUID/genshinuid_wikitext/texture2D/desc_tag.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
@ -89,6 +89,11 @@ def get_str_size(
|
||||
result = ''
|
||||
line = ''
|
||||
for i in r:
|
||||
if i == '\n':
|
||||
result += f'{line}\n'
|
||||
line = ''
|
||||
continue
|
||||
|
||||
line += i
|
||||
size, _ = font.getsize(line)
|
||||
if size >= limit:
|
||||
|
@ -26,6 +26,10 @@ REF_PATH = WIKI_PATH / 'ref'
|
||||
WIKI_REL_PATH = WIKI_PATH / 'artifacts'
|
||||
CONSTELLATION_PATH = WIKI_PATH / 'constellation'
|
||||
WIKI_WEAPON_PATH = WIKI_PATH / 'weapon'
|
||||
WIKI_FOOD_PATH = WIKI_PATH / 'food'
|
||||
WIKI_TALENT_PATH = WIKI_PATH / 'talent'
|
||||
WIKI_ENEMY_PATH = WIKI_PATH / 'enemy'
|
||||
WIKI_CHAR_PATH = WIKI_PATH / 'char'
|
||||
TEXT2D_PATH = Path(__file__).parent / 'texture2d'
|
||||
|
||||
PLAYER_PATH = MAIN_PATH / 'players'
|
||||
@ -56,6 +60,10 @@ def init_dir():
|
||||
WIKI_REL_PATH,
|
||||
CONSTELLATION_PATH,
|
||||
WIKI_WEAPON_PATH,
|
||||
WIKI_FOOD_PATH,
|
||||
WIKI_TALENT_PATH,
|
||||
WIKI_ENEMY_PATH,
|
||||
WIKI_CHAR_PATH,
|
||||
]:
|
||||
i.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
10
poetry.lock
generated
@ -550,18 +550,18 @@ wmi = ["wmi (>=1.5.1,<2.0.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "email-validator"
|
||||
version = "1.3.1"
|
||||
version = "2.0.0"
|
||||
description = "A robust email address syntax and deliverability validation library."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.5"
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "email_validator-1.3.1-py2.py3-none-any.whl", hash = "sha256:49a72f5fa6ed26be1c964f0567d931d10bf3fdeeacdf97bc26ef1cd2a44e0bda"},
|
||||
{file = "email_validator-1.3.1.tar.gz", hash = "sha256:d178c5c6fa6c6824e9b04f199cf23e79ac15756786573c190d2ad13089411ad2"},
|
||||
{file = "email_validator-2.0.0-py3-none-any.whl", hash = "sha256:07c61b62ee446e39274b18204afa8e422baf64570776045272b04d10c02f64f6"},
|
||||
{file = "email_validator-2.0.0.tar.gz", hash = "sha256:f4904f4145c11f8de5897afbb8d7db4b465c57f13db1c8c106c16d02bceebd9a"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
dnspython = ">=1.15.0"
|
||||
dnspython = ">=2.0.0"
|
||||
idna = ">=2.0.0"
|
||||
|
||||
[[package]]
|
||||
|
@ -13,7 +13,7 @@ certifi==2022.12.7 ; python_full_version >= "3.8.1" and python_full_version < "4
|
||||
charset-normalizer==3.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
colorama==0.4.6 ; python_full_version >= "3.8.1" and python_version < "4.0" and platform_system == "Windows" or python_full_version >= "3.8.1" and python_version < "4.0" and sys_platform == "win32"
|
||||
dnspython==2.3.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
email-validator==1.3.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
email-validator==2.0.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
et-xmlfile==1.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-amis-admin==0.5.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-user-auth==0.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
|