mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🎨 功能开关代码优化 (#1680)
* 🎨 功能开关代码优化
* chore(version): Update version to v0.2.3-5f361ff
---------
Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
This commit is contained in:
parent
f0063283e7
commit
a28a60d9c8
@ -1 +1 @@
|
|||||||
__version__: v0.2.3-27e13e0
|
__version__: v0.2.3-5f361ff
|
||||||
|
|||||||
@ -133,7 +133,7 @@ async def build_task(group_id: str | None) -> BuildImage:
|
|||||||
task.id,
|
task.id,
|
||||||
task.module,
|
task.module,
|
||||||
task.name,
|
task.name,
|
||||||
"开启" if task.module not in group.block_task else "关闭",
|
"开启" if f"<{task.module}," not in group.block_task else "关闭",
|
||||||
"开启" if task.status else "关闭",
|
"开启" if task.status else "关闭",
|
||||||
task.run_time or "-",
|
task.run_time or "-",
|
||||||
]
|
]
|
||||||
@ -214,9 +214,6 @@ class PluginManage:
|
|||||||
f"<{module},", ""
|
f"<{module},", ""
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
module_list = await PluginInfo.filter(
|
|
||||||
plugin_type=PluginType.NORMAL
|
|
||||||
).values_list("module", flat=True)
|
|
||||||
module_list = [f"<{module}" for module in module_list]
|
module_list = [f"<{module}" for module in module_list]
|
||||||
group.block_plugin = ",".join(module_list) + "," # type: ignore
|
group.block_plugin = ",".join(module_list) + "," # type: ignore
|
||||||
await group.save(update_fields=["block_plugin"])
|
await group.save(update_fields=["block_plugin"])
|
||||||
|
|||||||
@ -70,16 +70,20 @@ async def _():
|
|||||||
data_list = []
|
data_list = []
|
||||||
for group in await GroupConsole.all():
|
for group in await GroupConsole.all():
|
||||||
if group.block_plugin:
|
if group.block_plugin:
|
||||||
if modules := group.block_plugin.split(",")[:-1]:
|
if modules := group.block_plugin.split(","):
|
||||||
if block_plugin := [
|
if block_plugin := [
|
||||||
f"<{module}" for module in modules if not module.startswith("<")
|
f"<{module}" for module in modules if not module.startswith("<")
|
||||||
]:
|
]:
|
||||||
group.block_plugin = ",".join(block_plugin) + ","
|
group.block_plugin = (",".join(block_plugin) + ",").replace(
|
||||||
|
"<,", ""
|
||||||
|
)
|
||||||
if group.block_task:
|
if group.block_task:
|
||||||
if modules := group.block_task.split(",")[:-1]:
|
if modules := group.block_task.split(","):
|
||||||
if block_task := [
|
if block_task := [
|
||||||
f"<{module}" for module in modules if not module.startswith("<")
|
f"<{module}" for module in modules if not module.startswith("<")
|
||||||
]:
|
]:
|
||||||
group.block_task = ",".join(block_task) + ","
|
group.block_task = (",".join(block_task) + ",").replace(
|
||||||
|
"<,", ""
|
||||||
|
)
|
||||||
data_list.append(group)
|
data_list.append(group)
|
||||||
await GroupConsole.bulk_update(data_list, ["block_plugin", "block_task"], 10)
|
await GroupConsole.bulk_update(data_list, ["block_plugin", "block_task"], 10)
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
|
from typing import Any, overload
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Dict, overload
|
|
||||||
|
|
||||||
from nonebot import require
|
from nonebot import require
|
||||||
|
|
||||||
require("nonebot_plugin_session")
|
require("nonebot_plugin_session")
|
||||||
from loguru import logger as logger_
|
from loguru import logger as logger_
|
||||||
from nonebot.log import default_filter, default_format
|
|
||||||
from nonebot_plugin_session import Session
|
from nonebot_plugin_session import Session
|
||||||
|
from nonebot.log import default_filter, default_format
|
||||||
|
|
||||||
from zhenxun.configs.path_config import LOG_PATH
|
from zhenxun.configs.path_config import LOG_PATH
|
||||||
|
|
||||||
@ -33,8 +33,10 @@ class logger:
|
|||||||
TEMPLATE_A = "Adapter[{}] {}"
|
TEMPLATE_A = "Adapter[{}] {}"
|
||||||
TEMPLATE_B = "Adapter[{}] [<u><c>{}</c></u>]: {}"
|
TEMPLATE_B = "Adapter[{}] [<u><c>{}</c></u>]: {}"
|
||||||
TEMPLATE_C = "Adapter[{}] 用户[<u><e>{}</e></u>] 触发 [<u><c>{}</c></u>]: {}"
|
TEMPLATE_C = "Adapter[{}] 用户[<u><e>{}</e></u>] 触发 [<u><c>{}</c></u>]: {}"
|
||||||
TEMPLATE_D = "Adapter[{}] 群聊[<u><e>{}</e></u>] 用户[<u><e>{}</e></u>] 触发 [<u><c>{}</c></u>]: {}"
|
TEMPLATE_D = "Adapter[{}] 群聊[<u><e>{}</e></u>] 用户[<u><e>{}</e></u>] 触发"
|
||||||
TEMPLATE_E = "Adapter[{}] 群聊[<u><e>{}</e></u>] 用户[<u><e>{}</e></u>] 触发 [<u><c>{}</c></u>] [Target](<u><e>{}</e></u>): {}"
|
" [<u><c>{}</c></u>]: {}"
|
||||||
|
TEMPLATE_E = "Adapter[{}] 群聊[<u><e>{}</e></u>] 用户[<u><e>{}</e></u>] 触发"
|
||||||
|
" [<u><c>{}</c></u>] [Target](<u><e>{}</e></u>): {}"
|
||||||
|
|
||||||
TEMPLATE_ADAPTER = "Adapter[<m>{}</m>] "
|
TEMPLATE_ADAPTER = "Adapter[<m>{}</m>] "
|
||||||
TEMPLATE_USER = "用户[<u><e>{}</e></u>] "
|
TEMPLATE_USER = "用户[<u><e>{}</e></u>] "
|
||||||
@ -88,8 +90,7 @@ class logger:
|
|||||||
platform: str | None = None,
|
platform: str | None = None,
|
||||||
):
|
):
|
||||||
user_id: str | None = session # type: ignore
|
user_id: str | None = session # type: ignore
|
||||||
group_id = None
|
if isinstance(session, Session):
|
||||||
if type(session) == Session:
|
|
||||||
user_id = session.id1
|
user_id = session.id1
|
||||||
adapter = session.bot_type
|
adapter = session.bot_type
|
||||||
if session.id3:
|
if session.id3:
|
||||||
@ -102,7 +103,7 @@ class logger:
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
logger_.opt(colors=True).info(template)
|
logger_.opt(colors=True).info(template)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger_.info(template)
|
logger_.info(template)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -110,7 +111,7 @@ class logger:
|
|||||||
cls,
|
cls,
|
||||||
info: str,
|
info: str,
|
||||||
command: str,
|
command: str,
|
||||||
param: Dict[str, Any] | None = None,
|
param: dict[str, Any] | None = None,
|
||||||
result: str = "",
|
result: str = "",
|
||||||
):
|
):
|
||||||
param_str = ""
|
param_str = ""
|
||||||
@ -163,8 +164,7 @@ class logger:
|
|||||||
e: Exception | None = None,
|
e: Exception | None = None,
|
||||||
):
|
):
|
||||||
user_id: str | None = session # type: ignore
|
user_id: str | None = session # type: ignore
|
||||||
group_id = None
|
if isinstance(session, Session):
|
||||||
if type(session) == Session:
|
|
||||||
user_id = session.id1
|
user_id = session.id1
|
||||||
adapter = session.bot_type
|
adapter = session.bot_type
|
||||||
if session.id3:
|
if session.id3:
|
||||||
@ -224,8 +224,7 @@ class logger:
|
|||||||
e: Exception | None = None,
|
e: Exception | None = None,
|
||||||
):
|
):
|
||||||
user_id: str | None = session # type: ignore
|
user_id: str | None = session # type: ignore
|
||||||
group_id = None
|
if isinstance(session, Session):
|
||||||
if type(session) == Session:
|
|
||||||
user_id = session.id1
|
user_id = session.id1
|
||||||
adapter = session.bot_type
|
adapter = session.bot_type
|
||||||
if session.id3:
|
if session.id3:
|
||||||
@ -285,8 +284,7 @@ class logger:
|
|||||||
e: Exception | None = None,
|
e: Exception | None = None,
|
||||||
):
|
):
|
||||||
user_id: str | None = session # type: ignore
|
user_id: str | None = session # type: ignore
|
||||||
group_id = None
|
if isinstance(session, Session):
|
||||||
if type(session) == Session:
|
|
||||||
user_id = session.id1
|
user_id = session.id1
|
||||||
adapter = session.bot_type
|
adapter = session.bot_type
|
||||||
if session.id3:
|
if session.id3:
|
||||||
|
|||||||
@ -604,6 +604,11 @@ async def broadcast_group(
|
|||||||
or group.channel_id in ignore_group
|
or group.channel_id in ignore_group
|
||||||
)
|
)
|
||||||
) or key in _used_group:
|
) or key in _used_group:
|
||||||
|
logger.debug(
|
||||||
|
"广播方法群组重复, 已跳过...",
|
||||||
|
log_cmd,
|
||||||
|
group_id=group.group_id,
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
is_run = False
|
is_run = False
|
||||||
if check_func:
|
if check_func:
|
||||||
@ -612,6 +617,11 @@ async def broadcast_group(
|
|||||||
else:
|
else:
|
||||||
is_run = check_func(group.group_id)
|
is_run = check_func(group.group_id)
|
||||||
if not is_run:
|
if not is_run:
|
||||||
|
logger.debug(
|
||||||
|
"广播方法检测运行方法为 False, 已跳过...",
|
||||||
|
log_cmd,
|
||||||
|
group_id=group.group_id,
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
target = PlatformUtils.get_target(
|
target = PlatformUtils.get_target(
|
||||||
_bot, None, group.group_id, group.channel_id
|
_bot, None, group.group_id, group.channel_id
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user