|
12 | 12 |
|
13 | 13 | from ..computer_client import get_booter |
14 | 14 |
|
| 15 | + |
| 16 | +def _check_admin_permission(context: ContextWrapper[AstrAgentContext]) -> str | None: |
| 17 | + cfg = context.context.context.get_config( |
| 18 | + umo=context.context.event.unified_msg_origin |
| 19 | + ) |
| 20 | + provider_settings = cfg.get("provider_settings", {}) |
| 21 | + require_admin = provider_settings.get("computer_use_require_admin", True) |
| 22 | + if require_admin and context.context.event.role != "admin": |
| 23 | + return ( |
| 24 | + "error: Permission denied. File upload/download is only allowed for admin users. " |
| 25 | + "Tell user to set admins in `AstrBot WebUI -> Config -> General Config` by adding their user ID to the admins list if they need this feature." |
| 26 | + f"User's ID is: {context.context.event.get_sender_id()}. User's ID can be found by using /sid command." |
| 27 | + ) |
| 28 | + return None |
| 29 | + |
| 30 | + |
15 | 31 | # @dataclass |
16 | 32 | # class CreateFileTool(FunctionTool): |
17 | 33 | # name: str = "astrbot_create_file" |
@@ -102,6 +118,8 @@ async def call( |
102 | 118 | context: ContextWrapper[AstrAgentContext], |
103 | 119 | local_path: str, |
104 | 120 | ) -> str | None: |
| 121 | + if permission_error := _check_admin_permission(context): |
| 122 | + return permission_error |
105 | 123 | sb = await get_booter( |
106 | 124 | context.context.context, |
107 | 125 | context.context.event.unified_msg_origin, |
@@ -161,6 +179,8 @@ async def call( |
161 | 179 | remote_path: str, |
162 | 180 | also_send_to_user: bool = True, |
163 | 181 | ) -> ToolExecResult: |
| 182 | + if permission_error := _check_admin_permission(context): |
| 183 | + return permission_error |
164 | 184 | sb = await get_booter( |
165 | 185 | context.context.context, |
166 | 186 | context.context.event.unified_msg_origin, |
|
0 commit comments