Files
Mofox-Core/plugins/permission_example/plugin.py
minecraft1024a 1e037e5ce9 feat(maizone): 新增QQ空间互通组功能,根据聊天上下文生成说说
引入了全新的“QQ空间互通组”功能。用户可以配置多个群聊为一个互通组。
在通过指令发布说说时,系统会自动获取这些群聊的近期聊天记录作为上下文,从而生成与当前讨论话题更相关的说说内容。

- 在 `config.toml` 中新增了 `[maizone_intercom]` 配置项用于定义互通组。
- 重构并增强了动态(说说)的拉取逻辑,提高了对不同数据格式的兼容性和解析的稳定性。
- 对项目中的多个文件进行了代码清理,移除了未使用的导入,使代码更加整洁。
2025-08-26 20:20:54 +08:00

107 lines
3.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
权限系统示例插件
演示如何在插件中使用权限系统,包括权限节点注册、权限检查等功能。
"""
from typing import List
from src.plugin_system.apis.plugin_register_api import register_plugin
from src.plugin_system.base.base_plugin import BasePlugin
from src.plugin_system.base.base_command import BaseCommand
from src.plugin_system.apis.logging_api import get_logger
from src.plugin_system.base.config_types import ConfigField
from src.plugin_system.utils.permission_decorators import require_permission, require_master
from src.common.message import ChatStream, Message
logger = get_logger(__name__)
class ExampleAdminCommand(BaseCommand):
"""需要管理员权限的示例命令"""
command_name = "admin_example"
command_description = "管理员权限示例命令"
command_pattern = r"^/admin_example$"
command_help = "管理员权限示例命令"
command_examples = ["/admin_example"]
intercept_message = True
def can_execute(self, message: Message, chat_stream: ChatStream) -> bool:
"""基本检查"""
return True
@require_permission("plugin.example.admin")
async def execute(self, message: Message, chat_stream: ChatStream, args: List[str]) -> None:
"""执行管理员命令"""
await self.send_text("✅ 你有管理员权限!这是一个管理员专用功能。")
return True, "执行成功", True
class ExampleUserCommand(BaseCommand):
"""普通用户权限的示例命令"""
command_name = "user_example"
command_description = "用户权限示例命令"
command_pattern = r"^/user_example$"
command_help = "用户权限示例命令"
command_examples = ["/user_example"]
intercept_message = True
def can_execute(self, message: Message, chat_stream: ChatStream) -> bool:
"""基本检查"""
return True
@require_permission("plugin.example.user")
async def execute(self, message: Message, chat_stream: ChatStream, args: List[str]) -> None:
"""执行用户命令"""
await self.send_text("✅ 你有用户权限!这是一个普通用户功能。")
class ExampleMasterCommand(BaseCommand):
"""Master专用的示例命令"""
command_name = "master_example"
command_description = "Master专用示例命令"
command_pattern = r"^/master_example$"
command_help = "Master专用示例命令"
command_examples = ["/master_example"]
intercept_message = True
def can_execute(self, message: Message, chat_stream: ChatStream) -> bool:
"""基本检查"""
return True
@require_master()
async def execute(self, message: Message, chat_stream: ChatStream, args: List[str]) -> None:
"""执行Master命令"""
await self.send_text("👑 你是Master用户这是Master专用功能。")
@register_plugin
class HelloWorldPlugin(BasePlugin):
"""权限系统示例插件"""
# 插件基本信息
plugin_name: str = "permission_example" # 内部标识符
enable_plugin: bool = True
dependencies: List[str] = [] # 插件依赖列表
python_dependencies: List[str] = [] # Python包依赖列表
config_file_name: str = "config.toml" # 配置文件名
# 配置Schema定义
config_schema: dict = {
"plugin": {
"name": ConfigField(type=str, default="permission_example", description="插件名称"),
"version": ConfigField(type=str, default="1.0.0", description="插件版本"),
"enabled": ConfigField(type=bool, default=False, description="是否启用插件"),
}
}
def get_plugin_components(self):
return [(ExampleAdminCommand.get_command_info,ExampleAdminCommand),
(ExampleUserCommand.get_command_info,ExampleUserCommand),
(ExampleMasterCommand.get_command_info,ExampleMasterCommand)
]