feat: 持久记忆和代码优化、函数工具筛选

This commit is contained in:
2025-12-10 17:21:43 +08:00
parent 7d3ef70093
commit e0a38eb6f2
87 changed files with 2179 additions and 241 deletions

View File

@@ -22,7 +22,7 @@ class Repeater(PluginBase):
def __init__(self):
super().__init__()
self.config = None
self.group_messages: Dict[str, Dict] = {} # {group_id: {"content": str, "count": int}}
self.group_messages: Dict[str, Dict] = {} # {group_id: {"content": str, "count": int, "repeated": bool}}
async def async_init(self):
"""异步初始化"""
@@ -70,23 +70,27 @@ class Repeater(PluginBase):
# 获取该群的消息记录
if from_wxid not in self.group_messages:
self.group_messages[from_wxid] = {"content": content, "count": 1}
self.group_messages[from_wxid] = {"content": content, "count": 1, "repeated": False}
return True
group_data = self.group_messages[from_wxid]
# 如果消息相同,计数+1
if group_data["content"] == content:
# 如果已经复读过这条消息,忽略后续相同消息
if group_data["repeated"]:
return True
group_data["count"] += 1
# 达到触发次数,复读
if group_data["count"] == repeat_count:
if group_data["count"] >= repeat_count:
await bot.send_text(from_wxid, content)
logger.info(f"复读消息: {from_wxid} - {content[:20]}...")
# 重置计数,避免重复复读
group_data["count"] = 0
# 标记已复读,避免重复复读
group_data["repeated"] = True
else:
# 消息不同,重置记录
self.group_messages[from_wxid] = {"content": content, "count": 1}
self.group_messages[from_wxid] = {"content": content, "count": 1, "repeated": False}
return True