mirror of
https://github.com/baiqwerdvd/StarRailUID.git
synced 2025-05-08 04:55:47 +08:00
✨完成很小一部分 sr开拓月历
的工作
This commit is contained in:
parent
ac22592318
commit
39d80a3e0a
@ -3,12 +3,10 @@ from gsuid_core.bot import Bot
|
|||||||
from gsuid_core.models import Event
|
from gsuid_core.models import Event
|
||||||
|
|
||||||
from .note_text import award
|
from .note_text import award
|
||||||
|
|
||||||
# from ..utils.convert import get_uid
|
|
||||||
from ..utils.api import get_sqla
|
from ..utils.api import get_sqla
|
||||||
|
from ..utils.convert import get_uid
|
||||||
from ..utils.error_reply import UID_HINT
|
from ..utils.error_reply import UID_HINT
|
||||||
|
from .draw_note_card import draw_note_img
|
||||||
# from .draw_note_card import draw_note_img
|
|
||||||
|
|
||||||
sv_get_monthly_data = SV('sr查询月历')
|
sv_get_monthly_data = SV('sr查询月历')
|
||||||
|
|
||||||
@ -23,11 +21,12 @@ async def send_monthly_data(bot: Bot, ev: Event):
|
|||||||
await bot.send(await award(sr_uid))
|
await bot.send(await award(sr_uid))
|
||||||
|
|
||||||
|
|
||||||
# @sv_get_monthly_data.on_fullmatch(('sr当前信息', 'srzj', 'sr月历'))
|
@sv_get_monthly_data.on_fullmatch(('sr开拓月历', 'srzj', 'sr月历'))
|
||||||
# async def send_monthly_pic(bot: Bot, ev: Event):
|
async def send_monthly_pic(bot: Bot, ev: Event):
|
||||||
# await bot.logger.info('开始执行[sr每日信息]')
|
await bot.logger.info('开始执行[sr开拓月历]')
|
||||||
# uid = await get_uid(bot, ev)
|
sr_uid = await get_uid(bot, ev)
|
||||||
# if uid is None:
|
if sr_uid is None:
|
||||||
# return UID_HINT
|
return UID_HINT
|
||||||
# im = await draw_note_img(str(uid))
|
im = await draw_note_img(str(sr_uid))
|
||||||
# await bot.send(im)
|
im = 'WIP 还妹写完'
|
||||||
|
await bot.send(im)
|
||||||
|
229
StarRailUID/starrailuid_note/draw_note_card.py
Normal file
229
StarRailUID/starrailuid_note/draw_note_card.py
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from PIL import Image, ImageDraw
|
||||||
|
from gsuid_core.logger import logger
|
||||||
|
|
||||||
|
from ..utils.mys_api import mys_api
|
||||||
|
from ..utils.error_reply import get_error
|
||||||
|
from ..utils.image.convert import convert_img
|
||||||
|
from ..utils.fonts.starrail_fonts import sr_font_20, sr_font_28, sr_font_34
|
||||||
|
|
||||||
|
TEXT_PATH = Path(__file__).parent / 'texture2d'
|
||||||
|
|
||||||
|
monthly_bg = Image.open(TEXT_PATH / 'monthly_bg.png')
|
||||||
|
avatar_default = Image.open(TEXT_PATH / '200101.png')
|
||||||
|
|
||||||
|
first_color = (29, 29, 29)
|
||||||
|
second_color = (67, 61, 56)
|
||||||
|
second_color2 = (98, 98, 98)
|
||||||
|
black_color = (54, 54, 54)
|
||||||
|
|
||||||
|
COLOR_MAP = {
|
||||||
|
'每日活跃': (248, 227, 157),
|
||||||
|
'活动奖励': (99, 231, 176),
|
||||||
|
'冒险奖励': (114, 205, 251),
|
||||||
|
'模拟宇宙奖励': (160, 149, 248),
|
||||||
|
'忘却之庭奖励': (221, 119, 250),
|
||||||
|
'邮件奖励': (244, 110, 104),
|
||||||
|
'其他': (255, 242, 200),
|
||||||
|
'Daily Activity': (248, 227, 157),
|
||||||
|
'Events': (99, 231, 176),
|
||||||
|
'Adventure': (114, 205, 251),
|
||||||
|
'moni': (160, 149, 248),
|
||||||
|
'Spiral Abyss': (221, 119, 250),
|
||||||
|
'Quests': (244, 110, 104),
|
||||||
|
'Other': (255, 242, 200),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def draw_note_img(sr_uid: str) -> Union[bytes, str]:
|
||||||
|
# 获取数据
|
||||||
|
data = await mys_api.get_award(sr_uid)
|
||||||
|
if isinstance(data, int):
|
||||||
|
return get_error(data)
|
||||||
|
# nickname and level
|
||||||
|
role_basic_info = await mys_api.get_role_basic_info(sr_uid)
|
||||||
|
if isinstance(role_basic_info, int):
|
||||||
|
return get_error(role_basic_info)
|
||||||
|
nickname = role_basic_info['nickname']
|
||||||
|
|
||||||
|
day_hcoin = data['day_data']['current_hcoin']
|
||||||
|
day_rails_pass = data['day_data']['current_rails_pass']
|
||||||
|
lastday_hcoin = 0
|
||||||
|
lastday_rails_pass = 0
|
||||||
|
if int(sr_uid[0]) < 6:
|
||||||
|
lastday_hcoin = data['day_data']['last_hcoin']
|
||||||
|
lastday_rails_pass = data['day_data']['last_rails_pass']
|
||||||
|
month_hcoin = data['month_data']['current_hcoin']
|
||||||
|
month_rails_pass = data['month_data']['current_rails_pass']
|
||||||
|
lastmonth_hcoin = data['month_data']['last_hcoin']
|
||||||
|
# lastmonth_rails_pass = data['month_data']['last_rails_pass']
|
||||||
|
|
||||||
|
day_hcoin_str = await int_carry(day_hcoin)
|
||||||
|
# day_rails_pass_str = await int_carry(day_rails_pass)
|
||||||
|
# month_hcoin_str = await int_carry(month_hcoin)
|
||||||
|
# month_rails_pass_str = await int_carry(month_rails_pass)
|
||||||
|
# lastday_stone_str = f'昨日星琼:{await int_carry(lastday_hcoin)}'
|
||||||
|
# lastday_mora_str = f'昨日星轨通票&星轨专票:' \
|
||||||
|
# f'{await int_carry(lastday_rails_pass)}'
|
||||||
|
# lastmonth_stone_str = f'上月星琼:{await int_carry(lastmonth_hcoin)}'
|
||||||
|
# lastmonth_mora_str = f'上月星轨通票&星轨专票:' \
|
||||||
|
# f'{await int_carry(lastmonth_rails_pass)}'
|
||||||
|
|
||||||
|
# 处理数据
|
||||||
|
# 今日比昨日 星琼
|
||||||
|
day_hcoin_percent = day_hcoin / lastday_hcoin if lastday_hcoin != 0 else 1
|
||||||
|
day_hcoin_percent = day_hcoin_percent if day_hcoin_percent <= 1 else 1
|
||||||
|
# 今日比昨日 星轨通票&星轨专票
|
||||||
|
day_rails_pass_percent = (
|
||||||
|
day_rails_pass / lastday_rails_pass if lastday_rails_pass != 0 else 1
|
||||||
|
)
|
||||||
|
day_rails_pass_percent = (
|
||||||
|
day_rails_pass_percent if day_rails_pass_percent <= 1 else 1
|
||||||
|
)
|
||||||
|
# 本月比上月 星琼
|
||||||
|
month_hcoin_percent = (
|
||||||
|
month_hcoin / lastmonth_hcoin if lastmonth_hcoin != 0 else 1
|
||||||
|
)
|
||||||
|
month_hcoin_percent = (
|
||||||
|
month_hcoin_percent if month_hcoin_percent <= 1 else 1
|
||||||
|
)
|
||||||
|
# 本月比上月 星轨通票&星轨专票
|
||||||
|
month_rails_pass_percent = (
|
||||||
|
month_rails_pass / month_rails_pass if month_rails_pass != 0 else 1
|
||||||
|
)
|
||||||
|
month_rails_pass_percent = (
|
||||||
|
month_rails_pass_percent if month_rails_pass_percent <= 1 else 1
|
||||||
|
)
|
||||||
|
|
||||||
|
# # 获取背景图片各项参数
|
||||||
|
# based_w = 700
|
||||||
|
# based_h = 1300
|
||||||
|
|
||||||
|
img = monthly_bg.copy()
|
||||||
|
avatar_img = avatar_default.copy()
|
||||||
|
char_pic = avatar_img.convert('RGBA').resize(
|
||||||
|
(125, 125), Image.Resampling.LANCZOS # type: ignore
|
||||||
|
)
|
||||||
|
img.paste(char_pic, (115, 133), char_pic)
|
||||||
|
img_draw = ImageDraw.Draw(img)
|
||||||
|
|
||||||
|
# 写Nickname
|
||||||
|
img_draw.text(
|
||||||
|
(310, 183), nickname, font=sr_font_34, fill=first_color, anchor='lm'
|
||||||
|
)
|
||||||
|
|
||||||
|
# 写UID
|
||||||
|
img_draw.text(
|
||||||
|
(300, 215),
|
||||||
|
f'UID {sr_uid}',
|
||||||
|
font=sr_font_20,
|
||||||
|
fill=second_color2,
|
||||||
|
anchor='lm',
|
||||||
|
)
|
||||||
|
|
||||||
|
# 写本日星琼
|
||||||
|
img_draw.text(
|
||||||
|
(300, 260),
|
||||||
|
day_hcoin_str,
|
||||||
|
font=sr_font_28,
|
||||||
|
fill=second_color2,
|
||||||
|
anchor='lm',
|
||||||
|
)
|
||||||
|
|
||||||
|
# 写本月星琼
|
||||||
|
img_draw.text(
|
||||||
|
(300, 260),
|
||||||
|
day_hcoin_str,
|
||||||
|
font=sr_font_28,
|
||||||
|
fill=second_color2,
|
||||||
|
anchor='lm',
|
||||||
|
)
|
||||||
|
|
||||||
|
# 写本日星琼
|
||||||
|
img_draw.text(
|
||||||
|
(300, 260),
|
||||||
|
day_hcoin_str,
|
||||||
|
font=sr_font_28,
|
||||||
|
fill=second_color2,
|
||||||
|
anchor='lm',
|
||||||
|
)
|
||||||
|
|
||||||
|
# 写本日星琼
|
||||||
|
img_draw.text(
|
||||||
|
(300, 260),
|
||||||
|
day_hcoin_str,
|
||||||
|
font=sr_font_28,
|
||||||
|
fill=second_color2,
|
||||||
|
anchor='lm',
|
||||||
|
)
|
||||||
|
|
||||||
|
ring_pic = Image.open(TEXT_PATH / 'ring.apng')
|
||||||
|
ring_list = []
|
||||||
|
ring_list.append([int(day_hcoin_percent * 89 + 0.5), (-5, 475)])
|
||||||
|
ring_list.append([int(day_rails_pass_percent * 89 + 0.5), (371, 475)])
|
||||||
|
ring_list.append([int(month_hcoin_percent * 89 + 0.5), (-5, 948)])
|
||||||
|
ring_list.append([int(month_rails_pass_percent * 89 + 0.5), (371, 948)])
|
||||||
|
ring_list.sort(key=lambda x: -x[0], reverse=True)
|
||||||
|
print(ring_list)
|
||||||
|
for i in ring_list:
|
||||||
|
ring_pic.seek(i[0])
|
||||||
|
img.paste(ring_pic, i[1], ring_pic)
|
||||||
|
|
||||||
|
# 具体数据
|
||||||
|
# img_draw.text((243, 718), str(day_hcoin_percent),
|
||||||
|
# first_color, sr_font_58, 'mm')
|
||||||
|
# img_draw.text((625, 718), str(day_rails_pass_percent),
|
||||||
|
# first_color, sr_font_58, 'mm')
|
||||||
|
# img_draw.text((245, 1192), str(month_hcoin_str),
|
||||||
|
# first_color, sr_font_58, 'mm')
|
||||||
|
# img_draw.text((621, 1192), str(month_rails_pass_str),
|
||||||
|
# first_color, sr_font_58, 'mm')
|
||||||
|
#
|
||||||
|
# img_draw.text(
|
||||||
|
# (245, 923), lastday_stone_str, second_color, sr_font_26, 'mm'
|
||||||
|
# )
|
||||||
|
# img_draw.text(
|
||||||
|
# (621, 923), lastday_mora_str, second_color, sr_font_26, 'mm'
|
||||||
|
# )
|
||||||
|
# img_draw.text(
|
||||||
|
# (245, 1396), lastmonth_stone_str, second_color, sr_font_26, 'mm'
|
||||||
|
# )
|
||||||
|
# img_draw.text(
|
||||||
|
# (621, 1396), lastmonth_mora_str, second_color, sr_font_26, 'mm'
|
||||||
|
# )
|
||||||
|
|
||||||
|
if data['month_data']['group_by'] == []:
|
||||||
|
for index, action in enumerate(COLOR_MAP):
|
||||||
|
if action == '其他':
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
xy = ((139, 579), (347, 787))
|
||||||
|
temp = -90
|
||||||
|
for index, i in enumerate(data['month_data']['group_by']):
|
||||||
|
img_draw.pieslice(
|
||||||
|
xy,
|
||||||
|
temp,
|
||||||
|
temp + (i['percent'] / 100) * 360,
|
||||||
|
COLOR_MAP[i['action_name']],
|
||||||
|
)
|
||||||
|
temp = temp + (i['percent'] / 100) * 360
|
||||||
|
if i['action'] == '其他':
|
||||||
|
continue
|
||||||
|
img_draw.rectangle(
|
||||||
|
((407, 1523 + index * 52), (453, 1548 + index * 52)),
|
||||||
|
fill=COLOR_MAP[i['action_name']],
|
||||||
|
)
|
||||||
|
|
||||||
|
img = await convert_img(img)
|
||||||
|
logger.info('[开拓月历] 图片绘制完成!等待发送...')
|
||||||
|
return img
|
||||||
|
|
||||||
|
|
||||||
|
async def int_carry(i: int) -> str:
|
||||||
|
if i >= 100000:
|
||||||
|
i_str = '{:.1f}W'.format(i / 10000)
|
||||||
|
else:
|
||||||
|
i_str = str(i)
|
||||||
|
return i_str
|
BIN
StarRailUID/starrailuid_note/texture2d/ring.apng
Normal file
BIN
StarRailUID/starrailuid_note/texture2d/ring.apng
Normal file
Binary file not shown.
After Width: | Height: | Size: 784 KiB |
@ -33,11 +33,11 @@ async def send_daily_info(bot: Bot, ev: Event):
|
|||||||
@sv_get_resin_admin.on_fullmatch(('sr强制推送体力提醒'))
|
@sv_get_resin_admin.on_fullmatch(('sr强制推送体力提醒'))
|
||||||
async def force_notice_job(bot: Bot, ev: Event):
|
async def force_notice_job(bot: Bot, ev: Event):
|
||||||
await bot.logger.info('开始执行[sr强制推送体力信息]')
|
await bot.logger.info('开始执行[sr强制推送体力信息]')
|
||||||
await notice_job()
|
await sr_notice_job()
|
||||||
|
|
||||||
|
|
||||||
@scheduler.scheduled_job('cron', minute='*/30')
|
@scheduler.scheduled_job('cron', minute='*/30')
|
||||||
async def notice_job():
|
async def sr_notice_job():
|
||||||
result = await get_notice_list()
|
result = await get_notice_list()
|
||||||
logger.info('[sr推送检查]完成!等待消息推送中...')
|
logger.info('[sr推送检查]完成!等待消息推送中...')
|
||||||
logger.debug(result)
|
logger.debug(result)
|
||||||
|
@ -21,6 +21,7 @@ sr_font_26 = starrail_font_origin(26)
|
|||||||
sr_font_28 = starrail_font_origin(28)
|
sr_font_28 = starrail_font_origin(28)
|
||||||
sr_font_30 = starrail_font_origin(30)
|
sr_font_30 = starrail_font_origin(30)
|
||||||
sr_font_32 = starrail_font_origin(32)
|
sr_font_32 = starrail_font_origin(32)
|
||||||
|
sr_font_34 = starrail_font_origin(34)
|
||||||
sr_font_36 = starrail_font_origin(36)
|
sr_font_36 = starrail_font_origin(36)
|
||||||
sr_font_38 = starrail_font_origin(38)
|
sr_font_38 = starrail_font_origin(38)
|
||||||
sr_font_40 = starrail_font_origin(40)
|
sr_font_40 = starrail_font_origin(40)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user