Skip to content

Commit f6eb33c

Browse files
committed
refactor(command-management): inline platform command refresh
1 parent 60880dc commit f6eb33c

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

astrbot/dashboard/services/command_service.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,20 @@ async def toggle_command(self, handler_full_name: str | None, enabled) -> dict:
5454
except ValueError as exc:
5555
raise CommandServiceError(str(exc)) from exc
5656

57-
await self._refresh_platform_commands()
57+
if self.core_lifecycle:
58+
platform_manager = getattr(self.core_lifecycle, "platform_manager", None)
59+
if platform_manager:
60+
for platform in list(platform_manager.get_insts()):
61+
try:
62+
await platform.refresh_registered_commands()
63+
except Exception as exc:
64+
logger.warning(
65+
"Failed to refresh registered commands for platform %s: %s",
66+
type(platform).__name__,
67+
exc,
68+
exc_info=True,
69+
)
70+
5871
return await self._get_command_payload(handler_full_name)
5972

6073
async def rename_command(
@@ -71,7 +84,20 @@ async def rename_command(
7184
except ValueError as exc:
7285
raise CommandServiceError(str(exc)) from exc
7386

74-
await self._refresh_platform_commands()
87+
if self.core_lifecycle:
88+
platform_manager = getattr(self.core_lifecycle, "platform_manager", None)
89+
if platform_manager:
90+
for platform in list(platform_manager.get_insts()):
91+
try:
92+
await platform.refresh_registered_commands()
93+
except Exception as exc:
94+
logger.warning(
95+
"Failed to refresh registered commands for platform %s: %s",
96+
type(platform).__name__,
97+
exc,
98+
exc_info=True,
99+
)
100+
75101
return await self._get_command_payload(handler_full_name)
76102

77103
async def update_permission(
@@ -89,25 +115,6 @@ async def update_permission(
89115

90116
return await self._get_command_payload(handler_full_name)
91117

92-
async def _refresh_platform_commands(self) -> None:
93-
if not self.core_lifecycle:
94-
return
95-
96-
platform_manager = getattr(self.core_lifecycle, "platform_manager", None)
97-
if not platform_manager:
98-
return
99-
100-
for platform in list(platform_manager.get_insts()):
101-
try:
102-
await platform.refresh_registered_commands()
103-
except Exception as exc:
104-
logger.warning(
105-
"Failed to refresh registered commands for platform %s: %s",
106-
type(platform).__name__,
107-
exc,
108-
exc_info=True,
109-
)
110-
111118
def _get_wake_prefix(self, config_id: str) -> list:
112119
wake_prefix = self.config.get("wake_prefix", ["/"])
113120
config_id = config_id.strip()

0 commit comments

Comments
 (0)