46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""Generated reviewed adapter for person-directory."""
|
||
|
||
from jwebot_sdk import Event, ExtensionResult, ReplyPlan, SingleGroupContext
|
||
|
||
|
||
PROFILE = 'person-directory'
|
||
AUTHOR = 'official'
|
||
DESCRIPTION = '查询当前群已配置人物、基本属性和别名'
|
||
HELP_ENTRIES = ('/人物列表 [页码] /people;/人物 [名称或别名] /person',)
|
||
COMMANDS = ('/人物列表', '/别名列表', '/people', '/人物', '/个人属性', '/person')
|
||
|
||
|
||
def _handler(context: SingleGroupContext, command: str):
|
||
def handle(event: Event, arguments: str) -> ExtensionResult:
|
||
response = context.services.call(
|
||
PROFILE,
|
||
operation="execute",
|
||
payload={
|
||
"command": command,
|
||
"arguments": arguments,
|
||
"event": event.to_mapping(),
|
||
},
|
||
)
|
||
texts = response.get("texts")
|
||
if isinstance(texts, list) and texts and all(
|
||
isinstance(item, str) and item.strip() for item in texts
|
||
):
|
||
return ExtensionResult(
|
||
reply=ReplyPlan.multi_text(texts),
|
||
metadata={"local_extension": PROFILE, "author": AUTHOR},
|
||
)
|
||
text = response.get("text")
|
||
if not isinstance(text, str) or not text.strip():
|
||
raise ValueError("local service returned invalid text")
|
||
return ExtensionResult(
|
||
reply=ReplyPlan.text(text),
|
||
metadata={"local_extension": PROFILE, "author": AUTHOR},
|
||
)
|
||
|
||
return handle
|
||
|
||
|
||
def plugin(context: SingleGroupContext) -> None:
|
||
for command in COMMANDS:
|
||
context.commands.register(command, _handler(context, command))
|