feat: 对部分消息回复用markdown进行了重新排版

This commit is contained in:
snowy 2024-03-20 22:30:52 +08:00
parent 2b8cb2afb6
commit 14d9f041ce
7 changed files with 51 additions and 10 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ compile.bat
# nuitka
main.build/
main.exe
main.cmd

View File

@ -0,0 +1,10 @@
import pip
def install(plugin_name) -> bool:
try:
pip.main(['install', plugin_name])
return True
except Exception as e:
print(e)
return False

View File

@ -2,7 +2,7 @@ import nonebot.plugin
from nonebot import on_command
from nonebot.permission import SUPERUSER
from src.utils.message import send_markdown
from src.utils.message import button, send_markdown
from src.utils.typing import T_Bot, T_MessageEvent
from src.utils.language import get_user_lang
@ -17,7 +17,9 @@ async def _(event: T_MessageEvent, bot: T_Bot):
for plugin in nonebot.get_loaded_plugins():
# 检查是否有 metadata 属性
if plugin.metadata:
reply += f"\n- **{plugin.metadata.name}**".replace('_', r'\_')
reply += (f"\n{button(lang.get('npm.disable'), 'disable-plugin %s' % plugin.name, False, False)} **{plugin.metadata.name}**\n"
f"\n > {plugin.metadata.description}\n\n***\n")
else:
reply += f"\n- **{plugin.name}**".replace('_', r'\_')
reply += (f"\n{button(lang.get('npm.disable'), 'disable-plugin %s' % plugin.name, False, False)} **{plugin.name}**\n"
f"\n > {lang.get('npm.no_description')}\n\n***\n")
await send_markdown(reply, bot, event=event)

View File

@ -12,6 +12,9 @@ main.monitor.usage=Usage
npm.loaded_plugins=Loaded plugins
npm.total=Total {TOTAL}
npm.disable=Disable
npm.enable=Enable
npm.no_description=No description
user.profile_manager.query=Your {ATTR} is {VALUE}
user.profile_manager.set=Your {ATTR} has been set to {VALUE}

View File

@ -12,6 +12,9 @@ main.monitor.usage=使用率
npm.loaded_plugins=已加载插件
npm.total=总计 {TOTAL}
npm.disable=停用
npm.enable=启用
npm.no_description=无描述
user.profile_manager.query=你的个人信息 {ATTR} 为 {VALUE}
user.profile_manager.set=你的个人信息 {ATTR} 已设置为 {VALUE}

View File

@ -2,7 +2,7 @@ import nonebot
from nonebot.adapters.onebot import v11, v12
from typing_extensions import Any
from .tools import de_escape
from .tools import de_escape, encode_url
from .typing import T_Bot, T_MessageEvent
@ -71,3 +71,18 @@ async def send_markdown(markdown: str, bot: T_Bot, *, message_type: str=None, s
nonebot.logger.error("send_markdown: bot type not supported")
data = {}
return data
def button(name: str, cmd: str, reply: bool = False, enter: bool = True) -> str:
"""生成点击按钮的链接
Args:
name:
cmd:
reply: 是否以回复的方式发送消息
enter: 自动发送消息则为True
Returns:
markdown格式的链接
"""
return f"[{name}](mqqapi://aio/inlinecmd?command={encode_url(cmd)}&reply={str(reply).lower()}&enter={str(enter).lower()})"

View File

@ -1,3 +1,6 @@
from urllib.parse import quote
def convert_size(size: int, precision: int = 2, add_unit: bool = True, suffix: str = "iB") -> str:
"""把字节数转换为人类可读的字符串,计算正负
@ -42,3 +45,7 @@ def de_escape(text: str) -> str:
text = text.replace(k, v)
return text
def encode_url(text: str) -> str:
return quote(text, safe="")