临时调整权限模块,备份

This commit is contained in:
liuwei
2025-06-09 14:12:31 +08:00
parent cedab1cefd
commit 9d15bf965b
30 changed files with 882 additions and 138 deletions

View File

@@ -29,6 +29,10 @@ VIDEO_EXTENSIONS = {'.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm'}
class DifyPlugin(MessagePluginInterface):
"""Dify AI聊天插件"""
# 功能权限常量
FEATURE_KEY = "AI_CAPABILITY"
FEATURE_DESCRIPTION = "🤖 AI聊天功能 [ai, dify, 聊天, AI]"
@property
def name(self) -> str:
return "Dify聊天"
@@ -53,6 +57,14 @@ class DifyPlugin(MessagePluginInterface):
def commands(self) -> List[str]:
return self._commands
@property
def feature_key(self) -> Optional[str]:
return self.FEATURE_KEY
@property
def feature_description(self) -> Optional[str]:
return self.FEATURE_DESCRIPTION
def __init__(self):
super().__init__()
# 会话上下文管理,格式: {group_id/wxid: [conversation_history]}
@@ -64,6 +76,8 @@ class DifyPlugin(MessagePluginInterface):
# 会话过期时间(秒)
self.conversation_timeout = 3600 # 1小时
self.last_activity: Dict[str, float] = {}
# 注册功能权限
self.feature = self.register_feature()
def initialize(self, context: Dict[str, Any]) -> bool:
"""初始化插件"""
@@ -120,7 +134,7 @@ class DifyPlugin(MessagePluginInterface):
return False
@plugin_stats_decorator(plugin_name="Dify聊天")
@plugin_points_cost(2, "AI聊天消耗积分", Feature.AI_CAPABILITY)
@plugin_points_cost(2, "AI聊天消耗积分", FEATURE_KEY)
async def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
"""处理消息"""
content = str(message.get("content", "")).strip()
@@ -135,7 +149,7 @@ class DifyPlugin(MessagePluginInterface):
target = roomid if roomid else sender
# 检查权限
if roomid and gbm.get_group_permission(target, Feature.AI_CAPABILITY) == PermissionStatus.DISABLED:
if roomid and gbm.get_group_permission(target, self.feature) == PermissionStatus.DISABLED:
return False, "没有权限"
# 处理被@的消息
@@ -184,8 +198,8 @@ class DifyPlugin(MessagePluginInterface):
revoke.add_message_to_revoke(target, client_msg_id, create_time, new_msg_id, 5)
return False, f"处理出错: {e}"
async def _send_response(self, bot: WechatAPIClient, target: str, sender: str,
response: str, roomid: str) -> Tuple[bool, str]:
async def _send_response(self, bot: WechatAPIClient, target: str, sender: str,
response: str, roomid: str) -> Tuple[bool, str]:
"""发送响应消息的辅助方法"""
try:
# 判断是否为本地文件路径