mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-05-30 04:00:31 +08:00
✨ draw_config_card.py
This commit is contained in:
parent
ceb2ee9082
commit
d1cac471f6
92
genshinuid_config/draw_config_card.py
Normal file
92
genshinuid_config/draw_config_card.py
Normal file
@ -0,0 +1,92 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
from nonebot.log import logger
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from .set_config import SWITCH_MAP
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.draw_image_tools.draw_image_tool import CustomizeImage
|
||||
from ..utils.genshin_fonts.genshin_fonts import genshin_font_origin
|
||||
from ..utils.db_operation.db_operation import (
|
||||
get_all_uid,
|
||||
config_check,
|
||||
get_all_cookie,
|
||||
get_all_stoken,
|
||||
)
|
||||
|
||||
TEXT_PATH = Path(__file__).parent / 'texture2d'
|
||||
config_title = Image.open(TEXT_PATH / 'config_title.png')
|
||||
config_on = Image.open(TEXT_PATH / 'config_on.png')
|
||||
config_off = Image.open(TEXT_PATH / 'config_off.png')
|
||||
|
||||
gs_font_36 = genshin_font_origin(36)
|
||||
gs_font_40 = genshin_font_origin(40)
|
||||
gs_font_24 = genshin_font_origin(24)
|
||||
|
||||
first_color = (20, 20, 20)
|
||||
second_color = (57, 57, 57)
|
||||
|
||||
DETAIL_MAP = {
|
||||
'米游币推送': '开启后会私聊每个用户当前米游币任务完成情况',
|
||||
'简洁签到报告': '开启后可以大大减少每日签到报告字数 ',
|
||||
'私聊报告': '关闭后将不再给主人推送当天米游币任务完成情况',
|
||||
'随机图': '开启后[查询心海]等命令展示图将替换为随机图片',
|
||||
'定时签到': '开启后每晚00:30将开始自动签到任务',
|
||||
'定时米游币': '开启后每晚01:16将开始自动米游币任务',
|
||||
}
|
||||
|
||||
|
||||
async def draw_config_img() -> Union[bytes, str]:
|
||||
# 获取背景图片各项参数
|
||||
based_w = 850
|
||||
based_h = 850 + 155 * (len(SWITCH_MAP) - 3)
|
||||
|
||||
CI_img = CustomizeImage('', based_w, based_h)
|
||||
img = CI_img.bg_img
|
||||
color = CI_img.bg_color
|
||||
color_mask = Image.new('RGBA', (based_w, based_h), color)
|
||||
config_mask = Image.open(TEXT_PATH / 'config_mask.png').resize(
|
||||
(based_w, based_h)
|
||||
)
|
||||
img.paste(color_mask, (0, 0), config_mask)
|
||||
img.paste(config_title, (0, 0), config_title)
|
||||
img_draw = ImageDraw.Draw(img)
|
||||
|
||||
# 获取数据
|
||||
uid_list = await get_all_uid()
|
||||
cookie_list = await get_all_cookie()
|
||||
stoken_list = await get_all_stoken()
|
||||
|
||||
uid_num = len(uid_list)
|
||||
cookie_num = len(cookie_list)
|
||||
stoken_num = len(stoken_list)
|
||||
img_draw.text((210, 600), str(uid_num), first_color, gs_font_40, 'mm')
|
||||
img_draw.text((431, 600), str(cookie_num), first_color, gs_font_40, 'mm')
|
||||
img_draw.text((651, 600), str(stoken_num), first_color, gs_font_40, 'mm')
|
||||
|
||||
tasks = []
|
||||
for index, name in enumerate(DETAIL_MAP):
|
||||
tasks.append(_draw_config_line(img, name, index))
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
res = await convert_img(img)
|
||||
logger.info('[查询配置信息]绘图已完成,等待发送!')
|
||||
return res
|
||||
|
||||
|
||||
async def _draw_config_line(img: Image.Image, name: str, index: int):
|
||||
detail = DETAIL_MAP[name]
|
||||
switch_name = SWITCH_MAP[name]
|
||||
config_line = Image.open(TEXT_PATH / 'config_line.png')
|
||||
config_line_draw = ImageDraw.Draw(config_line)
|
||||
if name.startswith('定时'):
|
||||
name += '(全部)'
|
||||
config_line_draw.text((52, 46), name, first_color, gs_font_36, 'lm')
|
||||
config_line_draw.text((52, 80), detail, second_color, gs_font_24, 'lm')
|
||||
if await config_check(switch_name):
|
||||
config_line.paste(config_on, (613, 21), config_on)
|
||||
else:
|
||||
config_line.paste(config_off, (613, 21), config_off)
|
||||
img.paste(config_line, (26, 850 + index * 155), config_line)
|
@ -18,6 +18,8 @@ SWITCH_MAP = {
|
||||
'简洁签到报告': 'SignReportSimple',
|
||||
'私聊报告': 'PrivateReport',
|
||||
'随机图': 'RandomPic',
|
||||
'定时签到': 'SchedSignin',
|
||||
'定时米游币': 'SchedMhyBBSCoin',
|
||||
}
|
||||
|
||||
PUSH_MAP = {
|
||||
|
BIN
genshinuid_config/texture2d/config_line.png
Normal file
BIN
genshinuid_config/texture2d/config_line.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
BIN
genshinuid_config/texture2d/config_mask.png
Normal file
BIN
genshinuid_config/texture2d/config_mask.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 53 KiB |
BIN
genshinuid_config/texture2d/config_off.png
Normal file
BIN
genshinuid_config/texture2d/config_off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
genshinuid_config/texture2d/config_on.png
Normal file
BIN
genshinuid_config/texture2d/config_on.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
genshinuid_config/texture2d/config_title.png
Normal file
BIN
genshinuid_config/texture2d/config_title.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 155 KiB |
@ -64,6 +64,36 @@ class CookiesDAL:
|
||||
else:
|
||||
return '该用户没有绑定过Stoken噢~'
|
||||
|
||||
async def get_all_cookie_list(self) -> List[str]:
|
||||
"""
|
||||
:说明:
|
||||
获得所有Cookies列表
|
||||
:返回:
|
||||
* ck_list (List[str]): Cookie列表。
|
||||
"""
|
||||
sql = select(NewCookiesTable).where(NewCookiesTable.Cookies != '')
|
||||
result = await self.db_session.execute(sql) # type: ignore
|
||||
data = result.scalars().all()
|
||||
ck_list = []
|
||||
for item in data:
|
||||
ck_list.append(item.Cookies)
|
||||
return ck_list
|
||||
|
||||
async def get_all_stoken_list(self) -> List[str]:
|
||||
"""
|
||||
:说明:
|
||||
获得所有Stoken列表
|
||||
:返回:
|
||||
* sk_list (List[str]): stoken列表。
|
||||
"""
|
||||
sql = select(NewCookiesTable).where(NewCookiesTable.Stoken != '')
|
||||
result = await self.db_session.execute(sql) # type: ignore
|
||||
data = result.scalars().all()
|
||||
sk_list = []
|
||||
for item in data:
|
||||
sk_list.append(item.Stoken)
|
||||
return sk_list
|
||||
|
||||
async def get_cache_ck(self, uid: str) -> Union[Column[str], str, None]:
|
||||
"""
|
||||
:说明:
|
||||
|
@ -66,6 +66,22 @@ async def get_all_uid() -> List:
|
||||
return lst
|
||||
|
||||
|
||||
async def get_all_cookie() -> List:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
lst = await Cookies.get_all_cookie_list()
|
||||
return lst
|
||||
|
||||
|
||||
async def get_all_stoken() -> List:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
lst = await Cookies.get_all_stoken_list()
|
||||
return lst
|
||||
|
||||
|
||||
async def select_db(userid, mode='auto') -> Union[List, str, None]:
|
||||
"""
|
||||
:说明:
|
||||
|
BIN
utils/draw_image_tools/bg/defalut2.jpg
Normal file
BIN
utils/draw_image_tools/bg/defalut2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 710 KiB |
Loading…
x
Reference in New Issue
Block a user