diff --git a/gsuid_core/help/draw_core_help.py b/gsuid_core/help/draw_core_help.py new file mode 100644 index 0000000..d4249f6 --- /dev/null +++ b/gsuid_core/help/draw_core_help.py @@ -0,0 +1,74 @@ +from pathlib import Path +from typing import Dict, Literal + +import aiofiles +from PIL import Image +from msgspec import json as msgjson + +from gsuid_core.help.utils import ICON +from gsuid_core.version import __version__ +from gsuid_core.help.model import PluginHelp +from gsuid_core.utils.plugins_config.gs_config import sp_config +from gsuid_core.help.draw_new_plugin_help import TEXT_PATH, get_new_help + +MASTER_HELP_DATA = Path(__file__).parent / 'master_help.json' +HELP_DATA = Path(__file__).parent / 'help.json' +help_mode: Literal['light', 'dark'] = sp_config.get_config('HelpMode').data + + +async def get_master_help_data() -> Dict[str, PluginHelp]: + async with aiofiles.open(MASTER_HELP_DATA, 'rb') as file: + return msgjson.decode(await file.read(), type=Dict[str, PluginHelp]) + + +async def get_help_data() -> Dict[str, PluginHelp]: + async with aiofiles.open(HELP_DATA, 'rb') as file: + return msgjson.decode(await file.read(), type=Dict[str, PluginHelp]) + + +async def draw_master_help(): + if help_mode == 'light': + item_bg = Image.open(TEXT_PATH / f'item_bg_{help_mode}.png') + need_cover = True + else: + item_bg = None + need_cover = False + + img = await get_new_help( + plugin_name='GsCore管理', + plugin_info={f'v{__version__}': ''}, + plugin_icon=Image.open(ICON), + plugin_help=await get_master_help_data(), + plugin_prefix='core', + item_bg=item_bg, + need_cover=need_cover, + help_mode=help_mode, + ) + return img + + +async def draw_core_help(): + from .utils import plugins_help + + help_data = await get_help_data() + help_data.update(plugins_help) # type: ignore + + if help_mode == 'light': + item_bg = Image.open(TEXT_PATH / f'item_bg_{help_mode}.png') + need_cover = True + else: + item_bg = None + need_cover = False + + img = await get_new_help( + plugin_name='GsCore', + plugin_info={f'v{__version__}': ''}, + plugin_icon=Image.open(ICON), + plugin_help=help_data, + plugin_prefix='', + item_bg=item_bg, + need_cover=need_cover, + help_mode=help_mode, + ) + + return img diff --git a/gsuid_core/help/draw_new_plugin_help.py b/gsuid_core/help/draw_new_plugin_help.py index b39ce6b..632780e 100644 --- a/gsuid_core/help/draw_new_plugin_help.py +++ b/gsuid_core/help/draw_new_plugin_help.py @@ -1,3 +1,4 @@ +import re import random from pathlib import Path from copy import deepcopy @@ -11,6 +12,7 @@ from gsuid_core.utils.fonts.fonts import core_font from gsuid_core.utils.image.convert import convert_img from gsuid_core.utils.plugins_config.gs_config import pic_gen_config from gsuid_core.utils.image.image_tools import ( + CustomizeImage, crop_center_img, draw_color_badge, ) @@ -39,6 +41,24 @@ def find_icon(name: str, icon_path: Path = ICON_PATH): return Image.open(_r) +def calculate_string_length(s: str): + total_length = 0 + result = '' + for char in s: + result += char + if '\u4e00' <= char <= '\u9fff': + total_length += 1 + elif re.match(r'[A-Za-z0-9]', char): + total_length += 0.5 + elif re.match(r'[^\w\s]', char): + total_length += 0.3 + + if total_length >= 8: + return result + else: + return result + + async def get_new_help( plugin_name: str, plugin_info: Dict[str, str], @@ -53,6 +73,8 @@ async def get_new_help( item_bg: Optional[Image.Image] = None, icon_path: Path = ICON_PATH, footer: Optional[Image.Image] = None, + column: int = 3, + need_cover: bool = False, enable_cache: bool = True, ): help_path = get_res_path('help') / f'{plugin_name}.jpg' @@ -66,11 +88,11 @@ async def get_new_help( return await convert_img(Image.open(help_path)) if banner_bg is None: - banner_bg = Image.open(TEXT_PATH / 'banner_bg.jpg') + banner_bg = Image.open(TEXT_PATH / f'banner_bg_{help_mode}.jpg') if help_bg is None: - help_bg = Image.open(TEXT_PATH / 'help_bg.jpg') + help_bg = Image.open(TEXT_PATH / f'bg_{help_mode}.jpg') if cag_bg is None: - cag_bg = Image.open(TEXT_PATH / 'cag_bg.png') + cag_bg = Image.open(TEXT_PATH / f'cag_bg_{help_mode}.png') if footer is None: footer = Image.open(TEXT_PATH / f'footer_{help_mode}.png') if item_bg is None: @@ -92,17 +114,13 @@ async def get_new_help( plugin_icon = plugin_icon.resize((128, 128)) # 准备计算整体帮助图大小 - w, h = 1545, 300 + footer.height + w, h = 120 + 475 * column, footer.height cag_num = len(plugin_help) - h += cag_num * 100 for cag in plugin_help: cag_data = plugin_help[cag]['data'] sv_num = len(cag_data) - h += (((sv_num - 1) // 3) + 1) * 175 - - # 基准图 - img = crop_center_img(help_bg, w, h) + h += (((sv_num - 1) // column) + 1) * 175 # 绘制banner banner_bg.paste(plugin_icon, (89, 88), plugin_icon) @@ -143,6 +161,46 @@ async def get_new_help( plugin_name_len += badge.width + 10 + bscale = w / banner_bg.size[0] + new_banner_h = int(banner_bg.size[1] * bscale) + new_cag_h = int(cag_bg.size[1] * bscale) + banner_bg = banner_bg.resize((w, new_banner_h)) + + h += new_banner_h + h += cag_num * new_cag_h + + # 基准图 + img = crop_center_img(help_bg, w, h) + if need_cover: + color = CustomizeImage.get_bg_color( + img, False if help_mode == 'dark' else True + ) + if help_mode == 'light': + add_color = 40 + max_color = 255 + c0 = color[0] + add_color + c0 = c0 if c0 < max_color else max_color + c1 = color[1] + add_color + c2 = color[2] + add_color + c1 = c1 if c1 < max_color else max_color + c2 = c2 if c2 < max_color else max_color + else: + add_color = -40 + max_color = 0 + c0 = color[0] + add_color + c0 = c0 if c0 > max_color else max_color + c1 = color[1] + add_color + c2 = color[2] + add_color + c1 = c1 if c1 > max_color else max_color + c2 = c2 if c2 > max_color else max_color + _color = (c0, c1, c2, 190) + _color_img = Image.new( + 'RGBA', + (w, h), + _color, + ) + img.paste(_color_img, (0, 0), _color_img) + img.paste(banner_bg, (0, 0), banner_bg) # 开始粘贴服务 @@ -171,7 +229,14 @@ async def get_new_help( font=core_font(30), anchor='lm', ) - img.paste(cag_bar, (0, 280 + hs), cag_bar) + + cag_bar = cag_bar.resize((w, new_cag_h)) + + img.paste( + cag_bar, + (0, int(new_banner_h + hs - 26 * bscale)), + cag_bar, + ) for i, command in enumerate(cag_data): command_name = command['name'] @@ -179,31 +244,50 @@ async def get_new_help( command_eg = command['eg'] command_bg = deepcopy(item_bg) - icon = find_icon(command_name, icon_path) + if 'icon' in command: + if isinstance(command['icon'], Image.Image): + icon: Image.Image = command['icon'] + else: + icon = Image.open(command['icon']) + else: + icon = find_icon(command_name, icon_path) + + if icon.width > 200: + icon = icon.resize((128, 128)) + _icon = Image.new('RGBA', (150, 150)) + _icon.paste(icon, (11, 11), icon) + icon = _icon + else: + icon = icon.resize((150, 150)) command_bg.paste(icon, (6, 12), icon) command_draw = ImageDraw.Draw(command_bg) + _command_name = calculate_string_length(command_name) + command_draw.text( - (160, 67), - plugin_prefix + command_name, + (156, 67), + _command_name, main_color, - font=core_font(40), + font=core_font(38), anchor='lm', ) command_draw.text( - (160, 116), + (156, 116), plugin_prefix + command_eg, sub_color, font=core_font(26), anchor='lm', ) - x, y = 45 + (i % 3) * 490, 370 + (i // 3) * 175 + hs + x, y = ( + 45 + (i % column) * 490, + int(new_banner_h + 70 * bscale + (i // column) * 175 + hs), + ) img.paste(command_bg, (x, y), command_bg) - hs += (((len(cag_data) - 1) // 3) + 1) * 175 + 100 + hs += (((len(cag_data) - 1) // column) + 1) * 175 + new_cag_h img.paste( footer, diff --git a/gsuid_core/help/help.json b/gsuid_core/help/help.json new file mode 100644 index 0000000..556e3fa --- /dev/null +++ b/gsuid_core/help/help.json @@ -0,0 +1,62 @@ +{ + "Mihomo账户登陆": { + "desc": "在执行查询之前请绑定账号", + "data": [ + { + "name": "扫码登陆", + "desc": "绑定自己的账户", + "eg": "扫码登陆", + "need_ck": false, + "need_sk": false, + "need_admin": false + }, + { + "name": "添加CK", + "desc": "手动添加CK, 仅限私聊", + "eg": "添加CK ltuid=xxx", + "need_ck": false, + "need_sk": false, + "need_admin": false + } + ] + }, + "MiHoMo账户管理": { + "desc": "在执行查询之前请绑定账号", + "data": [ + { + "name": "刷新CK", + "desc": "通过SK去刷新CK", + "eg": "刷新CK", + "need_ck": false, + "need_sk": false, + "need_admin": false + } + ] + }, + "设备绑定": { + "desc": "账户关联设备信息", + "data": [ + { + "name": "绑定设备", + "desc": "仅限私聊绑定设备", + "eg": "mys绑定设备", + "need_ck": true, + "need_sk": false, + "need_admin": false + } + ] + }, + "账户绑定检查": { + "desc": "账户关联设备信息", + "data": [ + { + "name": "绑定信息", + "desc": "检查自己在所有插件下的绑定信息", + "eg": "绑定信息", + "need_ck": false, + "need_sk": false, + "need_admin": false + } + ] + } + } diff --git a/gsuid_core/help/master_help.json b/gsuid_core/help/master_help.json new file mode 100644 index 0000000..618829b --- /dev/null +++ b/gsuid_core/help/master_help.json @@ -0,0 +1,147 @@ +{ + "管理插件": { + "desc": "安装/管理插件", + "data": [ + { + "name": "刷新插件列表", + "desc": "可以同步最新的插件列表", + "eg": "刷新插件列表", + "need_ck": false, + "need_sk": false, + "need_admin": true + }, + { + "name": "安装插件", + "desc": "安装插件", + "eg": "安装插件Pokemon", + "need_ck": false, + "need_sk": false, + "need_admin": true + }, + { + "name": "卸载插件", + "desc": "卸载插件", + "eg": "卸载插件Pokemon", + "need_ck": false, + "need_sk": false, + "need_admin": true + } + ] + }, + "更新插件": { + "desc": "更新插件", + "data": [ + { + "name": "更新插件", + "desc": "更新插件", + "eg": "更新插件Pokemon", + "need_ck": true, + "need_sk": false, + "need_admin": false + }, + { + "name": "强制更新插件", + "desc": "强制reset之后更新插件", + "eg": "强制更新插件", + "need_ck": false, + "need_sk": false, + "need_admin": false + }, + { + "name": "强行强制更新插件", + "desc": "强制reset+clean之后更新插件", + "eg": "强行强制更新插件", + "need_ck": false, + "need_sk": false, + "need_admin": false + } + ] + }, + "核心管理": { + "desc": "启停核心", + "data": [ + { + "name": "重启", + "desc": "重启核心", + "eg": "重启", + "need_ck": false, + "need_sk": false, + "need_admin": false + }, + { + "name": "关闭", + "desc": "警告:关闭后将无法通过命令调用", + "eg": "关闭", + "need_ck": true, + "need_sk": false, + "need_admin": false + }, + { + "name": "状态", + "desc": "查看目前核心的状态", + "eg": "状态", + "need_ck": false, + "need_sk": false, + "need_admin": false + } + ] + }, + "MiHoMo核心": { + "desc": "管理用户", + "data": [ + { + "name": "刷新全部CK", + "desc": "刷新全部用户的CK", + "eg": "刷新全部CK", + "need_ck": false, + "need_sk": false, + "need_admin": true + }, + { + "name": "校验全部CK", + "desc": "校验全部ck的状态", + "eg": "校验全部CK", + "need_ck": false, + "need_sk": false, + "need_admin": false + }, + { + "name": "校验全部SK", + "desc": "校验全部sk的状态", + "eg": "校验全部SK", + "need_ck": false, + "need_sk": false, + "need_admin": false + }, + { + "name": "清除无效用户", + "desc": "清理失效的用户", + "eg": "清除无效用户", + "need_ck": false, + "need_sk": false, + "need_admin": true + } + ] + }, + "杂项": { + "desc": "一些可能会有用的功能", + "data": [ + { + "name": "重置网页控制台密码", + "desc": "重置网页控制台密码", + "eg": "重置网页控制台密码", + "need_ck": false, + "need_sk": false, + "need_admin": false + }, + { + "name": "给我发消息", + "desc": "给主人发送一条主动消息", + "eg": "给我发消息", + "need_ck": true, + "need_sk": false, + "need_admin": false + } + ] + } + } diff --git a/gsuid_core/help/new_icon/CK.png b/gsuid_core/help/new_icon/CK.png new file mode 100644 index 0000000..46f3164 Binary files /dev/null and b/gsuid_core/help/new_icon/CK.png differ diff --git a/gsuid_core/help/new_icon/七圣.png b/gsuid_core/help/new_icon/七圣.png new file mode 100644 index 0000000..57292c7 Binary files /dev/null and b/gsuid_core/help/new_icon/七圣.png differ diff --git a/gsuid_core/help/new_icon/伤害.png b/gsuid_core/help/new_icon/伤害.png new file mode 100644 index 0000000..626192c Binary files /dev/null and b/gsuid_core/help/new_icon/伤害.png differ diff --git a/gsuid_core/help/new_icon/佳期.png b/gsuid_core/help/new_icon/佳期.png new file mode 100644 index 0000000..e5eb2f6 Binary files /dev/null and b/gsuid_core/help/new_icon/佳期.png differ diff --git a/gsuid_core/help/new_icon/充值.png b/gsuid_core/help/new_icon/充值.png new file mode 100644 index 0000000..93af319 Binary files /dev/null and b/gsuid_core/help/new_icon/充值.png differ diff --git a/gsuid_core/help/new_icon/全部重签.png b/gsuid_core/help/new_icon/全部重签.png new file mode 100644 index 0000000..fd1cbc9 Binary files /dev/null and b/gsuid_core/help/new_icon/全部重签.png differ diff --git a/gsuid_core/help/new_icon/公告.png b/gsuid_core/help/new_icon/公告.png new file mode 100644 index 0000000..52c719c Binary files /dev/null and b/gsuid_core/help/new_icon/公告.png differ diff --git a/gsuid_core/help/new_icon/关闭.png b/gsuid_core/help/new_icon/关闭.png new file mode 100644 index 0000000..a39bb24 Binary files /dev/null and b/gsuid_core/help/new_icon/关闭.png differ diff --git a/gsuid_core/help/new_icon/切换.png b/gsuid_core/help/new_icon/切换.png new file mode 100644 index 0000000..ffbcf49 Binary files /dev/null and b/gsuid_core/help/new_icon/切换.png differ diff --git a/gsuid_core/help/new_icon/删除.png b/gsuid_core/help/new_icon/删除.png new file mode 100644 index 0000000..cd72ae9 Binary files /dev/null and b/gsuid_core/help/new_icon/删除.png differ diff --git a/gsuid_core/help/new_icon/刷新.png b/gsuid_core/help/new_icon/刷新.png new file mode 100644 index 0000000..955776b Binary files /dev/null and b/gsuid_core/help/new_icon/刷新.png differ diff --git a/gsuid_core/help/new_icon/刷新CK.png b/gsuid_core/help/new_icon/刷新CK.png new file mode 100644 index 0000000..012a30d Binary files /dev/null and b/gsuid_core/help/new_icon/刷新CK.png differ diff --git a/gsuid_core/help/new_icon/刷新抽卡记录.png b/gsuid_core/help/new_icon/刷新抽卡记录.png new file mode 100644 index 0000000..ff61fd7 Binary files /dev/null and b/gsuid_core/help/new_icon/刷新抽卡记录.png differ diff --git a/gsuid_core/help/new_icon/刷新插件列表.png b/gsuid_core/help/new_icon/刷新插件列表.png new file mode 100644 index 0000000..f3ade41 Binary files /dev/null and b/gsuid_core/help/new_icon/刷新插件列表.png differ diff --git a/gsuid_core/help/new_icon/刷新面板.png b/gsuid_core/help/new_icon/刷新面板.png new file mode 100644 index 0000000..d55f327 Binary files /dev/null and b/gsuid_core/help/new_icon/刷新面板.png differ diff --git a/gsuid_core/help/new_icon/卡池.png b/gsuid_core/help/new_icon/卡池.png new file mode 100644 index 0000000..63266c8 Binary files /dev/null and b/gsuid_core/help/new_icon/卡池.png differ diff --git a/gsuid_core/help/new_icon/卡池列表.png b/gsuid_core/help/new_icon/卡池列表.png new file mode 100644 index 0000000..5daa9fe Binary files /dev/null and b/gsuid_core/help/new_icon/卡池列表.png differ diff --git a/gsuid_core/help/new_icon/卡组.png b/gsuid_core/help/new_icon/卡组.png new file mode 100644 index 0000000..1a3b5cb Binary files /dev/null and b/gsuid_core/help/new_icon/卡组.png differ diff --git a/gsuid_core/help/new_icon/卸载插件.png b/gsuid_core/help/new_icon/卸载插件.png new file mode 100644 index 0000000..2a6a799 Binary files /dev/null and b/gsuid_core/help/new_icon/卸载插件.png differ diff --git a/gsuid_core/help/new_icon/原石.png b/gsuid_core/help/new_icon/原石.png new file mode 100644 index 0000000..70a50d5 Binary files /dev/null and b/gsuid_core/help/new_icon/原石.png differ diff --git a/gsuid_core/help/new_icon/原魔.png b/gsuid_core/help/new_icon/原魔.png new file mode 100644 index 0000000..546224f Binary files /dev/null and b/gsuid_core/help/new_icon/原魔.png differ diff --git a/gsuid_core/help/new_icon/圣遗物.png b/gsuid_core/help/new_icon/圣遗物.png new file mode 100644 index 0000000..2caebbd Binary files /dev/null and b/gsuid_core/help/new_icon/圣遗物.png differ diff --git a/gsuid_core/help/new_icon/圣遗物仓库.png b/gsuid_core/help/new_icon/圣遗物仓库.png new file mode 100644 index 0000000..794cbd7 Binary files /dev/null and b/gsuid_core/help/new_icon/圣遗物仓库.png differ diff --git a/gsuid_core/help/new_icon/天赋.png b/gsuid_core/help/new_icon/天赋.png new file mode 100644 index 0000000..8c18f51 Binary files /dev/null and b/gsuid_core/help/new_icon/天赋.png differ diff --git a/gsuid_core/help/new_icon/委托.png b/gsuid_core/help/new_icon/委托.png new file mode 100644 index 0000000..25ea56c Binary files /dev/null and b/gsuid_core/help/new_icon/委托.png differ diff --git a/gsuid_core/help/new_icon/安装插件.png b/gsuid_core/help/new_icon/安装插件.png new file mode 100644 index 0000000..2ee61c2 Binary files /dev/null and b/gsuid_core/help/new_icon/安装插件.png differ diff --git a/gsuid_core/help/new_icon/完成度.png b/gsuid_core/help/new_icon/完成度.png new file mode 100644 index 0000000..aea2ad4 Binary files /dev/null and b/gsuid_core/help/new_icon/完成度.png differ diff --git a/gsuid_core/help/new_icon/宝箱.png b/gsuid_core/help/new_icon/宝箱.png new file mode 100644 index 0000000..6827e87 Binary files /dev/null and b/gsuid_core/help/new_icon/宝箱.png differ diff --git a/gsuid_core/help/new_icon/小助手.png b/gsuid_core/help/new_icon/小助手.png new file mode 100644 index 0000000..7cbbd7e Binary files /dev/null and b/gsuid_core/help/new_icon/小助手.png differ diff --git a/gsuid_core/help/new_icon/开启体力推送.png b/gsuid_core/help/new_icon/开启体力推送.png new file mode 100644 index 0000000..e240b2e Binary files /dev/null and b/gsuid_core/help/new_icon/开启体力推送.png differ diff --git a/gsuid_core/help/new_icon/强制更新插件.png b/gsuid_core/help/new_icon/强制更新插件.png new file mode 100644 index 0000000..f9dbe42 Binary files /dev/null and b/gsuid_core/help/new_icon/强制更新插件.png differ diff --git a/gsuid_core/help/new_icon/强行强制更新插件.png b/gsuid_core/help/new_icon/强行强制更新插件.png new file mode 100644 index 0000000..7c23c3f Binary files /dev/null and b/gsuid_core/help/new_icon/强行强制更新插件.png differ diff --git a/gsuid_core/help/new_icon/御神签.png b/gsuid_core/help/new_icon/御神签.png new file mode 100644 index 0000000..02e6092 Binary files /dev/null and b/gsuid_core/help/new_icon/御神签.png differ diff --git a/gsuid_core/help/new_icon/怪物.png b/gsuid_core/help/new_icon/怪物.png new file mode 100644 index 0000000..aae711f Binary files /dev/null and b/gsuid_core/help/new_icon/怪物.png differ diff --git a/gsuid_core/help/new_icon/成就.png b/gsuid_core/help/new_icon/成就.png new file mode 100644 index 0000000..0da451d Binary files /dev/null and b/gsuid_core/help/new_icon/成就.png differ diff --git a/gsuid_core/help/new_icon/扫码登陆.png b/gsuid_core/help/new_icon/扫码登陆.png new file mode 100644 index 0000000..363197f Binary files /dev/null and b/gsuid_core/help/new_icon/扫码登陆.png differ diff --git a/gsuid_core/help/new_icon/抗性.png b/gsuid_core/help/new_icon/抗性.png new file mode 100644 index 0000000..5e762d4 Binary files /dev/null and b/gsuid_core/help/new_icon/抗性.png differ diff --git a/gsuid_core/help/new_icon/抽卡记录.png b/gsuid_core/help/new_icon/抽卡记录.png new file mode 100644 index 0000000..1b4b096 Binary files /dev/null and b/gsuid_core/help/new_icon/抽卡记录.png differ diff --git a/gsuid_core/help/new_icon/换.png b/gsuid_core/help/new_icon/换.png new file mode 100644 index 0000000..c3c9852 Binary files /dev/null and b/gsuid_core/help/new_icon/换.png differ diff --git a/gsuid_core/help/new_icon/排名.png b/gsuid_core/help/new_icon/排名.png new file mode 100644 index 0000000..88e4d78 Binary files /dev/null and b/gsuid_core/help/new_icon/排名.png differ diff --git a/gsuid_core/help/new_icon/探索.png b/gsuid_core/help/new_icon/探索.png new file mode 100644 index 0000000..32d1e96 Binary files /dev/null and b/gsuid_core/help/new_icon/探索.png differ diff --git a/gsuid_core/help/new_icon/推送.png b/gsuid_core/help/new_icon/推送.png new file mode 100644 index 0000000..1bb5027 Binary files /dev/null and b/gsuid_core/help/new_icon/推送.png differ diff --git a/gsuid_core/help/new_icon/收集.png b/gsuid_core/help/new_icon/收集.png new file mode 100644 index 0000000..4f61bfc Binary files /dev/null and b/gsuid_core/help/new_icon/收集.png differ diff --git a/gsuid_core/help/new_icon/攻略.png b/gsuid_core/help/new_icon/攻略.png new file mode 100644 index 0000000..dc72668 Binary files /dev/null and b/gsuid_core/help/new_icon/攻略.png differ diff --git a/gsuid_core/help/new_icon/无效用户.png b/gsuid_core/help/new_icon/无效用户.png new file mode 100644 index 0000000..e801908 Binary files /dev/null and b/gsuid_core/help/new_icon/无效用户.png differ diff --git a/gsuid_core/help/new_icon/更新.png b/gsuid_core/help/new_icon/更新.png new file mode 100644 index 0000000..88a7efe Binary files /dev/null and b/gsuid_core/help/new_icon/更新.png differ diff --git a/gsuid_core/help/new_icon/更新插件.png b/gsuid_core/help/new_icon/更新插件.png new file mode 100644 index 0000000..df64907 Binary files /dev/null and b/gsuid_core/help/new_icon/更新插件.png differ diff --git a/gsuid_core/help/new_icon/札记.png b/gsuid_core/help/new_icon/札记.png new file mode 100644 index 0000000..2fa185c Binary files /dev/null and b/gsuid_core/help/new_icon/札记.png differ diff --git a/gsuid_core/help/new_icon/查询.png b/gsuid_core/help/new_icon/查询.png new file mode 100644 index 0000000..e35cf75 Binary files /dev/null and b/gsuid_core/help/new_icon/查询.png differ diff --git a/gsuid_core/help/new_icon/校验全部SK.png b/gsuid_core/help/new_icon/校验全部SK.png new file mode 100644 index 0000000..2b056d2 Binary files /dev/null and b/gsuid_core/help/new_icon/校验全部SK.png differ diff --git a/gsuid_core/help/new_icon/武器.png b/gsuid_core/help/new_icon/武器.png new file mode 100644 index 0000000..68e682f Binary files /dev/null and b/gsuid_core/help/new_icon/武器.png differ diff --git a/gsuid_core/help/new_icon/每日.png b/gsuid_core/help/new_icon/每日.png new file mode 100644 index 0000000..85f0b0c Binary files /dev/null and b/gsuid_core/help/new_icon/每日.png differ diff --git a/gsuid_core/help/new_icon/每月.png b/gsuid_core/help/new_icon/每月.png new file mode 100644 index 0000000..452410b Binary files /dev/null and b/gsuid_core/help/new_icon/每月.png differ diff --git a/gsuid_core/help/new_icon/毕业度.png b/gsuid_core/help/new_icon/毕业度.png new file mode 100644 index 0000000..97efa1b Binary files /dev/null and b/gsuid_core/help/new_icon/毕业度.png differ diff --git a/gsuid_core/help/new_icon/注册时间.png b/gsuid_core/help/new_icon/注册时间.png new file mode 100644 index 0000000..7720ce8 Binary files /dev/null and b/gsuid_core/help/new_icon/注册时间.png differ diff --git a/gsuid_core/help/new_icon/活动.png b/gsuid_core/help/new_icon/活动.png new file mode 100644 index 0000000..2206f9c Binary files /dev/null and b/gsuid_core/help/new_icon/活动.png differ diff --git a/gsuid_core/help/new_icon/深渊.png b/gsuid_core/help/new_icon/深渊.png new file mode 100644 index 0000000..eec3dee Binary files /dev/null and b/gsuid_core/help/new_icon/深渊.png differ diff --git a/gsuid_core/help/new_icon/添加CK.png b/gsuid_core/help/new_icon/添加CK.png new file mode 100644 index 0000000..e158b81 Binary files /dev/null and b/gsuid_core/help/new_icon/添加CK.png differ diff --git a/gsuid_core/help/new_icon/清除原神公告红点.png b/gsuid_core/help/new_icon/清除原神公告红点.png new file mode 100644 index 0000000..89f1547 Binary files /dev/null and b/gsuid_core/help/new_icon/清除原神公告红点.png differ diff --git a/gsuid_core/help/new_icon/清除无效用户.png b/gsuid_core/help/new_icon/清除无效用户.png new file mode 100644 index 0000000..a87b8d6 Binary files /dev/null and b/gsuid_core/help/new_icon/清除无效用户.png differ diff --git a/gsuid_core/help/new_icon/版本深渊.png b/gsuid_core/help/new_icon/版本深渊.png new file mode 100644 index 0000000..f90a0bd Binary files /dev/null and b/gsuid_core/help/new_icon/版本深渊.png differ diff --git a/gsuid_core/help/new_icon/状态.png b/gsuid_core/help/new_icon/状态.png new file mode 100644 index 0000000..724691c Binary files /dev/null and b/gsuid_core/help/new_icon/状态.png differ diff --git a/gsuid_core/help/new_icon/签到.png b/gsuid_core/help/new_icon/签到.png new file mode 100644 index 0000000..c2ba701 Binary files /dev/null and b/gsuid_core/help/new_icon/签到.png differ diff --git a/gsuid_core/help/new_icon/米游币.png b/gsuid_core/help/new_icon/米游币.png new file mode 100644 index 0000000..a4d51b9 Binary files /dev/null and b/gsuid_core/help/new_icon/米游币.png differ diff --git a/gsuid_core/help/new_icon/素材.png b/gsuid_core/help/new_icon/素材.png new file mode 100644 index 0000000..60626df Binary files /dev/null and b/gsuid_core/help/new_icon/素材.png differ diff --git a/gsuid_core/help/new_icon/练度.png b/gsuid_core/help/new_icon/练度.png new file mode 100644 index 0000000..033b6a3 Binary files /dev/null and b/gsuid_core/help/new_icon/练度.png differ diff --git a/gsuid_core/help/new_icon/绑定.png b/gsuid_core/help/new_icon/绑定.png new file mode 100644 index 0000000..0c43de9 Binary files /dev/null and b/gsuid_core/help/new_icon/绑定.png differ diff --git a/gsuid_core/help/new_icon/绑定设备.png b/gsuid_core/help/new_icon/绑定设备.png new file mode 100644 index 0000000..2050302 Binary files /dev/null and b/gsuid_core/help/new_icon/绑定设备.png differ diff --git a/gsuid_core/help/new_icon/结晶.png b/gsuid_core/help/new_icon/结晶.png new file mode 100644 index 0000000..f234b58 Binary files /dev/null and b/gsuid_core/help/new_icon/结晶.png differ diff --git a/gsuid_core/help/new_icon/网页控制台.png b/gsuid_core/help/new_icon/网页控制台.png new file mode 100644 index 0000000..813a0c7 Binary files /dev/null and b/gsuid_core/help/new_icon/网页控制台.png differ diff --git a/gsuid_core/help/new_icon/自动签到.png b/gsuid_core/help/new_icon/自动签到.png new file mode 100644 index 0000000..4234fa7 Binary files /dev/null and b/gsuid_core/help/new_icon/自动签到.png differ diff --git a/gsuid_core/help/new_icon/血量.png b/gsuid_core/help/new_icon/血量.png new file mode 100644 index 0000000..8153588 Binary files /dev/null and b/gsuid_core/help/new_icon/血量.png differ diff --git a/gsuid_core/help/new_icon/血量表.png b/gsuid_core/help/new_icon/血量表.png new file mode 100644 index 0000000..e64d446 Binary files /dev/null and b/gsuid_core/help/new_icon/血量表.png differ diff --git a/gsuid_core/help/new_icon/表情.png b/gsuid_core/help/new_icon/表情.png new file mode 100644 index 0000000..0064d18 Binary files /dev/null and b/gsuid_core/help/new_icon/表情.png differ diff --git a/gsuid_core/help/new_icon/角色.png b/gsuid_core/help/new_icon/角色.png new file mode 100644 index 0000000..1e19966 Binary files /dev/null and b/gsuid_core/help/new_icon/角色.png differ diff --git a/gsuid_core/help/new_icon/角色排名.png b/gsuid_core/help/new_icon/角色排名.png new file mode 100644 index 0000000..bd93e31 Binary files /dev/null and b/gsuid_core/help/new_icon/角色排名.png differ diff --git a/gsuid_core/help/new_icon/角色排行榜.png b/gsuid_core/help/new_icon/角色排行榜.png new file mode 100644 index 0000000..fa779da Binary files /dev/null and b/gsuid_core/help/new_icon/角色排行榜.png differ diff --git a/gsuid_core/help/new_icon/角色材料.png b/gsuid_core/help/new_icon/角色材料.png new file mode 100644 index 0000000..8552f11 Binary files /dev/null and b/gsuid_core/help/new_icon/角色材料.png differ diff --git a/gsuid_core/help/new_icon/设置体力阈值.png b/gsuid_core/help/new_icon/设置体力阈值.png new file mode 100644 index 0000000..7a4eb5f Binary files /dev/null and b/gsuid_core/help/new_icon/设置体力阈值.png differ diff --git a/gsuid_core/help/new_icon/通用.png b/gsuid_core/help/new_icon/通用.png new file mode 100644 index 0000000..cff12c9 Binary files /dev/null and b/gsuid_core/help/new_icon/通用.png differ diff --git a/gsuid_core/help/new_icon/配置.png b/gsuid_core/help/new_icon/配置.png new file mode 100644 index 0000000..bf4bf51 Binary files /dev/null and b/gsuid_core/help/new_icon/配置.png differ diff --git a/gsuid_core/help/new_icon/重启.png b/gsuid_core/help/new_icon/重启.png new file mode 100644 index 0000000..f5158c0 Binary files /dev/null and b/gsuid_core/help/new_icon/重启.png differ diff --git a/gsuid_core/help/new_icon/食物.png b/gsuid_core/help/new_icon/食物.png new file mode 100644 index 0000000..cfcb630 Binary files /dev/null and b/gsuid_core/help/new_icon/食物.png differ diff --git a/gsuid_core/help/texture2d/banner_bg_dark.jpg b/gsuid_core/help/texture2d/banner_bg_dark.jpg new file mode 100644 index 0000000..42aad67 Binary files /dev/null and b/gsuid_core/help/texture2d/banner_bg_dark.jpg differ diff --git a/gsuid_core/help/texture2d/banner_bg.jpg b/gsuid_core/help/texture2d/banner_bg_light.jpg similarity index 100% rename from gsuid_core/help/texture2d/banner_bg.jpg rename to gsuid_core/help/texture2d/banner_bg_light.jpg diff --git a/gsuid_core/help/texture2d/bg_dark.jpg b/gsuid_core/help/texture2d/bg_dark.jpg new file mode 100644 index 0000000..e3cddad Binary files /dev/null and b/gsuid_core/help/texture2d/bg_dark.jpg differ diff --git a/gsuid_core/help/texture2d/bg.jpg b/gsuid_core/help/texture2d/bg_light.jpg similarity index 100% rename from gsuid_core/help/texture2d/bg.jpg rename to gsuid_core/help/texture2d/bg_light.jpg diff --git a/gsuid_core/help/texture2d/cag_bg.png b/gsuid_core/help/texture2d/cag_bg.png deleted file mode 100644 index 998f4a2..0000000 Binary files a/gsuid_core/help/texture2d/cag_bg.png and /dev/null differ diff --git a/gsuid_core/help/texture2d/cag_bg_dark.png b/gsuid_core/help/texture2d/cag_bg_dark.png new file mode 100644 index 0000000..fb31ac7 Binary files /dev/null and b/gsuid_core/help/texture2d/cag_bg_dark.png differ diff --git a/gsuid_core/help/texture2d/cag_bg_light.png b/gsuid_core/help/texture2d/cag_bg_light.png new file mode 100644 index 0000000..5896497 Binary files /dev/null and b/gsuid_core/help/texture2d/cag_bg_light.png differ diff --git a/gsuid_core/help/texture2d/item_bg_dark.png b/gsuid_core/help/texture2d/item_bg_dark.png new file mode 100644 index 0000000..d1ccf6b Binary files /dev/null and b/gsuid_core/help/texture2d/item_bg_dark.png differ diff --git a/gsuid_core/help/texture2d/item_bg_light.png b/gsuid_core/help/texture2d/item_bg_light.png new file mode 100644 index 0000000..91acdbe Binary files /dev/null and b/gsuid_core/help/texture2d/item_bg_light.png differ diff --git a/gsuid_core/help/utils.py b/gsuid_core/help/utils.py new file mode 100644 index 0000000..5dae8e2 --- /dev/null +++ b/gsuid_core/help/utils.py @@ -0,0 +1,29 @@ +from pathlib import Path +from typing import Optional + +from PIL import Image + +ICON = Path(__file__).parent.parent.parent / 'ICON.png' +plugins_help = { + "插件帮助一览": {"desc": "这里可以看到注册过的插件帮助。", "data": []}, +} + + +def register_help( + name: str, + help: str, + icon: Optional[Image.Image] = None, +): + if icon is None: + icon = Image.open(ICON) + plugins_help['插件帮助一览']['data'].append( + { + "name": name, + "desc": f"{name}插件帮助功能", + "eg": f'发送 {help} 获得帮助', + "icon": icon, + "need_ck": False, + "need_sk": False, + "need_admin": False, + } + ) diff --git a/gsuid_core/plugins/core_command/core_help/__init__.py b/gsuid_core/plugins/core_command/core_help/__init__.py index ad5e66e..4464a24 100644 --- a/gsuid_core/plugins/core_command/core_help/__init__.py +++ b/gsuid_core/plugins/core_command/core_help/__init__.py @@ -2,11 +2,30 @@ from gsuid_core.sv import SV from gsuid_core.bot import Bot from gsuid_core.models import Event from gsuid_core.logger import logger +from gsuid_core.help.draw_core_help import draw_core_help, draw_master_help sv_core_help_img = SV('Core帮助') -@sv_core_help_img.on_fullmatch(('core帮助', 'Core帮助')) -async def send_core_htlp_msg(bot: Bot, ev: Event): +@sv_core_help_img.on_fullmatch( + ( + 'core帮助', + 'Core帮助', + '帮助', + ) +) +async def send_core_help_msg(bot: Bot, ev: Event): logger.info('[早柚核心] 开始执行[帮助图]') - await bot.send('该功能已删除...') + await bot.send(await draw_core_help()) + + +@sv_core_help_img.on_fullmatch( + ( + 'core管理帮助', + 'Core管理帮助', + '管理帮助', + ) +) +async def send_core_master_help_msg(bot: Bot, ev: Event): + logger.info('[早柚核心] 开始执行[管理帮助图]') + await bot.send(await draw_master_help()) diff --git a/gsuid_core/plugins/core_command/install_plugins/__init__.py b/gsuid_core/plugins/core_command/install_plugins/__init__.py index b28c23b..c63e3df 100644 --- a/gsuid_core/plugins/core_command/install_plugins/__init__.py +++ b/gsuid_core/plugins/core_command/install_plugins/__init__.py @@ -6,9 +6,38 @@ from gsuid_core.utils.plugins_update._plugins import ( update_plugins, get_plugins_url, install_plugins, + uninstall_plugin, + check_plugin_exist, ) -sv_core_install_plugins = SV('core管理插件', pm=1) +sv_core_install_plugins = SV('core管理插件', pm=0) + + +@sv_core_install_plugins.on_prefix(('core卸载插件')) +async def send_plugins_uninstall(bot: Bot, ev: Event): + if not ev.text: + return await bot.send( + '请在命令之后加上要卸载插件名称!\n例如: core卸载插件GenshinUID' + ) + plugin_name = ev.text.strip() + path = await check_plugin_exist(plugin_name) + if path is None: + return await bot.send('不存在该插件...请检查是否输入正确!') + elif isinstance(path, str): + return await bot.send(path) + + resp = await bot.receive_resp( + '再次确认是否要删除插件文件夹?\n输入Y确认删除!', + ) + if resp is not None: + if resp.text.lower() == 'y': + await bot.send('开始删除...请稍等一段时间...') + im = await uninstall_plugin(path) + await bot.send(im) + else: + await bot.send('已取消删除!') + else: + await bot.send('已取消删除!') @sv_core_install_plugins.on_prefix(('core安装插件')) diff --git a/gsuid_core/plugins/core_command/user_login/__init__.py b/gsuid_core/plugins/core_command/user_login/__init__.py index 4e39710..1f4498e 100644 --- a/gsuid_core/plugins/core_command/user_login/__init__.py +++ b/gsuid_core/plugins/core_command/user_login/__init__.py @@ -1,5 +1,7 @@ import json -from typing import Dict +import random +import asyncio +from typing import Dict, List from gsuid_core.sv import SV from gsuid_core.bot import Bot @@ -16,10 +18,11 @@ from gsuid_core.utils.cookie_manager.add_ck import ( get_ck_by_all_stoken, ) -sv_core_user_config = SV('用户管理', pm=2) +sv_core_user_config = SV('用户管理', pm=1) sv_core_user_add = SV('用户添加') sv_core_user_qrcode_login = SV('扫码登陆') sv_core_user_addck = SV('添加CK', area='DIRECT') +sv_data_manger = SV('用户数据管理', pm=0) @sv_core_user_config.on_fullmatch(('刷新全部CK', '刷新全部ck')) @@ -36,6 +39,109 @@ async def send_refresh_ck_msg(bot: Bot, ev: Event): await bot.send(im) +@sv_data_manger.on_fullmatch(('校验全部Cookies')) +async def send_check_cookie(bot: Bot, ev: Event): + user_list = await GsUser.get_all_user() + invalid_user: List[GsUser] = [] + for user in user_list: + if user.cookie and user.mys_id and user.uid: + mys_data = await mys_api.get_mihoyo_bbs_info( + user.mys_id, + user.cookie, + True if int(user.uid[0]) > 5 else False, + ) + if isinstance(mys_data, int): + await GsUser.update_data_by_uid( + user.uid, ev.bot_id, cookie=None + ) + invalid_user.append(user) + continue + for i in mys_data: + if i['game_id'] != 2: + mys_data.remove(i) + if len(user_list) > 4: + im = f'正常Cookies数量: {len(user_list) - len(invalid_user)}' + invalid = '\n'.join( + [ + f'uid{user.uid}的Cookies是异常的!已删除该条Cookies!\n' + for user in invalid_user + ] + ) + return_str = f'{im}\n{invalid if invalid else "无失效Cookie!"}' + else: + return_str = '\n'.join( + [ + ( + f'uid{user.uid}/mys{user.mys_id}的Cookies是正常的!' + if user not in invalid_user + else f'uid{user.uid}的Cookies是异常的!已删除该条Cookies!' + ) + for user in user_list + ] + ) + + await bot.send(return_str) + + for i in invalid_user: + await bot.target_send( + f'您绑定的Cookies(uid{i.uid})已失效,以下功能将会受到影响:\n' + '查看完整信息列表\n查看深渊配队\n自动签到/当前状态/每月统计\n' + '请及时重新绑定Cookies并重新开关相应功能。', + 'direct', + target_id=i.user_id, + ) + await asyncio.sleep(3 + random.randint(1, 3)) + + +@sv_data_manger.on_fullmatch(('校验全部Stoken')) +async def send_check_stoken(bot: Bot, ev: Event): + user_list = await GsUser.get_all_user() + invalid_user: List[GsUser] = [] + for user in user_list: + if user.stoken and user.mys_id: + mys_data = await mys_api.get_cookie_token_by_stoken( + '', user.mys_id, user.stoken + ) + if isinstance(mys_data, int) and user.uid: + await GsUser.update_data_by_uid( + user.uid, ev.bot_id, stoken=None + ) + invalid_user.append(user) + continue + if len(user_list) > 3: + im = f'正常Stoken数量: {len(user_list) - len(invalid_user)}' + invalid = '\n'.join( + [ + f'uid{user.uid}的Stoken是异常的!已清除Stoken!\n' + for user in invalid_user + ] + ) + return_str = f'{im}\n{invalid if invalid else "无失效Stoken!"}' + else: + return_str = '\n'.join( + [ + ( + f'uid{user.uid}/mys{user.mys_id}的Stoken是正常的!' + if user not in invalid_user + else f'uid{user.uid}的Stoken是异常的!已清除Stoken!' + ) + for user in user_list + ] + ) + + await bot.send(return_str) + + for i in invalid_user: + await bot.target_send( + f'您绑定的Stoken(uid{i.uid})已失效,以下功能将会受到影响:\n' + 'gs开启自动米游币,开始获取米游币。\n' + '重新添加后需要重新开启自动米游币。', + 'direct', + target_id=i.user_id, + ) + await asyncio.sleep(3 + random.randint(1, 3)) + + async def _send_help(bot: Bot, im): p = Button('🔍查询信息', '查询') q = Button('💠查询探索度', '查询探索') diff --git a/gsuid_core/utils/plugins_config/sp_config.py b/gsuid_core/utils/plugins_config/sp_config.py index f8e841f..86c0410 100644 --- a/gsuid_core/utils/plugins_config/sp_config.py +++ b/gsuid_core/utils/plugins_config/sp_config.py @@ -1,6 +1,6 @@ from typing import Dict -from .models import GSC, GsIntConfig +from .models import GSC, GsIntConfig, GsStrConfig SP_CONIFG: Dict[str, GSC] = { 'ButtonRow': GsIntConfig( @@ -9,4 +9,10 @@ SP_CONIFG: Dict[str, GSC] = { 2, 5, ), + 'HelpMode': GsStrConfig( + '帮助模式', + '帮助模式', + 'dark', + ['light', 'dark'], + ), } diff --git a/gsuid_core/utils/plugins_update/_plugins.py b/gsuid_core/utils/plugins_update/_plugins.py index 6d0ec0e..83b4f17 100644 --- a/gsuid_core/utils/plugins_update/_plugins.py +++ b/gsuid_core/utils/plugins_update/_plugins.py @@ -20,6 +20,22 @@ plugins_list: Dict[str, Dict[str, str]] = {} is_install_dep = core_plugins_config.get_config('AutoInstallDep').data +async def check_plugin_exist(name: str): + name = name.lower() + if name in ['core_command', 'gs_test']: + return '内置插件不可删除!' + for i in PLUGINS_PATH.iterdir(): + if i.stem.lower() == name: + return i + + +async def uninstall_plugin(path: Path): + if not path.exists(): + return '该插件不存在!' + path.unlink() + return '删除成功!' + + # 传入一个path对象 async def run_poetry_install(path: Optional[Path] = None) -> int: if path is None: diff --git a/gsuid_core/version.py b/gsuid_core/version.py index 43a1e95..906d362 100644 --- a/gsuid_core/version.py +++ b/gsuid_core/version.py @@ -1 +1 @@ -__version__ = "0.5.3" +__version__ = "0.6.0"