Merge branch 'dev' of https://github.com/MoFox-Studio/MoFox_Bot into dev
This commit is contained in:
@@ -226,56 +226,42 @@ class SingleStreamContextManager:
|
|||||||
self.access_count += 1
|
self.access_count += 1
|
||||||
|
|
||||||
async def _calculate_message_interest(self, message: DatabaseMessages) -> float:
|
async def _calculate_message_interest(self, message: DatabaseMessages) -> float:
|
||||||
"""异步实现:使用插件的异步评分器正确 await 计算兴趣度并返回分数。"""
|
"""
|
||||||
try:
|
异步计算消息的兴趣度。
|
||||||
|
此方法通过检查当前是否存在正在运行的 asyncio 事件循环来兼容同步和异步调用。
|
||||||
|
"""
|
||||||
|
# 内部异步函数,封装实际的计算逻辑
|
||||||
|
async def _get_score():
|
||||||
try:
|
try:
|
||||||
from src.plugins.built_in.affinity_flow_chatter.interest_scoring import (
|
from src.plugins.built_in.affinity_flow_chatter.interest_scoring import (
|
||||||
chatter_interest_scoring_system,
|
chatter_interest_scoring_system,
|
||||||
)
|
)
|
||||||
try:
|
interest_score = await chatter_interest_scoring_system._calculate_single_message_score(
|
||||||
interest_score = await chatter_interest_scoring_system._calculate_single_message_score(
|
message=message, bot_nickname=global_config.bot.nickname
|
||||||
message=message, bot_nickname=global_config.bot.nickname
|
|
||||||
)
|
|
||||||
interest_value = interest_score.total_score
|
|
||||||
logger.debug(f"使用插件内部系统计算兴趣度: {interest_value:.3f}")
|
|
||||||
return interest_value
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"插件内部兴趣度计算失败: {e}")
|
|
||||||
return 0.5
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"插件内部兴趣度计算加载失败,使用默认值: {e}")
|
|
||||||
return 0.5
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"计算消息兴趣度失败: {e}")
|
|
||||||
return 0.5
|
|
||||||
|
|
||||||
async def _calculate_message_interest_async(self, message: DatabaseMessages) -> float:
|
|
||||||
"""异步实现:使用插件的异步评分器正确 await 计算兴趣度并返回分数。"""
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
from src.plugins.built_in.affinity_flow_chatter.interest_scoring import (
|
|
||||||
chatter_interest_scoring_system,
|
|
||||||
)
|
)
|
||||||
|
interest_value = interest_score.total_score
|
||||||
# 直接 await 插件的异步方法
|
logger.debug(f"使用插件内部系统计算兴趣度: {interest_value:.3f}")
|
||||||
try:
|
return interest_value
|
||||||
interest_score = await chatter_interest_scoring_system._calculate_single_message_score(
|
except ImportError as e:
|
||||||
message=message, bot_nickname=global_config.bot.nickname
|
logger.debug(f"兴趣度计算插件加载失败,可能未启用: {e}")
|
||||||
)
|
return 0.5
|
||||||
interest_value = interest_score.total_score
|
|
||||||
logger.debug(f"使用插件内部系统计算兴趣度: {interest_value:.3f}")
|
|
||||||
return interest_value
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"插件内部兴趣度计算失败: {e}")
|
|
||||||
return 0.5
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"插件内部兴趣度计算加载失败,使用默认值: {e}")
|
# 在某些情况下(例如机器人自己的消息),没有兴趣度是正常的
|
||||||
|
logger.info(f"插件内部兴趣度计算失败,使用默认值: {e}")
|
||||||
return 0.5
|
return 0.5
|
||||||
|
|
||||||
except Exception as e:
|
# 检查并获取当前事件循环
|
||||||
logger.error(f"计算消息兴趣度失败: {e}")
|
try:
|
||||||
return 0.5
|
loop = asyncio.get_running_loop()
|
||||||
|
except RuntimeError: # 'RuntimeError: There is no current event loop...'
|
||||||
|
loop = None
|
||||||
|
|
||||||
|
if loop and loop.is_running():
|
||||||
|
# 如果事件循环正在运行,直接 await
|
||||||
|
return await _get_score()
|
||||||
|
else:
|
||||||
|
# 否则,使用 asyncio.run() 来安全执行
|
||||||
|
return asyncio.run(_get_score())
|
||||||
|
|
||||||
async def add_message_async(self, message: DatabaseMessages, skip_energy_update: bool = False) -> bool:
|
async def add_message_async(self, message: DatabaseMessages, skip_energy_update: bool = False) -> bool:
|
||||||
"""异步实现的 add_message:将消息添加到 context,并 await 能量更新与分发。"""
|
"""异步实现的 add_message:将消息添加到 context,并 await 能量更新与分发。"""
|
||||||
|
|||||||
@@ -156,7 +156,10 @@ class SendHandler:
|
|||||||
logger.error("命令或参数缺失")
|
logger.error("命令或参数缺失")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
logger.info(f"准备向 Napcat 发送命令: command='{command}', args_dict='{args_dict}'")
|
||||||
response = await self.send_message_to_napcat(command, args_dict)
|
response = await self.send_message_to_napcat(command, args_dict)
|
||||||
|
logger.info(f"收到 Napcat 的命令响应: {response}")
|
||||||
|
|
||||||
if response.get("status") == "ok":
|
if response.get("status") == "ok":
|
||||||
logger.info(f"命令 {command_name} 执行成功")
|
logger.info(f"命令 {command_name} 执行成功")
|
||||||
else:
|
else:
|
||||||
@@ -530,12 +533,14 @@ class SendHandler:
|
|||||||
Returns:
|
Returns:
|
||||||
Tuple[CommandType, Dict[str, Any]]
|
Tuple[CommandType, Dict[str, Any]]
|
||||||
"""
|
"""
|
||||||
|
logger.info(f"开始处理表情回应命令, 接收到参数: {args}")
|
||||||
try:
|
try:
|
||||||
message_id = int(args["message_id"])
|
message_id = int(args["message_id"])
|
||||||
emoji_id = int(args["emoji_id"])
|
emoji_id = int(args["emoji_id"])
|
||||||
set_like = str(args["set"])
|
set_like = str(args["set"])
|
||||||
except:
|
except (KeyError, ValueError) as e:
|
||||||
raise ValueError("缺少必需参数: message_id 或 emoji_id")
|
logger.error(f"处理表情回应命令时发生错误: {e}, 原始参数: {args}")
|
||||||
|
raise ValueError(f"缺少必需参数或参数类型错误: {e}")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
CommandType.SET_EMOJI_LIKE.value,
|
CommandType.SET_EMOJI_LIKE.value,
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class PokeAction(BaseAction):
|
|||||||
# === 基本信息(必须填写)===
|
# === 基本信息(必须填写)===
|
||||||
action_name = "poke_user"
|
action_name = "poke_user"
|
||||||
action_description = "向用户发送戳一戳"
|
action_description = "向用户发送戳一戳"
|
||||||
activation_type = ActionActivationType.ALWAYS
|
activation_type = ActionActivationType.LLM_JUDGE
|
||||||
parallel_action = True
|
parallel_action = True
|
||||||
|
|
||||||
# === 功能描述(必须填写)===
|
# === 功能描述(必须填写)===
|
||||||
@@ -157,8 +157,10 @@ class PokeAction(BaseAction):
|
|||||||
3. **互动提醒**: 你想以一种有趣的方式提醒或与某人互动,但请确保这是对话的自然延伸,而不是无故打扰。
|
3. **互动提醒**: 你想以一种有趣的方式提醒或与某人互动,但请确保这是对话的自然延伸,而不是无故打扰。
|
||||||
4. **上下文需求**: 上下文明确需要你戳一个或多个人。
|
4. **上下文需求**: 上下文明确需要你戳一个或多个人。
|
||||||
5. **频率限制**: 如果最近已经戳过,或者用户情绪不高,请绝对不要使用。
|
5. **频率限制**: 如果最近已经戳过,或者用户情绪不高,请绝对不要使用。
|
||||||
|
6. **核心原则**:
|
||||||
请回答"是"或"否"。
|
* 这是一个**强打扰**且**高消耗**的动作。
|
||||||
|
* **禁止**在模糊情境下使用。
|
||||||
|
请严格根据上述规则,回答“是”或“否”。
|
||||||
"""
|
"""
|
||||||
associated_types = ["text"]
|
associated_types = ["text"]
|
||||||
|
|
||||||
@@ -169,6 +171,8 @@ class PokeAction(BaseAction):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
times = int(self.action_data.get("times", 1))
|
times = int(self.action_data.get("times", 1))
|
||||||
|
if times > 3:
|
||||||
|
times = 3
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
times = 1
|
times = 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user