mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2025-07-27 06:20:56 +00:00
feat: 统一双引号
This commit is contained in:
@ -20,12 +20,12 @@ class StorePlugin(LiteModel):
|
||||
name: str
|
||||
desc: str
|
||||
module_name: str
|
||||
project_link: str = ''
|
||||
homepage: str = ''
|
||||
author: str = ''
|
||||
project_link: str = ""
|
||||
homepage: str =""
|
||||
author: str = ""
|
||||
type: str | None = None
|
||||
version: str | None = ''
|
||||
time: str = ''
|
||||
version: str | None = ""
|
||||
time: str = ""
|
||||
tags: list[PluginTag] = []
|
||||
is_official: bool = False
|
||||
|
||||
@ -59,7 +59,7 @@ def get_plugin_default_enable(plugin_module_name: str) -> bool:
|
||||
bool: 插件默认状态
|
||||
"""
|
||||
plug = nonebot.plugin.get_plugin_by_module_name(plugin_module_name)
|
||||
return (plug.metadata.extra.get('default_enable', True)
|
||||
return (plug.metadata.extra.get("default_enable", True)
|
||||
if plug.metadata else True) if plug else True
|
||||
|
||||
|
||||
@ -75,9 +75,9 @@ def get_plugin_session_enable(event: T_MessageEvent, plugin_module_name: str) ->
|
||||
bool: 插件当前状态
|
||||
"""
|
||||
if event.message_type == "group":
|
||||
session: GroupChat = group_db.first(GroupChat, 'group_id = ?', event.group_id, default=GroupChat(group_id=str(event.group_id)))
|
||||
session: GroupChat = group_db.first(GroupChat, "group_id = ?", event.group_id, default=GroupChat(group_id=str(event.group_id)))
|
||||
else:
|
||||
session: User = user_db.first(User, 'user_id = ?', event.user_id, default=User(user_id=str(event.user_id)))
|
||||
session: User = user_db.first(User, "user_id = ?", event.user_id, default=User(user_id=str(event.user_id)))
|
||||
# 默认停用插件在启用列表内表示启用
|
||||
# 默认停用插件不在启用列表内表示停用
|
||||
# 默认启用插件在停用列表内表示停用
|
||||
@ -104,4 +104,4 @@ def get_plugin_can_be_toggle(plugin_module_name: str) -> bool:
|
||||
bool: 插件是否可以被启用/停用
|
||||
"""
|
||||
plug = nonebot.plugin.get_plugin_by_module_name(plugin_module_name)
|
||||
return plug.metadata.extra.get('toggleable', True) if plug and plug.metadata else True
|
||||
return plug.metadata.extra.get("toggleable", True) if plug and plug.metadata else True
|
||||
|
@ -68,9 +68,9 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
if len(rs):
|
||||
reply = f"{ulang.get('npm.search_result')} | {ulang.get('npm.total', TOTAL=len(rs))}\n***"
|
||||
for plugin in rs[:min(max_show, len(rs))]:
|
||||
btn_install = md.button(ulang.get('npm.install'), 'npm install %s' % plugin.module_name)
|
||||
link_page = md.link(ulang.get('npm.homepage'), plugin.homepage)
|
||||
link_pypi = md.link(ulang.get('npm.pypi'), plugin.homepage)
|
||||
btn_install = md.button(ulang.get("npm.install"), "npm install %s" % plugin.module_name)
|
||||
link_page = md.link(ulang.get("npm.homepage"), plugin.homepage)
|
||||
link_pypi = md.link(ulang.get("npm.pypi"), plugin.homepage)
|
||||
|
||||
reply += (f"\n# **{plugin.name}**\n"
|
||||
f"\n> **{plugin.desc}**\n"
|
||||
@ -93,7 +93,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
if not store_plugin:
|
||||
await npm_alc.finish(ulang.get("npm.plugin_not_found", NAME=plugin_module_name))
|
||||
|
||||
homepage_btn = md.button(ulang.get('npm.homepage'), store_plugin.homepage)
|
||||
homepage_btn = md.button(ulang.get("npm.homepage"), store_plugin.homepage)
|
||||
if r:
|
||||
|
||||
r_load = nonebot.load_plugin(plugin_module_name) # 加载插件
|
||||
@ -103,7 +103,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
if r_load:
|
||||
if found_in_db_plugin is None:
|
||||
plugin_db.upsert(installed_plugin)
|
||||
info = ulang.get('npm.install_success', NAME=store_plugin.name).replace('_', r'\\_') # markdown转义
|
||||
info = md.escape(ulang.get("npm.install_success", NAME=store_plugin.name)) # markdown转义
|
||||
await send_markdown(
|
||||
f"{info}\n\n"
|
||||
f"```\n{log}\n```",
|
||||
@ -111,9 +111,9 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
event=event
|
||||
)
|
||||
else:
|
||||
await npm_alc.finish(ulang.get('npm.plugin_already_installed', NAME=store_plugin.name))
|
||||
await npm_alc.finish(ulang.get("npm.plugin_already_installed", NAME=store_plugin.name))
|
||||
else:
|
||||
info = ulang.get('npm.load_failed', NAME=plugin_module_name, HOMEPAGE=homepage_btn).replace('_', r'\\_')
|
||||
info = ulang.get("npm.load_failed", NAME=plugin_module_name, HOMEPAGE=homepage_btn).replace("_", r"\\_")
|
||||
await send_markdown(
|
||||
f"{info}\n\n"
|
||||
f"```\n{log}\n```\n",
|
||||
@ -121,7 +121,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
event=event
|
||||
)
|
||||
else:
|
||||
info = ulang.get('npm.install_failed', NAME=plugin_module_name, HOMEPAGE=homepage_btn).replace('_', r'\\_')
|
||||
info = ulang.get("npm.install_failed", NAME=plugin_module_name, HOMEPAGE=homepage_btn).replace("_", r"\\_")
|
||||
await send_markdown(
|
||||
f"{info}\n\n"
|
||||
f"```\n{log}\n```",
|
||||
@ -216,7 +216,7 @@ def npm_install(plugin_module_name) -> tuple[bool, str]:
|
||||
for mirror in mirrors:
|
||||
try:
|
||||
nonebot.logger.info(f"npm_install try mirror: {mirror}")
|
||||
result = pip.main(['install', plugin_module_name, "-i", mirror])
|
||||
result = pip.main(["install", plugin_module_name, "-i", mirror])
|
||||
success = result == 0
|
||||
if success:
|
||||
break
|
||||
|
@ -20,21 +20,21 @@ from nonebot_plugin_alconna import on_alconna, Alconna, Args, Arparma
|
||||
|
||||
list_plugins = on_alconna(
|
||||
Alconna(
|
||||
['list-plugins', "插件列表", "列出插件"],
|
||||
["list-plugins", "插件列表", "列出插件"],
|
||||
)
|
||||
)
|
||||
|
||||
toggle_plugin = on_alconna(
|
||||
Alconna(
|
||||
['enable-plugin', 'disable-plugin'],
|
||||
Args['plugin_name', str],
|
||||
["enable-plugin", "disable-plugin"],
|
||||
Args["plugin_name", str],
|
||||
)
|
||||
)
|
||||
|
||||
global_toggle = on_alconna(
|
||||
Alconna(
|
||||
['toggle-global'],
|
||||
Args['plugin_name', str],
|
||||
["toggle-global"],
|
||||
Args["plugin_name", str],
|
||||
),
|
||||
permission=SUPERUSER
|
||||
)
|
||||
@ -49,27 +49,27 @@ async def _(event: T_MessageEvent, bot: T_Bot):
|
||||
for plugin in nonebot.get_loaded_plugins():
|
||||
# 检查是否有 metadata 属性
|
||||
# 添加帮助按钮
|
||||
btn_usage = md.button(lang.get('npm.usage'), f'help {plugin.module_name}', False)
|
||||
btn_usage = md.button(lang.get("npm.usage"), f"help {plugin.module_name}", False)
|
||||
store_plugin = await get_store_plugin(plugin.module_name)
|
||||
|
||||
session_enable = get_plugin_session_enable(event, plugin.module_name)
|
||||
default_enable = get_plugin_default_enable(plugin.module_name)
|
||||
|
||||
if store_plugin:
|
||||
btn_homepage = md.link(lang.get('npm.homepage'), store_plugin.homepage)
|
||||
btn_homepage = md.link(lang.get("npm.homepage"), store_plugin.homepage)
|
||||
show_name = store_plugin.name
|
||||
show_desc = store_plugin.desc
|
||||
elif plugin.metadata:
|
||||
if plugin.metadata.extra.get('liteyuki'):
|
||||
btn_homepage = md.link(lang.get('npm.homepage'), "https://github.com/snowykami/LiteyukiBot")
|
||||
if plugin.metadata.extra.get("liteyuki"):
|
||||
btn_homepage = md.link(lang.get("npm.homepage"), "https://github.com/snowykami/LiteyukiBot")
|
||||
else:
|
||||
btn_homepage = lang.get('npm.homepage')
|
||||
btn_homepage = lang.get("npm.homepage")
|
||||
show_name = plugin.metadata.name
|
||||
show_desc = plugin.metadata.description
|
||||
else:
|
||||
btn_homepage = lang.get('npm.homepage')
|
||||
btn_homepage = lang.get("npm.homepage")
|
||||
show_name = plugin.name
|
||||
show_desc = lang.get('npm.no_description')
|
||||
show_desc = lang.get("npm.no_description")
|
||||
|
||||
if plugin.metadata:
|
||||
reply += (f"\n**{md.escape(show_name)}**\n"
|
||||
@ -83,22 +83,22 @@ async def _(event: T_MessageEvent, bot: T_Bot):
|
||||
if await GROUP_ADMIN(bot, event) or await GROUP_OWNER(bot, event) or await SUPERUSER(bot, event):
|
||||
# 添加启用/停用插件按钮
|
||||
cmd_toggle = f"{'disable' if session_enable else 'enable'}-plugin {plugin.module_name}"
|
||||
text_toggle = lang.get('npm.disable' if session_enable else 'npm.enable')
|
||||
text_toggle = lang.get("npm.disable" if session_enable else "npm.enable")
|
||||
can_be_toggle = get_plugin_can_be_toggle(plugin.module_name)
|
||||
btn_toggle = text_toggle if not can_be_toggle else md.button(text_toggle, cmd_toggle)
|
||||
|
||||
reply += f" {btn_toggle}"
|
||||
|
||||
if await SUPERUSER(bot, event):
|
||||
plugin_in_database = plugin_db.first(InstalledPlugin, 'module_name = ?', plugin.module_name)
|
||||
plugin_in_database = plugin_db.first(InstalledPlugin, "module_name = ?", plugin.module_name)
|
||||
# 添加移除插件和全局切换按钮
|
||||
global_enable = get_plugin_global_enable(plugin.module_name)
|
||||
btn_uninstall = (
|
||||
md.button(lang.get('npm.uninstall'), f'npm uninstall {plugin.module_name}')) if plugin_in_database else lang.get(
|
||||
md.button(lang.get("npm.uninstall"), f'npm uninstall {plugin.module_name}')) if plugin_in_database else lang.get(
|
||||
'npm.uninstall')
|
||||
|
||||
btn_toggle_global_text = lang.get('npm.disable_global' if global_enable else 'npm.enable_global')
|
||||
cmd_toggle_global = f'npm toggle-global {plugin.module_name}'
|
||||
btn_toggle_global_text = lang.get("npm.disable_global" if global_enable else "npm.enable_global")
|
||||
cmd_toggle_global = f"npm toggle-global {plugin.module_name}"
|
||||
btn_toggle_global = btn_toggle_global_text if not can_be_toggle else md.button(btn_toggle_global_text, cmd_toggle_global)
|
||||
|
||||
reply += f" {btn_uninstall} {btn_toggle_global}"
|
||||
@ -115,7 +115,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
ulang = get_user_lang(str(event.user_id))
|
||||
plugin_module_name = result.args.get("plugin_name")
|
||||
|
||||
toggle = result.header_result == 'enable-plugin' # 判断是启用还是停用
|
||||
toggle = result.header_result == "enable-plugin" # 判断是启用还是停用
|
||||
|
||||
session_enable = get_plugin_session_enable(event, plugin_module_name) # 获取插件当前状态
|
||||
|
||||
@ -149,7 +149,6 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot):
|
||||
else:
|
||||
session.enabled_plugins.remove(plugin_module_name)
|
||||
if event.message_type == "private":
|
||||
print("已保存")
|
||||
user_db.upsert(session)
|
||||
else:
|
||||
group_db.upsert(session)
|
||||
|
@ -9,8 +9,8 @@ __plugin_meta__ = PluginMetadata(
|
||||
usage="",
|
||||
homepage="https://github.com/snowykami/LiteyukiBot",
|
||||
extra={
|
||||
"liteyuki": True,
|
||||
"toggleable" : False,
|
||||
"default_enable" : True,
|
||||
"liteyuki" : True,
|
||||
"toggleable" : False,
|
||||
"default_enable": True,
|
||||
}
|
||||
)
|
||||
|
@ -1,2 +0,0 @@
|
||||
def detect_lang(input_str: str) -> str:
|
||||
return "zh-CN" if input_str == "zh" else "en"
|
@ -116,7 +116,7 @@ def get_profile_menu(key: str, ulang: Language) -> Optional[str]:
|
||||
reply = f"**{setting_name} {ulang.get('user.profile.settings')}**\n***\n"
|
||||
if key == "lang":
|
||||
for lang_code, lang_name in get_all_lang().items():
|
||||
btn_set = md.button(ulang.get('user.profile.set'), f"profile set {key} {lang_code}")
|
||||
btn_set = md.button(ulang.get("user.profile.set"), f"profile set {key} {lang_code}")
|
||||
reply += f"\n{btn_set} | **{lang_name}** - {lang_code}\n***\n"
|
||||
elif key == "timezone":
|
||||
for tz in representative_timezones_list:
|
||||
@ -135,9 +135,9 @@ def set_profile(key: str, value: str) -> bool:
|
||||
是否成功设置,输入合法性不通过返回False
|
||||
|
||||
"""
|
||||
if key == 'lang':
|
||||
if key == "lang":
|
||||
if value in get_all_lang():
|
||||
return True
|
||||
elif key == 'timezone':
|
||||
elif key == "timezone":
|
||||
if value in pytz.all_timezones:
|
||||
return True
|
||||
|
Reference in New Issue
Block a user