fix(chat): 修复戳一戳等notice事件无法触发聊天流程的问题
该修复解决了机器人对“戳一戳”等 notice 事件没有响应的 bug。 问题根源在于 MessageManager 在处理 notice 消息时,仅将其添加到全局通知管理器后便直接返回,导致消息无法进入后续的聊天处理流程,即使相关配置已开启。 主要变更: 修改 Elysia/Bot/src/chat/message_manager/message_manager.py,在处理 notice 消息时,增加对 bot_config.toml 中 enable_notice_trigger_chat 配置的判断。只有在该配置为 false 时才中断流程,否则将消息继续送入聊天上下文。 修复了 _get_notice_ttl 函数中因 notice_type 可能为 None 而引发的潜在 TypeError。 将 Bot/src/config/official_configs.py 中 enable_notice_trigger_chat 的默认值从 False 修改为 True,以提供更合理的开箱即用体验。
This commit is contained in:
@@ -159,10 +159,17 @@ class MessageManager:
|
|||||||
try:
|
try:
|
||||||
# 检查是否为notice消息
|
# 检查是否为notice消息
|
||||||
if self._is_notice_message(message):
|
if self._is_notice_message(message):
|
||||||
# Notice消息处理 - 不进入未读消息
|
# Notice消息处理 - 添加到全局管理器
|
||||||
logger.info(f"📢 检测到notice消息: message_id={message.message_id}, is_notify={message.is_notify}, notice_type={getattr(message, 'notice_type', None)}")
|
logger.info(f"📢 检测到notice消息: message_id={message.message_id}, is_notify={message.is_notify}, notice_type={getattr(message, 'notice_type', None)}")
|
||||||
await self._handle_notice_message(stream_id, message)
|
await self._handle_notice_message(stream_id, message)
|
||||||
return
|
|
||||||
|
# 根据配置决定是否继续处理(触发聊天流程)
|
||||||
|
if not global_config.notice.enable_notice_trigger_chat:
|
||||||
|
logger.info(f"根据配置,流 {stream_id} 的Notice消息将被忽略,不触发聊天流程。")
|
||||||
|
return # 停止处理,不进入未读消息队列
|
||||||
|
else:
|
||||||
|
logger.info(f"根据配置,流 {stream_id} 的Notice消息将触发聊天流程。")
|
||||||
|
# 继续执行,将消息添加到未读队列
|
||||||
|
|
||||||
# 普通消息处理
|
# 普通消息处理
|
||||||
chat_manager = get_chat_manager()
|
chat_manager = get_chat_manager()
|
||||||
@@ -748,6 +755,8 @@ class MessageManager:
|
|||||||
try:
|
try:
|
||||||
# 根据notice类型设置不同的TTL
|
# 根据notice类型设置不同的TTL
|
||||||
notice_type = self._get_notice_type(message)
|
notice_type = self._get_notice_type(message)
|
||||||
|
if notice_type is None:
|
||||||
|
return 3600
|
||||||
|
|
||||||
ttl_mapping = {
|
ttl_mapping = {
|
||||||
"poke": 1800, # 戳一戳30分钟
|
"poke": 1800, # 戳一戳30分钟
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class MessageReceiveConfig(ValidatedConfigBase):
|
|||||||
class NoticeConfig(ValidatedConfigBase):
|
class NoticeConfig(ValidatedConfigBase):
|
||||||
"""Notice消息配置类"""
|
"""Notice消息配置类"""
|
||||||
|
|
||||||
enable_notice_trigger_chat: bool = Field(default=False, description="是否允许notice消息触发聊天流程")
|
enable_notice_trigger_chat: bool = Field(default=True, description="是否允许notice消息触发聊天流程")
|
||||||
notice_in_prompt: bool = Field(default=True, description="是否在提示词中展示最近的notice消息")
|
notice_in_prompt: bool = Field(default=True, description="是否在提示词中展示最近的notice消息")
|
||||||
notice_prompt_limit: int = Field(default=5, ge=1, le=20, description="在提示词中展示的最大notice数量")
|
notice_prompt_limit: int = Field(default=5, ge=1, le=20, description="在提示词中展示的最大notice数量")
|
||||||
notice_time_window: int = Field(default=3600, ge=60, le=86400, description="notice时间窗口(秒)")
|
notice_time_window: int = Field(default=3600, ge=60, le=86400, description="notice时间窗口(秒)")
|
||||||
|
|||||||
@@ -66,10 +66,10 @@ class EmojiAction(BaseAction):
|
|||||||
# LLM判断提示词
|
# LLM判断提示词
|
||||||
llm_judge_prompt = """
|
llm_judge_prompt = """
|
||||||
判定是否需要使用表情动作的条件:
|
判定是否需要使用表情动作的条件:
|
||||||
1. 用户明确要求使用表情包
|
1. 用户明确要求使用表情包。
|
||||||
2. 这是一个适合表达情绪的场合
|
2. 当前的对话氛围很适合用表情来活跃气氛。
|
||||||
3. 发表情包能使当前对话更有趣
|
3. 发送表情包能让互动变得更有趣、更生动。
|
||||||
4. 不要发送太多表情包,如果你已经发送过多个表情包则回答"否"
|
4. 请像正常人一样自然地使用表情包,不要过度依赖,也不要刷屏哦。
|
||||||
|
|
||||||
请回答"是"或"否"。
|
请回答"是"或"否"。
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -139,14 +139,14 @@ class PokeAction(BaseAction):
|
|||||||
|
|
||||||
# === 基本信息(必须填写)===
|
# === 基本信息(必须填写)===
|
||||||
action_name = "poke_user"
|
action_name = "poke_user"
|
||||||
action_description = """可以让你戳其他用户:
|
action_description = """可以让你戳其他用户,为互动增添一份小小的乐趣。
|
||||||
1. **关键**: 这是一个高消耗的动作,请仅在绝对必要时使用,例如用户明确要求或作为提醒的关键部分。请极其谨慎地使用。
|
判定条件:
|
||||||
2. **用户请求**: 用户明确要求使用戳一戳。
|
1. **互动时机**: 这是一个有趣的互动方式,可以在想提醒某人,或者单纯想开个玩笑时使用。
|
||||||
4. **上下文需求**: 上下文明确需要你戳一个或多个人。
|
2. **用户请求**: 当用户明确要求使用戳一戳时。
|
||||||
5. **频率限制**: 如果最近已经戳过,或者用户情绪不高,请绝对不要使用。
|
3. **上下文需求**: 当上下文明确需要你戳一个或多个人时。
|
||||||
6. **核心原则**:
|
4. **频率与情绪**: 如果最近已经戳过,或者感觉对方情绪不高,请避免使用,不要打扰到别人哦。
|
||||||
|
|
||||||
请严格根据上述规则,回答“是”或“否"""
|
请根据上述规则,回答“是”或“否”。"""
|
||||||
activation_type = ActionActivationType.ALWAYS
|
activation_type = ActionActivationType.ALWAYS
|
||||||
parallel_action = True
|
parallel_action = True
|
||||||
|
|
||||||
@@ -159,13 +159,12 @@ class PokeAction(BaseAction):
|
|||||||
action_require = ["当需要戳某个用户时使用", "当你想提醒特定用户时使用"]
|
action_require = ["当需要戳某个用户时使用", "当你想提醒特定用户时使用"]
|
||||||
llm_judge_prompt = """
|
llm_judge_prompt = """
|
||||||
判定是否需要使用戳一戳动作的条件:
|
判定是否需要使用戳一戳动作的条件:
|
||||||
1. **关键**: 这是一个高消耗的动作,请仅在绝对必要时使用,例如用户明确要求或作为提醒的关键部分。请极其谨慎地使用。
|
1. **互动时机**: 这是一个有趣的互动方式,可以在想提醒某人,或者单纯想开个玩笑时使用。
|
||||||
2. **用户请求**: 用户明确要求使用戳一戳。
|
2. **用户请求**: 当用户明确要求使用戳一戳时。
|
||||||
4. **上下文需求**: 上下文明确需要你戳一个或多个人。
|
3. **上下文需求**: 当上下文明确需要你戳一个或多个人时。
|
||||||
5. **频率限制**: 如果最近已经戳过,或者用户情绪不高,请绝对不要使用。
|
4. **频率与情绪**: 如果最近已经戳过,或者感觉对方情绪不高,请避免使用,不要打扰到别人哦。
|
||||||
6. **核心原则**:
|
|
||||||
|
|
||||||
请严格根据上述规则,回答“是”或“否”。
|
请根据上述规则,回答“是”或“否”。
|
||||||
"""
|
"""
|
||||||
associated_types = ["text"]
|
associated_types = ["text"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user