打通自动回复与表情语义库联动\n\n- 新增表情语义解析与表情资产查询模块,支持从历史表情中提取可读中文语义\n- 为 ai_auto_response 增加短回复表情匹配器,命中语义时优先发送表情并支持失败回退文本\n- 调整自动回复提示词与配置项,强化短情绪回复场景的表情替换能力
This commit is contained in:
45
db/emoji_asset_db.py
Normal file
45
db/emoji_asset_db.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from db.base import BaseDBOperator
|
||||
from db.connection import DBConnectionManager
|
||||
|
||||
|
||||
class EmojiAssetDB(BaseDBOperator):
|
||||
"""表情资产查询。
|
||||
|
||||
说明:
|
||||
1. 这里单独抽出查询类,避免自动回复插件为了拿表情库再去依赖后台蓝图;
|
||||
2. 查询只关心消息表里的原始表情记录,不负责语义解析和匹配打分;
|
||||
3. 后续无论后台页面、自动回复还是其他插件,都可以复用同一份表情资产数据源。
|
||||
"""
|
||||
|
||||
def __init__(self, db_manager: DBConnectionManager):
|
||||
super().__init__(db_manager)
|
||||
|
||||
def get_recent_emoji_assets(self, limit: int = 500) -> List[Dict]:
|
||||
"""获取近期表情消息记录。"""
|
||||
sql = """
|
||||
SELECT message_id, group_id, sender, timestamp, message_type, attachment_url, image_path
|
||||
FROM messages
|
||||
WHERE message_type IN ('47', '1048625', '1090519089')
|
||||
AND attachment_url IS NOT NULL
|
||||
AND attachment_url <> ''
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT %s
|
||||
"""
|
||||
return self.execute_query(sql, (limit,)) or []
|
||||
|
||||
def get_emoji_asset_by_md5(self, md5: str) -> Optional[Dict]:
|
||||
"""根据 md5 获取最近一条表情记录。"""
|
||||
sql = """
|
||||
SELECT message_id, group_id, sender, timestamp, message_type, attachment_url, image_path
|
||||
FROM messages
|
||||
WHERE message_type IN ('47', '1048625', '1090519089')
|
||||
AND attachment_url IS NOT NULL
|
||||
AND attachment_url <> ''
|
||||
AND attachment_url LIKE %s
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 1
|
||||
"""
|
||||
return self.execute_query(sql, (f'%md5="{md5}"%',), fetch_one=True)
|
||||
Reference in New Issue
Block a user