This commit is contained in:
tt-P607
2025-11-13 16:28:51 +08:00
4 changed files with 49 additions and 20 deletions

View File

@@ -241,6 +241,13 @@ class ChatterActionManager:
"command": command,
}
else:
# 检查目标消息是否为表情包消息以及配置是否允许回复表情包
if target_message and getattr(target_message, 'is_emoji', False):
# 如果是表情包消息且配置不允许回复表情包,则跳过回复
if not getattr(global_config.chat, 'allow_reply_to_emoji', True):
logger.info(f"{log_prefix} 目标消息为表情包且配置不允许回复表情包,跳过回复")
return {"action_type": action_name, "success": True, "reply_text": "", "skip_reason": "emoji_not_allowed"}
# 生成回复 (reply 或 respond)
# reply: 针对单条消息的回复,使用 s4u 模板
# respond: 对未读消息的统一回应,使用 normal 模板

View File

@@ -152,6 +152,8 @@ class ChatConfig(ValidatedConfigBase):
multiple_replies_strategy: Literal["keep_first", "keep_best", "keep_last"] = Field(
default="keep_first", description="多重回复处理策略keep_first(保留第一个)keep_best(保留最佳)keep_last(保留最后一个)"
)
# 表情包回复配置
allow_reply_to_emoji: bool = Field(default=True, description="是否允许回复表情包消息")
class MessageReceiveConfig(ValidatedConfigBase):

View File

@@ -47,16 +47,23 @@ def get_mood(chat_id: str) -> str:
return chat_mood.mood_state
def set_mood(chat_id: str, new_mood: str):
def set_mood(chat_id: str, new_mood: str) -> bool:
"""强制设定指定聊天的新情绪状态
Args:
chat_id (str): 聊天ID
new_mood (str): 新的情绪状态
Returns:
bool: 操作是否成功
"""
try:
chat_mood = mood_manager.get_mood_by_chat_id(chat_id)
chat_mood.mood_state = new_mood
logger.info(f"[{chat_id}] 情绪状态被强制设置为: {new_mood}")
return True
except Exception as e:
logger.error(f"强制设定指定聊天的新情绪状态时发生错误:{e}")
return False
async def lock_mood(chat_id: str, duration: float | None = None):
@@ -66,7 +73,10 @@ async def lock_mood(chat_id: str, duration: float | None = None):
Args:
chat_id (str): 聊天ID
duration (Optional[float]): 锁定时长(秒)。如果为 None则永久锁定直到手动解锁。
Returns:
bool: 操作是否成功
"""
try:
if chat_id in _unlock_tasks:
_unlock_tasks[chat_id].cancel()
del _unlock_tasks[chat_id]
@@ -82,14 +92,20 @@ async def lock_mood(chat_id: str, duration: float | None = None):
if chat_id in mood_manager.insomnia_chats:
await unlock_mood(chat_id)
logger.info(f"[{chat_id}] 情绪已自动解锁。")
task = asyncio.create_task(_unlock_after())
_unlock_tasks[chat_id] = task
return True
except Exception as e:
logger.error(f"锁定指定聊天的情绪时发生错误:{e}")
return False
async def unlock_mood(chat_id: str):
async def unlock_mood(chat_id: str) -> bool:
"""
立即解除情绪锁定。
Returns:
bool: 如果成功解锁则返回 True如果情绪未被锁定则返回 False。
"""
if chat_id in _unlock_tasks:
_unlock_tasks[chat_id].cancel()
@@ -98,6 +114,8 @@ async def unlock_mood(chat_id: str):
if chat_id in mood_manager.insomnia_chats:
mood_manager.insomnia_chats.remove(chat_id)
logger.info(f"[{chat_id}] 情绪已手动解锁。")
return True
return False
def is_mood_locked(chat_id: str) -> bool:

View File

@@ -165,6 +165,8 @@ decision_history_length = 3 # 决策历史记录的长度,用于增强语言
enable_multiple_replies = false # 是否允许多重回复True=允许多个回复动作False=只保留一个回复动作)
multiple_replies_strategy = "keep_first" # 多重回复处理策略keep_first(保留第一个)keep_best(保留最佳)keep_last(保留最后一个)
# 表情包回复配置
allow_reply_to_emoji = false # 是否允许回复表情包消息
[message_receive]
# 以下是消息过滤,可以根据规则过滤特定消息,将不会读取这些消息