Skip to content

Commit

Permalink
✨ 新增ba绑定好友码ba查询
Browse files Browse the repository at this point in the history
  • Loading branch information
KimigaiiWuyi committed Apr 2, 2024
1 parent af2a403 commit 4b486ac
Show file tree
Hide file tree
Showing 38 changed files with 2,545 additions and 5 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,8 @@ FodyWeavers.xsd
### CI ###
result.txt

### GenshinUID ###
*.xlsx
all_image
### BADATA ###
SchaleDB

### Debug ###
testnb2/
31 changes: 31 additions & 0 deletions BlueArchiveUID/bauid_info/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from gsuid_core.sv import SV
from gsuid_core.bot import Bot
from gsuid_core.models import Event
from gsuid_core.utils.database.api import get_uid

from ..utils.database.models import BaBind
from .draw_user_info_pic import draw_user_info_img

ba_user_info = SV('ba用户信息')


@ba_user_info.on_command(('ba查询'), block=True)
async def send_ba_user_info(bot: Bot, ev: Event):
fcode, user_id = await get_uid(
bot, ev, BaBind, partten=r'[A-Za-z0-9::]+', get_user_id=True
)

if not fcode:
return await bot.send(
'未绑定好友码, 请先使用[ba绑定vlhy4mw]绑定好友码...\n如需临时查询,请使用[ba查询vlhy4mw:1]'
)

fcode = fcode.replace(':', ':')

if ':' not in fcode or not fcode.endswith(('1', '2')):
return await bot.send(
'好友码需在末尾携带:符号以确认服务器\n:1为官服,:2为b服\n例如ba查询vlhy4mw:1即为查询官服vlhy4mw好友码'
)

im = await draw_user_info_img(fcode, ev, user_id)
await bot.send(im)
240 changes: 240 additions & 0 deletions BlueArchiveUID/bauid_info/draw_user_info_pic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
from pathlib import Path
from typing import Union

from PIL import Image, ImageDraw
from gsuid_core.models import Event
from gsuid_core.utils.image.convert import convert_img
from gsuid_core.utils.fonts.fonts import core_font as cf
from gsuid_core.utils.image.image_tools import (
crop_center_img,
get_event_avatar,
draw_pic_with_ring,
)

from ..utils.ba_api import xtzx_api
from ..utils.error_reply import get_error
from ..utils.resource_path import (
SKILL_ICON_PATH,
WEAPON_ICON_PATH,
EQUIPMENT_ICON_PATH,
STUDENT_COLLECTION_PATH,
)
from ..utils.ba_map import (
equipId2Icon,
weaponId2Nmae,
studentId2Name,
studentId2Type,
studentSkill2Icon,
studentId2weaponIcon,
)

TEXT_PATH = Path(__file__).parent / 'texture2d'
BLACK = (37, 37, 37)
GREY = (95, 102, 110)
weapon_star_full = Image.open(TEXT_PATH / 'weapon_star_full.png')
weapon_star_empty = Image.open(TEXT_PATH / 'weapon_star_empty.png')
footer = Image.open(TEXT_PATH / 'footer.png')

COLOR_MAP = {
'explosion': (144, 1, 8),
'pierce': (218, 160, 39),
'mystic': (34, 111, 155),
'sonic': (103, 79, 167),
}


async def draw_user_info_img(
_fcode: str, ev: Event, user_id: str
) -> Union[str, bytes]:
fcode, server = _fcode.split(':')
data = await xtzx_api.get_xtzx_friend_data(fcode, server)

if isinstance(data, int):
return get_error(data)

w, h = 1100, 2880
img = crop_center_img(Image.open(TEXT_PATH / 'bg.jpg'), w, h)
img = img.convert('RGBA')

title = Image.open(TEXT_PATH / 'title.png')
title_draw = ImageDraw.Draw(title)
avatar = await get_event_avatar(ev)
avatar = await draw_pic_with_ring(avatar, 308)
title.paste(avatar, (396, 57), avatar)
title_draw.text((550, 432), f'UserID: {user_id}', BLACK, cf(30), 'mm')

img.paste(title, (0, 0), title)

bar1 = Image.open(TEXT_PATH / 'bar.png')
bar2 = Image.open(TEXT_PATH / 'bar.png')
bar3 = Image.open(TEXT_PATH / 'bar.png')
bar1draw = ImageDraw.Draw(bar1)
bar2draw = ImageDraw.Draw(bar2)
bar3draw = ImageDraw.Draw(bar3)
bar1draw.text((550, 40), '基本信息', BLACK, cf(34), 'mm')
bar2draw.text((550, 40), '总力助战', BLACK, cf(34), 'mm')
bar3draw.text((550, 40), '演习助战', BLACK, cf(34), 'mm')

img.paste(bar1, (0, 475), bar1)
img.paste(bar2, (0, 865), bar2)
img.paste(bar3, (0, 1845), bar3)

avatar_card = Image.open(TEXT_PATH / 'avatar_card.png')

game_avatar_id = data['representCharacterUniqueId']
avatar_path = STUDENT_COLLECTION_PATH / f'{game_avatar_id}.webp'
game_avatar = Image.open(avatar_path).convert('RGBA')

game_nickname = data['nickname']
game_comment = data['comment']
game_level = str(data['level'])
friend_count = str(data['friendCount'])
count_str = f'好友数 {friend_count}/30'

avatar_card_draw = ImageDraw.Draw(avatar_card)
avatar_card.paste(game_avatar, (58, 87), game_avatar)

avatar_card_draw.text((308, 177), game_nickname, GREY, cf(44), 'lm')
avatar_card_draw.text((308, 284), game_comment, GREY, cf(28), 'lm')

avatar_card_draw.text((497, 118), count_str, BLACK, cf(25), 'mm')
avatar_card_draw.text((669, 118), f'{fcode}', BLACK, cf(25), 'mm')
avatar_card_draw.text((816, 118), f'等级{game_level}', BLACK, cf(25), 'mm')

img.paste(avatar_card, (0, 491), avatar_card)

assist_list = data['assistInfoList']

_assist_list = []
for i in assist_list:
if i['echelonType'] == 2:
_assist_list.append(i)
else:
while len(_assist_list) < 2:
_assist_list.append({})
for i in assist_list:
if i['echelonType'] == 15:
_assist_list.append(i)
else:
while len(_assist_list) < 4:
_assist_list.append({})

for index, assist in enumerate(_assist_list):
assist_card = Image.open(TEXT_PATH / 'assist_bg.png')
if assist:
assist_draw = ImageDraw.Draw(assist_card)

student_id = assist['uniqueId']
student_star = assist['starGrade']
student_level = assist['level']
student_star_pic = Image.open(
TEXT_PATH / f'star{student_star}.png'
)
student_star_pic = student_star_pic.convert('RGBA')
student_name = studentId2Name[str(student_id)]
student_type = studentId2Type[str(student_id)]

student_pic = Image.open(
STUDENT_COLLECTION_PATH / f'{student_id}.webp'
)
student_color = COLOR_MAP[student_type]
student_color_pic = Image.new(
'RGBA', student_pic.size, student_color
)

favor_rank = assist['favorRank']
ex = assist['exSkillLevel']
nm = assist['publicSkillLevel']
ps = assist['passiveSkillLevel']
sub = assist['extraPassiveSkillLevel']

skill_data = {
'ex': ex,
'nm': nm,
'ps': ps,
'sub': sub,
}
for sindex, s in enumerate(skill_data):
skill_bg = Image.open(
TEXT_PATH / f'{student_type}_skill_bg.png'
)
skill_draw = ImageDraw.Draw(skill_bg)

skill_icon = studentSkill2Icon[str(student_id)][s]
skill_path = SKILL_ICON_PATH / f'{skill_icon}.webp'
skill_pic = Image.open(skill_path).resize((36, 38))

skill = skill_data[s] if skill_data[s] != 10 else 'M'
skill_bg.paste(skill_pic, (25, 21), skill_pic)
skill_draw.text((71, 40), f'等级{skill}', GREY, cf(34), 'lm')
assist_card.paste(skill_bg, (312 + 172 * sindex, 96), skill_bg)

assist_card.paste(student_color_pic, (66, 108), student_pic)
assist_card.paste(student_pic, (68, 96), student_pic)
assist_card.paste(student_star_pic, (228, 390), student_star_pic)
assist_draw.text((146, 364), student_name, GREY, cf(32), 'mm')
assist_draw.text(
(251, 361), str(favor_rank), 'white', cf(25), 'mm'
)
assist_draw.text(
(151, 414), f'等级{student_level}', BLACK, cf(25), 'mm'
)

weapon_bg = Image.open(TEXT_PATH / 'weapon_bar.png')
if assist['weapon']:
weapon_draw = ImageDraw.Draw(weapon_bg)

weapon_star = assist['weaponStartGrade']
weapon_name = weaponId2Nmae[str(student_id)]
weapon_level = assist['weaponLevel']
weapon_icon_id = studentId2weaponIcon[str(student_id)]
weapon_path = WEAPON_ICON_PATH / f'{weapon_icon_id}.webp'
weapon_icon = Image.open(weapon_path).resize((400, 102))

weapon_bg.paste(weapon_icon, (11, 42), weapon_icon)
weapon_draw.text(
(470, 70), f'等级{weapon_level}', BLACK, cf(25), 'mm'
)
weapon_draw.text((486, 115), weapon_name, BLACK, cf(38), 'lm')

for i in range(5):
if i < weapon_star:
star_pic = weapon_star_full
else:
star_pic = weapon_star_empty
weapon_bg.paste(star_pic, (227 + 29 * i, 110), star_pic)

assist_card.paste(weapon_bg, (275, 147), weapon_bg)

equip_fg = Image.open(TEXT_PATH / 'equip_fg.png')
for eindex, equip in enumerate(assist['equipment']):
equip_bg = Image.open(TEXT_PATH / 'equip_bg.png')
equip_id = equip['UniqueId']
equip_icon = equipId2Icon[str(equip_id)]
equip_pic = Image.open(
EQUIPMENT_ICON_PATH / f'{equip_icon}.webp'
)
equip_level = equip['Level']
# equip_tier = equip['Tier']

equip_bg.paste(equip_pic, (2, 17), equip_pic)
equip_bg.paste(equip_fg, (0, 0), equip_fg)
equip_bg_draw = ImageDraw.Draw(equip_bg)
equip_bg_draw.text(
(75, 124),
f'等级{equip_level}',
'white',
cf(24),
'mm',
)
assist_card.paste(
equip_bg, (304 + eindex * 131, 306), equip_bg
)

x = 80 if index >= 2 else 0
img.paste(assist_card, (0, 884 + 450 * index + x), assist_card)

img.paste(footer, (0, h - 50), footer)
im = await convert_img(img)

return im
Binary file added BlueArchiveUID/bauid_info/texture2d/assist_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/equip_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/equip_fg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/footer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/star1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/star2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/star3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/star4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/star5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BlueArchiveUID/bauid_info/texture2d/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions BlueArchiveUID/bauid_user/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from gsuid_core.sv import SV
from gsuid_core.bot import Bot
from gsuid_core.models import Event
from gsuid_core.utils.message import send_diff_msg

from ..utils.database.models import BaBind

ba_user_bind = SV('ba用户绑定')


@ba_user_bind.on_command(
(
'ba绑定uid',
'ba绑定UID',
'ba绑定',
'ba好友码',
'ba切换uid',
'ba切换UID',
'ba切换',
'ba删除uid',
'ba删除UID',
'ba删除',
),
block=True,
)
async def send_ba_bind_uid_msg(bot: Bot, ev: Event):
uid = (
ev.text.strip()
.replace(':', ':')
.replace('好友', '')
.replace('码', '')
)

if not uid:
return await bot.send('该命令需要带上正确的好友码!')

if ':' not in uid or not uid.endswith(('1', '2')):
return await bot.send(
'好友码需在末尾携带:符号以确认服务器\n:1为官服,:2为b服\n例如ba绑定vlhy4mw:1即为绑定官服vlhy4mw好友码'
)

await bot.logger.info('[Ba] 开始执行[绑定/解绑用户信息]')
qid = ev.user_id
await bot.logger.info('[Ba] [绑定/解绑]UserID: {}'.format(qid))

if '绑定' in ev.command:
data = await BaBind.insert_uid(
qid, ev.bot_id, uid, ev.group_id, is_digit=False
)
return await send_diff_msg(
bot,
data,
{
0: f'[Ba] 绑定好友码{uid}成功!如绑定错误需删除,请使用命令:ba删除好友码',
-1: f'[Ba] 好友码{uid}的位数不正确!',
-2: f'[Ba] 好友码{uid}已经绑定过了!',
-3: '[Ba] 你输入了错误的格式!',
},
)
elif '切换' in ev.command:
retcode = await BaBind.switch_uid_by_game(qid, ev.bot_id, uid)
if retcode == 0:
return await bot.send(f'[Ba] 切换好友码{uid}成功!')
else:
return await bot.send(f'[Ba] 尚未绑定该好友码{uid}')
else:
data = await BaBind.delete_uid(qid, ev.bot_id, uid)
return await send_diff_msg(
bot,
data,
{
0: f'[Ba] 删除好友码{uid}成功!',
-1: f'[Ba] 该好友码{uid}不在已绑定列表中!',
},
)
Loading

0 comments on commit 4b486ac

Please sign in to comment.