Merge branch 'dev' of https://github.com/MoFox-Studio/MoFox-Core into dev
This commit is contained in:
10
bot.py
10
bot.py
@@ -249,7 +249,7 @@ class ShutdownManager:
|
||||
return success
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"麦麦关闭失败: {e}")
|
||||
logger.error(f"麦麦关闭失败: {e}", exc_info=True)
|
||||
return False
|
||||
|
||||
|
||||
@@ -602,12 +602,11 @@ class MaiBotMain:
|
||||
async def wait_for_user_input():
|
||||
"""等待用户输入(异步方式)"""
|
||||
try:
|
||||
# 在非生产环境下,使用异步方式等待输入
|
||||
if os.getenv("ENVIRONMENT") != "production":
|
||||
logger.info("程序执行完成,按 Ctrl+C 退出...")
|
||||
# 使用 Event 替代 sleep 循环,避免阻塞事件循环
|
||||
shutdown_event = asyncio.Event()
|
||||
await shutdown_event.wait()
|
||||
# 使用非阻塞循环
|
||||
while True:
|
||||
await asyncio.sleep(0.1)
|
||||
except KeyboardInterrupt:
|
||||
logger.info("用户中断程序")
|
||||
return True
|
||||
@@ -616,6 +615,7 @@ async def wait_for_user_input():
|
||||
return False
|
||||
|
||||
|
||||
|
||||
async def main_async():
|
||||
"""主异步函数"""
|
||||
exit_code = 0
|
||||
|
||||
@@ -1129,6 +1129,10 @@ class DefaultReplyer:
|
||||
if reply_to:
|
||||
# 兼容旧的reply_to
|
||||
sender, target = self._parse_reply_target(reply_to)
|
||||
# 回退逻辑:为 'reply_to' 路径提供 platform 和 user_id 的回退值,以修复 UnboundLocalError
|
||||
# 这样就不再强制要求必须有 user_id,解决了QQ空间插件等场景下的崩溃问题
|
||||
platform = chat_stream.platform
|
||||
user_id = ""
|
||||
else:
|
||||
# 对于 respond 动作,reply_message 可能为 None(统一回应未读消息)
|
||||
# 对于 reply 动作,reply_message 必须存在(针对特定消息回复)
|
||||
|
||||
@@ -50,6 +50,8 @@ class NapcatAdapter(BaseAdapter):
|
||||
host = config_api.get_plugin_config(plugin.config, "napcat_server.host", "localhost")
|
||||
port = config_api.get_plugin_config(plugin.config, "napcat_server.port", 8095)
|
||||
access_token = config_api.get_plugin_config(plugin.config, "napcat_server.access_token", "")
|
||||
mode_str = config_api.get_plugin_config(plugin.config, "napcat_server.mode", "reverse")
|
||||
ws_mode = "client" if mode_str == "direct" else "server"
|
||||
|
||||
ws_url = f"ws://{host}:{port}"
|
||||
headers = {}
|
||||
@@ -58,10 +60,11 @@ class NapcatAdapter(BaseAdapter):
|
||||
else:
|
||||
ws_url = "ws://127.0.0.1:8095"
|
||||
headers = {}
|
||||
ws_mode = "server"
|
||||
|
||||
# 配置 WebSocket 传输
|
||||
transport = WebSocketAdapterOptions(
|
||||
mode="server",
|
||||
mode=ws_mode,
|
||||
url=ws_url,
|
||||
headers=headers if headers else None,
|
||||
)
|
||||
|
||||
@@ -79,7 +79,7 @@ class MessageHandler:
|
||||
|
||||
# 获取群聊配置
|
||||
group_list_type = features_config.get("group_list_type", "blacklist")
|
||||
group_list = features_config.get("group_list", [])
|
||||
group_list = [str(item) for item in features_config.get("group_list", [])]
|
||||
|
||||
if group_list_type == "blacklist":
|
||||
# 黑名单模式:如果在黑名单中就过滤
|
||||
@@ -96,7 +96,7 @@ class MessageHandler:
|
||||
elif message_type == "private":
|
||||
# 获取私聊配置
|
||||
private_list_type = features_config.get("private_list_type", "blacklist")
|
||||
private_list = features_config.get("private_list", [])
|
||||
private_list = [str(item) for item in features_config.get("private_list", [])]
|
||||
|
||||
if private_list_type == "blacklist":
|
||||
# 黑名单模式:如果在黑名单中就过滤
|
||||
|
||||
Reference in New Issue
Block a user