mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-18 18:10:37 +08:00
feat: Enhance handler and capability dispatchers with improved error handling
- Updated HandlerDispatcher to raise TypeError for uninjectable required parameters, logging errors appropriately. - Refactored CapabilityDispatcher to raise TypeError for missing required parameters during capability execution. - Renamed _load_plugin_config to load_plugin_config for clarity and consistency. - Introduced _sync_plugin_registry method in SupervisorRuntime to manage plugin capabilities more effectively. - Enhanced capability registration logic to handle naming conflicts with better logging and automatic renaming. - Added tests for handler and capability dispatchers to ensure proper error handling and functionality. - Implemented new HTTP and metadata capabilities with corresponding tests for registration and retrieval. - Improved MemoryClient methods with additional tests for save_with_ttl, get_many, delete_many, and stats. - Added tests for the testing module to ensure proper import and functionality of PluginHarness.
This commit is contained in:
@@ -155,13 +155,21 @@ class HelloPlugin(Star):
|
||||
|
||||
# Batch operations
|
||||
values = await ctx.db.get_many(["demo:key1", "demo:key2"])
|
||||
await ctx.db.set_many({
|
||||
"demo:batch1": {"batch": True},
|
||||
"demo:batch2": {"batch": True},
|
||||
})
|
||||
await ctx.db.set_many(
|
||||
{
|
||||
"demo:batch1": {"batch": True},
|
||||
"demo:batch2": {"batch": True},
|
||||
}
|
||||
)
|
||||
|
||||
# Cleanup
|
||||
for key in ["demo:key1", "demo:key2", "demo:key3", "demo:batch1", "demo:batch2"]:
|
||||
for key in [
|
||||
"demo:key1",
|
||||
"demo:key2",
|
||||
"demo:key3",
|
||||
"demo:batch1",
|
||||
"demo:batch2",
|
||||
]:
|
||||
await ctx.db.delete(key)
|
||||
|
||||
return event.plain_result(
|
||||
@@ -177,9 +185,7 @@ class HelloPlugin(Star):
|
||||
count = 0
|
||||
async for change in ctx.db.watch("demo:"):
|
||||
count += 1
|
||||
await event.reply(
|
||||
f"变更: {change['op']} {change['key']}"
|
||||
)
|
||||
await event.reply(f"变更: {change['op']} {change['key']}")
|
||||
if count >= 3:
|
||||
break
|
||||
|
||||
@@ -310,10 +316,7 @@ class HelloPlugin(Star):
|
||||
async def on_group_join(self, event: MessageEvent, ctx: Context) -> None:
|
||||
"""Handle group join events."""
|
||||
ctx.logger.info("用户加入群组: {}", event.user_id)
|
||||
await ctx.platform.send(
|
||||
event.session_id,
|
||||
f"欢迎 {event.user_id} 加入群组!"
|
||||
)
|
||||
await ctx.platform.send(event.session_id, f"欢迎 {event.user_id} 加入群组!")
|
||||
|
||||
@on_event("group_leave")
|
||||
async def on_group_leave(self, event: MessageEvent, ctx: Context) -> None:
|
||||
|
||||
Reference in New Issue
Block a user