From 4d434dcb5732a363d10c87e2439a9279946f9a98 Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 9 Apr 2025 14:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=9D=83=E9=99=90=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/beautyleg/main.py | 5 +++-- plugins/dify/main.py | 2 +- plugins/game_task/main.py | 2 +- plugins/message_sign/main.py | 2 +- plugins/message_summary/main.py | 2 +- plugins/music/main.py | 2 +- plugins/video/main.py | 2 +- plugins/video_man/main.py | 2 +- plugins/xiuren_image/main.py | 2 +- utils/decorator/points_decorator.py | 20 ++++++++++++++++---- 10 files changed, 27 insertions(+), 14 deletions(-) diff --git a/plugins/beautyleg/main.py b/plugins/beautyleg/main.py index 0e82a84..4f35f3b 100644 --- a/plugins/beautyleg/main.py +++ b/plugins/beautyleg/main.py @@ -42,8 +42,9 @@ class BeautyLegPlugin(MessagePluginInterface): def __init__(self): super().__init__() + # 修改图片目录路径指向 resource/beauty_leg self.image_folder = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), - "beautyleg", "download_dir") + "resource", "beauty_leg") def initialize(self, context: Dict[str, Any]) -> bool: """初始化插件""" @@ -91,7 +92,7 @@ class BeautyLegPlugin(MessagePluginInterface): return command in self._commands @plugin_stats_decorator(plugin_name="美腿图片") - @plugin_points_cost(1, "美腿图片消耗积分") + @plugin_points_cost(1, "美腿图片消耗积分", Feature.BEAUTY_LEG) def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理消息""" content = str(message.get("content", "")).strip() diff --git a/plugins/dify/main.py b/plugins/dify/main.py index e72626e..73fd4ed 100644 --- a/plugins/dify/main.py +++ b/plugins/dify/main.py @@ -104,7 +104,7 @@ class DifyPlugin(MessagePluginInterface): return command in self._commands @plugin_stats_decorator(plugin_name="Dify聊天") - @plugin_points_cost(2, "AI聊天消耗积分") + @plugin_points_cost(2, "AI聊天消耗积分",Feature.AI_CAPABILITY) def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理消息""" content = str(message.get("content", "")).strip() diff --git a/plugins/game_task/main.py b/plugins/game_task/main.py index 787e7be..e7b42c2 100644 --- a/plugins/game_task/main.py +++ b/plugins/game_task/main.py @@ -249,7 +249,7 @@ class GameTaskPlugin(MessagePluginInterface): sender ) - @points_reward_decorator(calculate_game_points, "game", "百科答题奖励") + @points_reward_decorator(calculate_game_points, "game", "百科答题奖励", Feature.TASK_GAME) def _handle_submit_answer(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理提交答案请求""" try: diff --git a/plugins/message_sign/main.py b/plugins/message_sign/main.py index 438bf73..ee41dda 100644 --- a/plugins/message_sign/main.py +++ b/plugins/message_sign/main.py @@ -180,7 +180,7 @@ class MessageSignPlugin(MessagePluginInterface): # 修改process_message方法,使用装饰器 @plugin_stats_decorator(plugin_name="签到系统") - @points_reward_decorator(calculate_sign_in_points, "checkin", "每日签到奖励") + @points_reward_decorator(calculate_sign_in_points, "checkin", "每日签到奖励",Feature.SIGNIN) def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理消息""" content = str(message.get("content", "")).strip() diff --git a/plugins/message_summary/main.py b/plugins/message_summary/main.py index f607b6e..35bffbd 100644 --- a/plugins/message_summary/main.py +++ b/plugins/message_summary/main.py @@ -74,7 +74,7 @@ class MessageSummaryPlugin(MessagePluginInterface): return True @plugin_stats_decorator(plugin_name="群聊总结") - @plugin_points_cost(10, "群聊总结消耗积分") + @plugin_points_cost(10, "群聊总结消耗积分",Feature.SUMMARY_CAPABILITY) def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理消息""" try: diff --git a/plugins/music/main.py b/plugins/music/main.py index 6cd2863..cd74e0f 100644 --- a/plugins/music/main.py +++ b/plugins/music/main.py @@ -82,7 +82,7 @@ class MusicPlugin(MessagePluginInterface): return command in self._commands @plugin_stats_decorator(plugin_name="音乐点播") - @plugin_points_cost(1, "音乐点播消耗积分") + @plugin_points_cost(1, "音乐点播消耗积分", Feature.MUSIC) def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理消息""" content = str(message.get("content", "")).strip() diff --git a/plugins/video/main.py b/plugins/video/main.py index cc14aa5..59b6b5c 100644 --- a/plugins/video/main.py +++ b/plugins/video/main.py @@ -89,7 +89,7 @@ class VideoPlugin(MessagePluginInterface): return command in self._commands @plugin_stats_decorator(plugin_name="视频插件") - @plugin_points_cost(1, "视频插件消耗积分") + @plugin_points_cost(1, "视频插件消耗积分", Feature.VIDEO) def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理消息""" content = str(message.get("content", "")).strip() diff --git a/plugins/video_man/main.py b/plugins/video_man/main.py index 683bbd1..de603ba 100644 --- a/plugins/video_man/main.py +++ b/plugins/video_man/main.py @@ -90,7 +90,7 @@ class VideoManPlugin(MessagePluginInterface): return command in self._commands @plugin_stats_decorator(plugin_name="猛男视频") - @plugin_points_cost(1, "猛男视频消耗积分") + @plugin_points_cost(1, "猛男视频消耗积分", Feature.VIDEO_MAN) def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理消息""" content = str(message.get("content", "")).strip() diff --git a/plugins/xiuren_image/main.py b/plugins/xiuren_image/main.py index bf699d1..7a94fbf 100644 --- a/plugins/xiuren_image/main.py +++ b/plugins/xiuren_image/main.py @@ -88,7 +88,7 @@ class XiurenImagePlugin(MessagePluginInterface): return command in self._commands @plugin_stats_decorator(plugin_name="秀人图片") - @plugin_points_cost(1, "秀人图片消耗积分") + @plugin_points_cost(1, "秀人图片消耗积分", Feature.PIC) def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]: """处理消息""" content = str(message.get("content", "")).strip() diff --git a/utils/decorator/points_decorator.py b/utils/decorator/points_decorator.py index 530574d..dc0f606 100644 --- a/utils/decorator/points_decorator.py +++ b/utils/decorator/points_decorator.py @@ -10,13 +10,14 @@ from db.points_db import PointsDBOperator, PointSource def points_reward_decorator(points_calculator: Union[int, Callable], source_type: str = "other", - description: str = None): + description: str = None, feature: Feature = None): """积分奖励装饰器 Args: points_calculator: 积分数量或计算函数,如果是函数,接收(self, message, success, response)参数并返回积分数量 source_type: 积分来源类型 (checkin, game, other) description: 积分奖励描述 + feature: 功能权限枚举 Returns: 装饰器函数 @@ -25,6 +26,12 @@ def points_reward_decorator(points_calculator: Union[int, Callable], source_type def decorator(func: Callable) -> Callable: @functools.wraps(func) def wrapper(self, message: Dict[str, Any]) -> Tuple[bool, str]: + # 检查权限 + roomid = message.get("roomid", "") + if feature and roomid and hasattr(self, 'gbm'): + if self.gbm.get_group_permission(roomid, feature) == PermissionStatus.DISABLED: + return False, "没有权限" + # 调用原始方法 success, response = func(self, message) @@ -85,16 +92,16 @@ def points_reward_decorator(points_calculator: Union[int, Callable], source_type return success, response return wrapper - return decorator -def plugin_points_cost(points: int, description: str = None): +def plugin_points_cost(points: int, description: str = None, feature: Feature = None): """插件积分消费装饰器 Args: points: 消费积分数量 description: 积分消费描述 + feature: 功能权限枚举 Returns: 装饰器函数 @@ -104,6 +111,12 @@ def plugin_points_cost(points: int, description: str = None): @functools.wraps(func) def wrapper(self, message: Dict[str, Any]) -> Tuple[bool, str]: try: + # 检查权限 + roomid = message.get("roomid", "") + if feature and roomid and hasattr(self, 'gbm'): + if self.gbm.get_group_permission(roomid, feature) == PermissionStatus.DISABLED: + return False, "没有权限" + # 获取消息信息 sender = message.get("sender", "") roomid = message.get("roomid", "") @@ -160,5 +173,4 @@ def plugin_points_cost(points: int, description: str = None): return func(self, message) return wrapper - return decorator