临时调整权限模块,备份
This commit is contained in:
@@ -4,7 +4,7 @@ from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
from base.plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from base.plugin_common.plugin_interface import PluginStatus
|
||||
from utils.decorator.plugin_decorators import plugin_stats_decorator
|
||||
from utils.decorator.plugin_decorators import plugin_stats_decorator, plugin_points_cost
|
||||
from utils.revoke.message_auto_revoke import MessageAutoRevoke
|
||||
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
|
||||
from wechat_ipad import WechatAPIClient
|
||||
@@ -12,6 +12,10 @@ from wechat_ipad import WechatAPIClient
|
||||
|
||||
class RobotMenuPlugin(MessagePluginInterface):
|
||||
"""功能菜单插件"""
|
||||
|
||||
# 功能权限常量
|
||||
FEATURE_KEY = "ROBOT_MENU"
|
||||
FEATURE_DESCRIPTION = "📋 功能菜单 [菜单, 功能]"
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@@ -37,8 +41,18 @@ class RobotMenuPlugin(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__()
|
||||
# 注册功能权限
|
||||
self.feature = self.register_feature()
|
||||
|
||||
def initialize(self, context: Dict[str, Any]) -> bool:
|
||||
"""初始化插件"""
|
||||
@@ -133,17 +147,22 @@ class RobotMenuPlugin(MessagePluginInterface):
|
||||
return "当前没有启用机器人的群组"
|
||||
return "\n".join(group_list)
|
||||
|
||||
@plugin_stats_decorator(plugin_name="功能菜单")
|
||||
@plugin_stats_decorator(plugin_name="机器人菜单")
|
||||
@plugin_points_cost(1, "机器人菜单消耗积分", FEATURE_KEY)
|
||||
async def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
||||
"""处理消息"""
|
||||
content = str(message.get("content", "")).strip()
|
||||
self.LOG.debug(f"插件执行: {self.name}:{content}")
|
||||
command = content.split(" ")[0]
|
||||
sender = message.get("sender")
|
||||
roomid = message.get("roomid", "")
|
||||
gbm: GroupBotManager = message.get("gbm")
|
||||
bot: WechatAPIClient = message.get("bot")
|
||||
revoke: MessageAutoRevoke = message.get("revoke")
|
||||
|
||||
# 检查权限
|
||||
if roomid and gbm.get_group_permission(roomid, self.feature) == PermissionStatus.DISABLED:
|
||||
return False, "没有权限"
|
||||
|
||||
# 检查命令格式
|
||||
if len(content.split(" ")) == 1:
|
||||
# 显示功能菜单
|
||||
|
||||
Reference in New Issue
Block a user