-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f66c9bf
commit 993af24
Showing
8 changed files
with
322 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from gsuid_core.sv import SV | ||
from gsuid_core.bot import Bot | ||
from gsuid_core.models import Event | ||
|
||
from .draw_rank_pic import draw_rank_pic | ||
|
||
sv_ba_xtzx_rank = SV('BA什亭之匣学生排行榜') | ||
|
||
|
||
@sv_ba_xtzx_rank.on_command(('ba学生排行')) | ||
async def send_rank_msg(bot: Bot, ev: Event): | ||
await bot.send(await draw_rank_pic(ev.text.strip())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from pathlib import Path | ||
from typing import Union | ||
|
||
from PIL import Image, ImageDraw | ||
from gsuid_core.utils.image.convert import convert_img | ||
from gsuid_core.utils.fonts.fonts import core_font as cf | ||
|
||
from ..utils.ba_api import xtzx_api | ||
from ..utils.error_reply import get_error | ||
from ..utils.ba_map import student_name_to_id | ||
from ..bauid_info.draw_user_info_pic import BLACK, get_bg, draw_assist_card | ||
|
||
TEXT_PATH = Path(__file__).parent / 'texture2d' | ||
|
||
|
||
def get_color(rank_key: int): | ||
if rank_key < 10: | ||
rank_color = (235, 126, 163) | ||
elif rank_key < 80: | ||
rank_color = (235, 177, 129) | ||
elif rank_key < 200: | ||
rank_color = (151, 129, 235) | ||
else: | ||
rank_color = (202, 235, 129) | ||
return rank_color | ||
|
||
|
||
async def draw_rank_pic(student: str) -> Union[bytes, str]: | ||
student_id = student_name_to_id(student) | ||
if student_id == '9999': | ||
return '要查询的角色不存在或别名未收录, 请尝试使用完整名字。' | ||
data = await xtzx_api.get_xtzx_friend_ranking(1, student_id) | ||
if isinstance(data, int): | ||
return get_error(data) | ||
teacher_data = data['records'] | ||
|
||
img = get_bg(1100, 2800) | ||
for index, teacher in enumerate(teacher_data): | ||
info = teacher['assistInfoList'][0] | ||
assist_card = await draw_assist_card(info) | ||
rank_key = info['baRank']['key'] | ||
rank_value = info['baRank']['value'] | ||
rank_str = f'{rank_key} / {rank_value}' | ||
|
||
global_rank_key = info['baGlobalRank']['key'] | ||
global_rank_value = info['baGlobalRank']['value'] | ||
global_rank_str = f'{global_rank_key} / {global_rank_value}' | ||
|
||
rank_color = get_color(rank_key) | ||
global_rank_color = get_color(global_rank_key) | ||
|
||
card = Image.open(TEXT_PATH / 'card.png') | ||
card_draw = ImageDraw.Draw(card) | ||
|
||
card_draw.text( | ||
(230, 52), | ||
f'{teacher["nickname"]}', | ||
BLACK, | ||
cf(40), | ||
'lm', | ||
) | ||
|
||
if teacher['server'] == 1: | ||
s_f = (136, 205, 242) | ||
s_t = '官服' | ||
else: | ||
s_f = (243, 143, 225) | ||
s_t = 'B服' | ||
|
||
card_draw.rounded_rectangle((50, 36, 124, 68), 30, s_f) | ||
card_draw.text( | ||
(87, 52), | ||
s_t, | ||
BLACK, | ||
cf(24), | ||
'mm', | ||
) | ||
|
||
card_draw.rounded_rectangle((632, 36, 780, 68), 30, rank_color) | ||
card_draw.rounded_rectangle((904, 36, 1052, 68), 30, global_rank_color) | ||
card_draw.text( | ||
(706, 52), | ||
rank_str, | ||
BLACK, | ||
cf(24), | ||
'mm', | ||
) | ||
card_draw.text( | ||
(978, 52), | ||
global_rank_str, | ||
BLACK, | ||
cf(24), | ||
'mm', | ||
) | ||
card.paste(assist_card, (0, 40), assist_card) | ||
|
||
img.paste(card, (0, 28 + index * 550), card) | ||
|
||
img = await convert_img(img) | ||
return img |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.