mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 12:50:03 +08:00
update v0.0.5.0
This commit is contained in:
+44
-26
@@ -1,43 +1,61 @@
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, PrivateMessageEvent
|
||||
from nonebot.adapters.cqhttp import (
|
||||
Bot,
|
||||
MessageEvent,
|
||||
)
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.rule import to_me
|
||||
from configs.path_config import DATA_PATH
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from utils.message_builder import image
|
||||
import os
|
||||
from .data_source import create_help_img, create_group_help_img, get_plugin_help
|
||||
from .data_source import create_help_img, get_plugin_help
|
||||
from utils.utils import get_message_text
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
__plugin_name__ = "帮助"
|
||||
__zx_plugin_name__ = "帮助"
|
||||
|
||||
|
||||
if not os.path.exists(DATA_PATH + "group_help/"):
|
||||
os.mkdir(DATA_PATH + "group_help/")
|
||||
create_help_img()
|
||||
for file in os.listdir(DATA_PATH + "group_help/"):
|
||||
os.remove(DATA_PATH + "group_help/" + file)
|
||||
help_image = Path(IMAGE_PATH) / "help.png"
|
||||
simple_help_image = Path(IMAGE_PATH) / "simple_help.png"
|
||||
if help_image.exists():
|
||||
help_image.unlink()
|
||||
if simple_help_image.exists():
|
||||
simple_help_image.unlink()
|
||||
|
||||
_help = on_command("功能", rule=to_me(), aliases={"help", "帮助"}, priority=1, block=True)
|
||||
_help = on_command("详细功能", rule=to_me(), aliases={"详细帮助"}, priority=1, block=True)
|
||||
simple_help = on_command("功能", rule=to_me(), aliases={"help", "帮助"}, priority=1, block=True)
|
||||
|
||||
|
||||
@_help.handle()
|
||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
if not msg:
|
||||
if not os.path.exists(DATA_PATH + f"group_help/{event.group_id}.png"):
|
||||
create_group_help_img(event.group_id)
|
||||
await _help.finish(
|
||||
image(abspath=DATA_PATH + f"group_help/{event.group_id}.png")
|
||||
)
|
||||
else:
|
||||
await _help.finish(get_plugin_help(msg))
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if not help_image.exists():
|
||||
if help_image.exists():
|
||||
help_image.unlink()
|
||||
if simple_help_image.exists():
|
||||
simple_help_image.unlink()
|
||||
await create_help_img(help_image, simple_help_image)
|
||||
await _help.finish(image("help.png"))
|
||||
|
||||
|
||||
@_help.handle()
|
||||
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
|
||||
@simple_help.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
if not msg:
|
||||
await _help.finish(image("help.png"))
|
||||
is_super = False
|
||||
if msg:
|
||||
if '-super' in msg:
|
||||
if str(event.user_id) in bot.config.superusers:
|
||||
is_super = True
|
||||
msg = msg.replace('-super', '')
|
||||
msg = get_plugin_help(msg, is_super)
|
||||
if msg:
|
||||
await _help.send(image(b64=msg))
|
||||
else:
|
||||
await _help.send("没有此功能的帮助信息...")
|
||||
else:
|
||||
await _help.finish(get_plugin_help(msg))
|
||||
if not simple_help_image.exists():
|
||||
if help_image.exists():
|
||||
help_image.unlink()
|
||||
if simple_help_image.exists():
|
||||
simple_help_image.unlink()
|
||||
await create_help_img(help_image, simple_help_image)
|
||||
await _help.finish(image("simple_help.png"))
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
from configs.config import NICKNAME
|
||||
|
||||
# 实用
|
||||
utility_help = {
|
||||
"update_pic": "一些对图片的操作 --> 指令:操作图片/图片/修改图片(包含 10 种图片操作)",
|
||||
"search_buff_skin_price": "BUFF皮肤底价查询 --> 指令:查询皮肤(代理ip不得劲)",
|
||||
"weather": "天气查询 --> 指令:xx天气",
|
||||
"yiqing": "实时疫情数据 --> 指令:疫情查询/疫情/查询疫情",
|
||||
"bt": "bt(磁力搜索){仅支持私聊,懂的都懂} --> 指令:bt",
|
||||
"reimu": "老司机必备!{仅支持私聊,懂的都懂}-> 指令:上车",
|
||||
"what_anime": "靠图识番 --> 指令:识番",
|
||||
"nonebot_plugin_picsearcher": "以图搜图 --> 指令:识图/这是什么/上一张图是什么",
|
||||
"search_anime": "找不到想看的动漫吗? --> 指令:搜番",
|
||||
"songpicker2": "来一首歌听听? --> 指令:点歌",
|
||||
"epic": "epic速速白嫖 --> 指令:epic",
|
||||
"pixiv_r": "P站排行榜直接冲 --> 指令:p站排行(可含参数)",
|
||||
"pixiv_s": "P站的图随便搜搜 --> 指令:搜图(可含参数)",
|
||||
"pid_search": "通过PID搜索图片 --> 指令:p搜 [pid]",
|
||||
"translate": "出国旅游助手(狗头) --> 指令:英翻/翻英/日翻/翻日/韩翻/翻韩",
|
||||
"cover": "快捷的b站封面获取方式 --> 指令:b封面 [连接/av/bv/cv/直播id]",
|
||||
}
|
||||
# 娱乐
|
||||
entertainment_help = {
|
||||
"sign_in": "签到(影响色图和开箱) --> 指令:签到/我的签到/好感度排行/好感度总榜/好感度总榜[屏蔽我/显示我]",
|
||||
"send_img": "发送图片 --> 指令:美图/萝莉/壁纸/(美图/萝莉/壁纸[id])/N张图xx(N<=9)",
|
||||
"send_setu": "不要小看涩图啊混蛋! --> 指令:色图/色图[id]/n张色图/n张xx色图/查色图/...(请查看 色图 帮助)",
|
||||
"white2black_img": "黑白草图 --> 指令:黑白图/黑白草图",
|
||||
"coser": "三次元也不戳 --> 指令:coser",
|
||||
"jitang": "不喝点什么不舒服 --> 指令:鸡汤/语录",
|
||||
"send_dinggong_voice": "骂我(傲娇?) --> 指令:骂老子",
|
||||
"poke": "戳一戳发送语音美图萝莉图不美哉?",
|
||||
"open_cases": "模拟开箱(戒赌) --> 指令:开箱(N连开箱[N<=30])/我的开箱/群开箱统计/我的金色",
|
||||
"luxun": "鲁迅说过 --> 指令:鲁迅说",
|
||||
"fake_msg": "构造一个假消息 --> 指令:假消息",
|
||||
"shop_handle": "商店系统(初始送100金币) --> 指令:商店/我的金币/购买道具/使用道具",
|
||||
"draw_card_prts": "换个地方当非酋TvT... --> 指令:方舟一井/方舟N抽(0<N<300)",
|
||||
"draw_card_genshin": "提瓦特是个好地方! --> 指令:原神一井/原神N抽(0<N<180)/原神武器/角色N抽/重置原神抽卡次数",
|
||||
"draw_card_pretty": "赛马娘!!!! --> 指令:赛马娘一井/赛马娘N抽/赛马娘卡一井/赛马娘卡N抽(0<N<200)",
|
||||
"draw_card_guardian": "坎公骑冠剑.... --> 指令:坎公骑冠剑一井/坎公骑冠剑武器一井/坎公骑冠剑N抽/坎公骑冠剑武器N抽(0<N<300)",
|
||||
"draw_card_pcr": "公主连结(国服)来几发 --> 指令:pcr一井/pcrN抽(0<N<300)",
|
||||
"draw_card_azur": "我跟方舟坐狱友 --> 指令:碧蓝轻型/重型/特型N抽(0<N<300)",
|
||||
"draw_card_fgo": "你就是我的马斯塔嘛 --> 指令:fgoN抽(0<N<300)",
|
||||
"draw_card_onmyoji": "普通的阴阳师召唤 --> 指令:阴阳师N抽(0<N<300)",
|
||||
"one_friend": "我有一个朋友想问问... --> 指令:我有一个朋友想问问xxx(内容)",
|
||||
"nickname": "区区昵称! --> 指令:以后叫我xx(昵称)/我是谁/取消昵称",
|
||||
"almanac": "这是一张正经的黄历 --> 指令:原神黄历",
|
||||
"material_remind": "看看原神今天要刷什么 --> 指令:今日素材/今日材料/今天素材/今天材料",
|
||||
"qiu_qiu_translation": "这家伙到底在说什么? --> 指令:丘丘翻译/丘丘一下/丘丘语翻译",
|
||||
"query_resource_points": "地图资源速速查看 --> 指令:原神资源查询xx[路径]/原神资源列表/哪里有xx/xx在哪(xx=资源名称)",
|
||||
"russian": "紧张刺激的俄罗斯轮盘 --> 指令:俄罗斯轮盘帮助",
|
||||
"gold_redbag": f"运气项目又来啦! --> 指令:塞红包/ 抢红包指令: 开/抢/戳一戳{NICKNAME}/ 退回:退回未抢完的红包",
|
||||
"poetry": f"突然文艺的{NICKNAME}是否搞错了什么 --> 指令:念诗/来首诗/念首诗",
|
||||
"comments_163": "生了个人,我很抱歉 --> 指令:到点了/12点了/网易云热评/网易云评论",
|
||||
"pix_gallery": "偶尔也想看看美图? --> 指令:PIX [关键词/uid/pid:pid] [num]/查看pix图库 [关键词]/显示pix关键词",
|
||||
'nbnhhsh': "会说话就多说点! --> 指令:nbnhhsh/能不能好好说话 [文本](空格划分)",
|
||||
"roll": f"让{NICKNAME}来帮你决定吧! --> 指令:roll/ roll [文本](空格划分)",
|
||||
"wbtop": f"刚买完瓜,在吃瓜现场 --> 指令:微博热搜/微博热搜 [数字]",
|
||||
"bilibili_sub": f"非常快捷的订阅播报 --> 指令:添加订阅 [主播/up/番剧] [id/番名/链接] / 删除订阅 [id]/ 查看订阅"
|
||||
}
|
||||
# 其他
|
||||
other_help = [
|
||||
"查看当前的群欢迎消息 --> 指令:群欢迎消息",
|
||||
"这是一份正经的自我介绍 --> 指令:自我介绍",
|
||||
"不得看看自己权力多大? --> 指令:我的权限",
|
||||
"有人记得你是什么时候加入我们的 --> 指令:我的信息",
|
||||
"让我看看更新了什么 --> 指令:更新信息",
|
||||
f"{NICKNAME}给我把话收回去! --> 指令:撤回 [id](默认0)",
|
||||
"群拥有的权限 --> 指令:查看群权限",
|
||||
"数据统计可视化_1 --> 指令:功能调用统计/日功能调用统计/周功能调用统计/月功能调用统计",
|
||||
"数据统计可视化_2 --> 指令:周功能调用统计 [功能名称]/月功能调用统计 [功能名称]",
|
||||
"这里是PIX图库! --> 指令:添加pix关键词 [关键词]/添加pixuid/pid [UID/PID]/我的pix关键词",
|
||||
]
|
||||
+274
-160
@@ -1,175 +1,289 @@
|
||||
from utils.image_utils import CreateImg
|
||||
from configs.path_config import IMAGE_PATH, DATA_PATH
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from utils.manager import plugins2settings_manager
|
||||
from typing import Optional
|
||||
from services.log import logger
|
||||
from pathlib import Path
|
||||
from .config import *
|
||||
from configs.config import (
|
||||
INITIAL_OPEN_CASE_COUNT,
|
||||
INITIAL_SETU_PROBABILITY,
|
||||
ADMIN_DEFAULT_AUTH,
|
||||
)
|
||||
from configs.config import plugins2info_dict, NICKNAME
|
||||
from utils.static_data import group_manager
|
||||
from utils.utils import get_matchers
|
||||
import random
|
||||
import asyncio
|
||||
import nonebot
|
||||
import os
|
||||
|
||||
|
||||
width = 1600
|
||||
random_bk_path = Path(IMAGE_PATH) / "background" / "help" / "simple_help"
|
||||
|
||||
background = Path(IMAGE_PATH) / "background" / "0.png"
|
||||
|
||||
|
||||
def create_help_img():
|
||||
help_img_file = Path(IMAGE_PATH) / 'help.png'
|
||||
if help_img_file.exists():
|
||||
help_img_file.unlink()
|
||||
h = (
|
||||
100
|
||||
+ len(utility_help) * 24
|
||||
+ len(entertainment_help) * 24
|
||||
+ len(other_help) * 24
|
||||
) + 800
|
||||
A = CreateImg(width, h - 200, font_size=24)
|
||||
e = CreateImg(width, len(entertainment_help) * 26 + 100, font_size=24)
|
||||
rst = ""
|
||||
i = 0
|
||||
for cmd in entertainment_help:
|
||||
rst += f"{i + 1}.{entertainment_help[cmd]}\n"
|
||||
i += 1
|
||||
e.text((10, 10), "娱乐功能:")
|
||||
e.text((40, 40), rst)
|
||||
u = CreateImg(width, len(utility_help) * 26 + 100, font_size=24, color="black")
|
||||
rst = ""
|
||||
i = 0
|
||||
for cmd in utility_help:
|
||||
rst += f"{i + 1}.{utility_help[cmd]}\n"
|
||||
i += 1
|
||||
u.text((10, 10), "实用功能:", fill=(255, 255, 255))
|
||||
u.text((40, 40), rst, fill=(255, 255, 255))
|
||||
o = CreateImg(width, len(other_help) * 26 + 100, font_size=24)
|
||||
rst = ""
|
||||
for i in range(len(other_help)):
|
||||
rst += f"{i + 1}.{other_help[i]}\n"
|
||||
i += 1
|
||||
o.text((10, 10), "其他功能:")
|
||||
o.text((40, 40), rst)
|
||||
A.paste(e, (0, 0))
|
||||
A.paste(u, (0, e.h))
|
||||
A.paste(o, (0, e.h + u.h))
|
||||
A.text(
|
||||
(10, e.h + u.h + o.h + 50),
|
||||
f"大部分交互功能可以通过输入‘取消’,‘算了’来取消当前交互\n对{NICKNAME}说 “{NICKNAME}帮助 指令名” 获取对应详细帮助\n"
|
||||
"可以通过 “滴滴滴- [消息]” 联系管理员(有趣的想法尽管来吧!<还有Bug和建议>)"
|
||||
"\n[群管理员请看 管理员帮助(群主与管理员自带 5 级权限)]\n\n"
|
||||
f"\t「如果{NICKNAME}回复了一些不符合人设的话,那是因为每日白嫖的图灵次数已用完,使用的是备用接口【QAQ】」",
|
||||
async def create_help_img(help_image: Path, simple_help_image: Path):
|
||||
"""
|
||||
生成帮助图片
|
||||
:param help_image: 图片路径
|
||||
:param simple_help_image: 简易帮助图片路径
|
||||
"""
|
||||
return await asyncio.get_event_loop().run_in_executor(
|
||||
None, _create_help_img, help_image, simple_help_image
|
||||
)
|
||||
|
||||
A.save(IMAGE_PATH + "help.png")
|
||||
|
||||
|
||||
def create_group_help_img(group_id: int):
|
||||
group_id = str(group_id)
|
||||
h = (
|
||||
100
|
||||
+ len(utility_help) * 24
|
||||
+ len(entertainment_help) * 24
|
||||
+ len(other_help) * 24
|
||||
) + 800
|
||||
A = CreateImg(width, h, font_size=24)
|
||||
u = CreateImg(width, len(utility_help) * 26 + 100, font_size=24, color="black")
|
||||
o = CreateImg(width, len(other_help) * 26 + 100, font_size=24)
|
||||
e = CreateImg(width, len(entertainment_help) * 26 + 100, font_size=24)
|
||||
rst = ""
|
||||
i = 1
|
||||
for cmd in entertainment_help.keys():
|
||||
flag, dfg = parse_cmd(cmd, group_id)
|
||||
if dfg:
|
||||
cmd = rcmd(dfg)
|
||||
rst += f"【{flag}】{i}.{entertainment_help[cmd]}\n"
|
||||
i += 1
|
||||
e.text((10, 10), "娱乐功能:")
|
||||
e.text((40, 40), rst)
|
||||
|
||||
rst = ""
|
||||
i = 1
|
||||
for cmd in utility_help.keys():
|
||||
flag, dfg = parse_cmd(cmd, group_id)
|
||||
rst += f"【{flag}】{i}.{utility_help[cmd]}\n"
|
||||
i += 1
|
||||
u.text((10, 10), "实用功能:", fill=(255, 255, 255))
|
||||
u.text((40, 40), rst, fill=(255, 255, 255))
|
||||
|
||||
rst = ""
|
||||
for i in range(len(other_help)):
|
||||
rst += f"{i + 1}.{other_help[i]}\n"
|
||||
o.text((10, 10), "其他功能:")
|
||||
o.text((40, 40), rst)
|
||||
|
||||
A.paste(e, (0, 0))
|
||||
A.paste(u, (0, e.h))
|
||||
A.paste(o, (0, e.h + u.h))
|
||||
# A.text((width, 10), f'总开关【{"√" if data["总开关"] else "×"}】')
|
||||
A.text(
|
||||
(10, e.h + u.h + o.h + 50),
|
||||
f"大部分交互功能可以通过输入‘取消’,‘算了’来取消当前交互\n对{NICKNAME}说 “{NICKNAME}帮助 指令名” 获取对应详细帮助\n"
|
||||
"可以通过 “滴滴滴- [消息]” 联系管理员(有趣的想法尽管来吧!<还有Bug和建议>)"
|
||||
f"\n[群管理员请看 管理员帮助(群主与管理员自带 {ADMIN_DEFAULT_AUTH} 级权限)]",
|
||||
def _create_help_img(help_image: Path, simple_help_image: Path):
|
||||
"""
|
||||
生成帮助图片
|
||||
:param help_image: 图片路径
|
||||
:param simple_help_image: 简易帮助图片路径
|
||||
"""
|
||||
_matchers = get_matchers()
|
||||
width = 0
|
||||
matchers_data = {}
|
||||
_des_tmp = {}
|
||||
_plugin_name_tmp = []
|
||||
_tmp = []
|
||||
tmp_img = CreateImg(0, 0, plain_text="1", font_size=24)
|
||||
font_height = tmp_img.h
|
||||
for matcher in _matchers:
|
||||
plugin_name = None
|
||||
_plugin = nonebot.plugin.get_plugin(matcher.module)
|
||||
_module = _plugin.module
|
||||
try:
|
||||
plugin_name = _module.__getattribute__("__zx_plugin_name__")
|
||||
try:
|
||||
plugin_des = _module.__getattribute__("__plugin_des__")
|
||||
except AttributeError:
|
||||
plugin_des = "_"
|
||||
if (
|
||||
"[hidden]" in plugin_name.lower()
|
||||
or "[admin]" in plugin_name.lower()
|
||||
or "[superuser]" in plugin_name.lower()
|
||||
or plugin_name in _plugin_name_tmp
|
||||
or plugin_name == "帮助"
|
||||
):
|
||||
continue
|
||||
plugin_type = ("normal",)
|
||||
text_type = 0
|
||||
if plugins2settings_manager.get(
|
||||
matcher.module
|
||||
) and plugins2settings_manager[matcher.module].get("plugin_type"):
|
||||
plugin_type = tuple(
|
||||
plugins2settings_manager.get_plugin_data(matcher.module)[
|
||||
"plugin_type"
|
||||
]
|
||||
)
|
||||
else:
|
||||
try:
|
||||
plugin_type = _module.__getattribute__("__plugin_type__")
|
||||
except AttributeError:
|
||||
pass
|
||||
if len(plugin_type) > 1:
|
||||
try:
|
||||
text_type = int(plugin_type[1])
|
||||
except ValueError as e:
|
||||
logger.warning(f"生成列向帮助排列失败 {plugin_name}: {type(e)}: {e}")
|
||||
plugin_type = plugin_type[0]
|
||||
else:
|
||||
plugin_type = plugin_type[0]
|
||||
try:
|
||||
plugin_cmd = _module.__getattribute__("__plugin_cmd__")
|
||||
plugin_cmd = [x for x in plugin_cmd if "[_superuser]" not in x]
|
||||
except AttributeError:
|
||||
plugin_cmd = []
|
||||
if plugin_type not in matchers_data.keys():
|
||||
matchers_data[plugin_type] = {}
|
||||
if plugin_des in _des_tmp.keys():
|
||||
try:
|
||||
matchers_data[plugin_type][_des_tmp[plugin_des]]["cmd"] = (
|
||||
matchers_data[plugin_type][_des_tmp[plugin_des]]["cmd"]
|
||||
+ plugin_cmd
|
||||
)
|
||||
except KeyError as e:
|
||||
logger.warning(f"{type(e)}: {e}")
|
||||
else:
|
||||
matchers_data[plugin_type][plugin_name] = {
|
||||
"des": plugin_des,
|
||||
"cmd": plugin_cmd,
|
||||
"text_type": text_type,
|
||||
}
|
||||
try:
|
||||
if text_type == 0:
|
||||
x = tmp_img.getsize(
|
||||
f'{plugin_name}: {matchers_data[plugin_type][plugin_name]["des"]} ->'
|
||||
+ " / ".join(matchers_data[plugin_type][plugin_name]["cmd"])
|
||||
)[0]
|
||||
width = width if width > x else x
|
||||
except KeyError:
|
||||
pass
|
||||
if plugin_des not in _des_tmp:
|
||||
_des_tmp[plugin_des] = plugin_name
|
||||
except AttributeError as e:
|
||||
if plugin_name not in _plugin_name_tmp:
|
||||
logger.warning(f"获取功能 {matcher.module}: {plugin_name} 设置失败...e:{e}")
|
||||
if plugin_name not in _plugin_name_tmp:
|
||||
_plugin_name_tmp.append(plugin_name)
|
||||
help_img_list = []
|
||||
simple_help_img_list = []
|
||||
types = list(matchers_data.keys())
|
||||
types.sort()
|
||||
ix = 0
|
||||
for type_ in types:
|
||||
keys = list(matchers_data[type_].keys())
|
||||
keys.sort()
|
||||
help_str = f"{type_ if type_ != 'normal' else '功能'}:\n\n"
|
||||
simple_help_str = f"{type_ if type_ != 'normal' else '功能'}:\n\n"
|
||||
for i, k in enumerate(keys):
|
||||
simple_help_str += f"{i+1}.{k}\n"
|
||||
if matchers_data[type_][k]["text_type"] == 1:
|
||||
_x = tmp_img.getsize(
|
||||
f"{i+1}".rjust(5)
|
||||
+ f'.{k}: {matchers_data[type_][k]["des"]} {"->" if matchers_data[type_][k]["cmd"] else ""} '
|
||||
)[0]
|
||||
_str = (
|
||||
f"{i+1}".rjust(5)
|
||||
+ f'.{k}: {matchers_data[type_][k]["des"]} {"->" if matchers_data[type_][k]["cmd"] else ""} '
|
||||
)
|
||||
_str += matchers_data[type_][k]["cmd"][0] + "\n"
|
||||
for c in matchers_data[type_][k]["cmd"][1:]:
|
||||
_str += "".rjust(int(_x * 0.125) + 1) + f"{c}\n"
|
||||
help_str += _str
|
||||
else:
|
||||
help_str += (
|
||||
f"{i+1}".rjust(5)
|
||||
+ f'.{k}: {matchers_data[type_][k]["des"]} {"->" if matchers_data[type_][k]["cmd"] else ""} '
|
||||
+ " / ".join(matchers_data[type_][k]["cmd"])
|
||||
+ "\n"
|
||||
)
|
||||
height = len(help_str.split("\n")) * (font_height + 5)
|
||||
simple_height = len(simple_help_str.split("\n")) * (font_height + 5)
|
||||
A = CreateImg(
|
||||
width + 150, height, font_size=24, color="white" if not ix % 2 else "black"
|
||||
)
|
||||
A.text((10, 10), help_str, (255, 255, 255) if ix % 2 else (0, 0, 0))
|
||||
simple_width = 0
|
||||
for x in [tmp_img.getsize(x)[0] for x in simple_help_str.split("\n")]:
|
||||
simple_width = simple_width if simple_width > x else x
|
||||
bk = CreateImg(
|
||||
simple_width + 20, simple_height, font_size=24, color="#6495ED"
|
||||
)
|
||||
B = CreateImg(
|
||||
simple_width + 20,
|
||||
simple_height,
|
||||
font_size=24,
|
||||
color="white" if not ix % 2 else "black",
|
||||
)
|
||||
B.text((10, 10), simple_help_str, (255, 255, 255) if ix % 2 else (0, 0, 0))
|
||||
bk.paste(B, center_type="center")
|
||||
bk.transparent(2)
|
||||
ix += 1
|
||||
help_img_list.append(A)
|
||||
simple_help_img_list.append(bk)
|
||||
height = 0
|
||||
for img in help_img_list:
|
||||
height += img.h
|
||||
A = CreateImg(width + 150, height + 50, font_size=24)
|
||||
A.text((10, 10), '* 注: ‘*’ 代表可有多个相同参数 ‘?’ 代表可省略该参数 *\n\n" "功能名: 功能简介 -> 指令\n\n')
|
||||
current_height = 50
|
||||
for img in help_img_list:
|
||||
A.paste(img, (0, current_height))
|
||||
current_height += img.h
|
||||
A.save(help_image)
|
||||
height = 0
|
||||
width = 0
|
||||
for img in simple_help_img_list:
|
||||
if img.h > height:
|
||||
height = img.h
|
||||
width += img.w + 10
|
||||
B = CreateImg(width + 100, height + 250, font_size=24)
|
||||
width, _ = get_max_width_or_paste(simple_help_img_list, B)
|
||||
bk = None
|
||||
random_bk = os.listdir(random_bk_path)
|
||||
if random_bk:
|
||||
bk = random.choice(random_bk)
|
||||
x = max(width + 50, height + 250)
|
||||
B = CreateImg(
|
||||
x,
|
||||
x,
|
||||
font_size=24,
|
||||
color="#FFEFD5",
|
||||
background=random_bk_path / bk,
|
||||
)
|
||||
A.text(
|
||||
(10, e.h + u.h + o.h + 250),
|
||||
f"【注】「色图概率:好感度 + {int(INITIAL_SETU_PROBABILITY*100)}%\n"
|
||||
f"\t\t每 3 点好感度 + 1次开箱,初始 {INITIAL_OPEN_CASE_COUNT} 次\n"
|
||||
f"\t\t开启/关闭功能只需输入‘开启/关闭 指令名’(每个功能的第一个指令)」\n"
|
||||
f"\t\t示例:开启签到\n"
|
||||
f"\t\t可以通过管理员开关自动发送消息(早晚安等)\n"
|
||||
f"\t\t^请查看管理员帮助^\n\n"
|
||||
f"\t「如果{NICKNAME}回复了一些不符合人设的话,那是因为每日白嫖的图灵次数已用完,使用的是备用接口【QAQ】」",
|
||||
)
|
||||
A.save(DATA_PATH + f"group_help/{group_id}.png")
|
||||
B.filter("GaussianBlur", 10)
|
||||
_, B = get_max_width_or_paste(simple_help_img_list, B, True)
|
||||
w = 10
|
||||
h = 10
|
||||
for msg in ['目前支持的功能列表:', '可以通过 ‘帮助[功能名称]’ 来获取对应功能的使用方法', '或者使用 ‘详细帮助’ 来获取所有功能方法']:
|
||||
text = CreateImg(
|
||||
0,
|
||||
0,
|
||||
plain_text=msg,
|
||||
font_size=24,
|
||||
color=(255, 255, 255, 0),
|
||||
font='yuanshen.ttf'
|
||||
)
|
||||
B.paste(text, (w, h), True)
|
||||
h += 50
|
||||
if msg == '目前支持的功能列表:':
|
||||
w += 50
|
||||
B.save(simple_help_image)
|
||||
|
||||
|
||||
def parse_cmd(cmd, group_id):
|
||||
flag = "√"
|
||||
dfg = None
|
||||
if cmd.find("draw_card") != -1:
|
||||
lst = cmd.split("_")
|
||||
cmd = lst[0] + "_" + lst[1]
|
||||
dfg = lst[-1]
|
||||
elif cmd == "pixiv_r":
|
||||
cmd = "pixiv"
|
||||
dfg = "r"
|
||||
elif cmd == "pixiv_s":
|
||||
cmd = "pixiv"
|
||||
dfg = "s"
|
||||
if not group_manager.get_plugin_status(cmd, group_id):
|
||||
flag = "×"
|
||||
if cmd in ["bt", "reimu", "nickname"]:
|
||||
flag = "- "
|
||||
return flag, dfg
|
||||
def get_max_width_or_paste(
|
||||
simple_help_img_list: list, B: CreateImg = None, is_paste: bool = False
|
||||
) -> "int, CreateImg":
|
||||
"""
|
||||
获取最大宽度,或直接贴图
|
||||
:param simple_help_img_list: 简单帮助图片列表
|
||||
:param B: 背景图
|
||||
:param is_paste: 是否直接贴图
|
||||
"""
|
||||
current_width = 50
|
||||
current_height = 180
|
||||
max_width = simple_help_img_list[0].w
|
||||
for i in range(len(simple_help_img_list)):
|
||||
try:
|
||||
if is_paste and B:
|
||||
B.paste(simple_help_img_list[i], (current_width, current_height), True)
|
||||
current_height += simple_help_img_list[i].h + 40
|
||||
if current_height + simple_help_img_list[i + 1].h > B.h - 10:
|
||||
current_height = 180
|
||||
current_width += max_width + 30
|
||||
max_width = 0
|
||||
elif simple_help_img_list[i].w > max_width:
|
||||
max_width = simple_help_img_list[i].w
|
||||
except IndexError:
|
||||
pass
|
||||
if current_width > simple_help_img_list[0].w + 50:
|
||||
current_width += simple_help_img_list[-1].w
|
||||
return current_width, B
|
||||
|
||||
|
||||
def rcmd(dfg):
|
||||
if dfg in [
|
||||
"prts",
|
||||
"genshin",
|
||||
"pretty",
|
||||
"guardian",
|
||||
"pcr",
|
||||
"azur",
|
||||
"onmyoji",
|
||||
"fgo",
|
||||
]:
|
||||
return "draw_card_" + dfg
|
||||
if dfg == "r":
|
||||
return "pixiv_r"
|
||||
if dfg == "s":
|
||||
return "pixiv_s"
|
||||
|
||||
|
||||
def get_plugin_help(msg: str) -> str:
|
||||
plugin = None
|
||||
for p in plugins2info_dict.keys():
|
||||
if msg in plugins2info_dict[p]["cmd"]:
|
||||
plugin = nonebot.plugin.get_plugin(p)
|
||||
break
|
||||
if plugin:
|
||||
result = plugin.module.__getattribute__("__plugin_usage__")
|
||||
return result
|
||||
else:
|
||||
return "没有此功能的帮助信息..."
|
||||
def get_plugin_help(msg: str, is_super: bool = False) -> Optional[str]:
|
||||
"""
|
||||
获取功能的帮助信息
|
||||
:param msg: 功能cmd
|
||||
:param is_super: 是否为超级用户
|
||||
"""
|
||||
module = plugins2settings_manager.get_plugin_module(msg)
|
||||
if module:
|
||||
try:
|
||||
plugin = nonebot.plugin.get_plugin(module)
|
||||
if plugin:
|
||||
if is_super:
|
||||
result = plugin.module.__getattribute__(
|
||||
"__plugin_superuser_usage__"
|
||||
)
|
||||
else:
|
||||
result = plugin.module.__getattribute__("__plugin_usage__")
|
||||
width = 0
|
||||
for x in result.split("\n"):
|
||||
_width = len(x) * 24
|
||||
width = width if width > _width else _width
|
||||
height = len(result.split("\n")) * 45
|
||||
A = CreateImg(width, height, font_size=24)
|
||||
bk = CreateImg(
|
||||
width, height, background=Path(IMAGE_PATH) / "background" / "1.png"
|
||||
)
|
||||
A.paste(bk, alpha=True)
|
||||
A.text((int(width * 0.048), int(height * 0.21)), result)
|
||||
return A.pic2bs4()
|
||||
except AttributeError:
|
||||
pass
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user