update v0.0.5.0

This commit is contained in:
HibiKier
2021-10-03 14:24:07 +08:00
parent 87ed445a58
commit 00658cf165
182 changed files with 6439 additions and 3845 deletions
+12 -41
View File
@@ -3,51 +3,19 @@ from nonebot.permission import SUPERUSER
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
from nonebot.rule import to_me
from utils.image_utils import CreateImg
from configs.path_config import IMAGE_PATH
from utils.message_builder import image
from .data_source import create_help_image
from pathlib import Path
result = """超级用户帮助:
*:可多个类型参数 ?:可省略参数
1.添加/删除管理 [at] [level]
2.所有群组/好友
3.广播- [msg]
4.更新色图
5./t命令帮助
6.更新/设置cookie [cookie]
7.开启/关闭广播通知 [群号]
8.退群 [群号]
9.自检
10.更新价格/更加图片 ?[武器箱]
11.更新好友信息
12.更新群群信息
13.重载原神/方舟/赛马娘/坎公骑冠剑卡池
14.添加商品 [名称]-[价格]-[描述]-[折扣]-[限时时间]
15.删除商品 [名称(序号)]
16.修改商品 -name [名称(序号)] -price [价格] -des [描述] -discount [折扣] -time [限时]
17.节日红包 [金额] [数量] ?[祝福语] *?[指定群]
18.更新原神今日素材
19.更新原神资源信息
20.添加pix关键词/uid/pid *[关键词/uid/pid] ?[-f](强制通过不检测)
21.通过/取消pix关键词 [keyword/pid:pid/uid:uid]
22.删除pix关键词 [keyword/uid/pid:pid]
23.更新pix关键词 [keyword/pid:pid/uid:uid] [num]
24.删除pix图片 *[pid] ?[-b](同时加入黑名单)
25.查看pix图库 [keyword]
26.pix检测更新 [update]
27.pix [-s/-r] ?[tag]
28.检查更新真寻
29.真寻重启
30.添加/删除群白名单 *[群号]
31.关闭[功能] ?[群号/private/group](有群号时禁用指定群)
32.功能状态
33.查看群白名单"""
__zx_plugin_name__ = '超级用户帮助 [Superuser]'
height = len(result.split('\n')) * 24
A = CreateImg(1000, height, font_size=20)
A.text((10, 10), result)
A.save(f'{IMAGE_PATH}/super_help.png')
superuser_help_image = Path(IMAGE_PATH) / 'superuser_help.png'
if superuser_help_image.exists():
superuser_help_image.unlink()
super_help = on_command(
"超级用户帮助", rule=to_me(), priority=1, permission=SUPERUSER, block=True
@@ -56,4 +24,7 @@ super_help = on_command(
@super_help.handle()
async def _(bot: Bot, event: Event, state: T_State):
await super_help.finish(image('super_help.png'), at_sender=True)
if not superuser_help_image.exists():
await create_help_image()
x = image(superuser_help_image)
await super_help.finish(x)
+80
View File
@@ -0,0 +1,80 @@
from utils.image_utils import CreateImg
from configs.path_config import IMAGE_PATH
from services.log import logger
from utils.utils import get_matchers
from nonebot.adapters.cqhttp import Bot
from pathlib import Path
from nonebot import Driver
import asyncio
import nonebot
driver: Driver = nonebot.get_driver()
background = Path(IMAGE_PATH) / "background" / "0.png"
superuser_help_image = Path(IMAGE_PATH) / "superuser_help.png"
@driver.on_bot_connect
async def create_help_image(bot: Bot = None):
"""
创建超级用户帮助图片
"""
await asyncio.get_event_loop().run_in_executor(None, _create_help_image)
def _create_help_image():
"""
创建管理员帮助图片
"""
_matchers = get_matchers()
_plugin_name_list = []
width = 0
help_str = "超级用户帮助\n\n* 注: ‘*’ 代表可有多个相同参数 ‘?’ 代表可省略该参数 *\n\n"
tmp_img = CreateImg(0, 0, plain_text='1', font_size=24)
plugin_name = ""
for matcher in _matchers:
try:
_plugin = nonebot.plugin.get_plugin(matcher.module)
_module = _plugin.module
try:
plugin_name = _module.__getattribute__("__zx_plugin_name__")
except AttributeError:
continue
is_superuser_usage = False
try:
_ = _module.__getattribute__("__plugin_superuser_usage__")
is_superuser_usage = True
except AttributeError:
pass
if (
("[superuser]" in plugin_name.lower() or is_superuser_usage)
and plugin_name != "超级用户帮助 [Superuser]"
and plugin_name not in _plugin_name_list
and "[hidden]" not in plugin_name.lower()
):
_plugin_name_list.append(plugin_name)
try:
plugin_des = _module.__getattribute__("__plugin_des__")
except AttributeError:
plugin_des = '_'
plugin_cmd = _module.__getattribute__("__plugin_cmd__")
if is_superuser_usage:
plugin_cmd = [x for x in plugin_cmd if "[_superuser]" in x]
plugin_cmd = " / ".join(plugin_cmd).replace('[_superuser]', '').strip()
help_str += f"{plugin_des} -> {plugin_cmd}\n\n"
x = tmp_img.getsize(f"{plugin_des} -> {plugin_cmd}")[0]
width = width if width > x else x
except Exception as e:
logger.warning(
f"获取超级用户插件 {matcher.module}: {plugin_name} 设置失败... {type(e)}:{e}"
)
height = len(help_str.split("\n")) * 33
width += 500
A = CreateImg(width, height, font_size=24)
_background = CreateImg(width, height, background=background)
A.text((300, 140), help_str)
A.paste(_background, alpha=True)
A.save(superuser_help_image)
logger.info(f"已成功加载 {len(_plugin_name_list)} 条超级用户命令")