ForcePilot/backend/package/yuxi/channel/extensions/xmpp/commands.py

44 lines
1.4 KiB
Python
Raw Normal View History

import logging
logger = logging.getLogger("yuxi.channel.xmpp.commands")
def register_xmpp_commands(bot, account):
if "xep_0050" not in bot.plugin:
return
commands = bot.plugin["xep_0050"]
async def handle_help(iq, session):
form = bot.plugin["xep_0004"].make_form(ftype="result")
form.add_field(
var="info",
ftype="text-single",
label="Bot Info",
value=f"ForcePilot XMPP Bot ({account.bare_jid})",
)
form.add_field(
var="rooms",
ftype="text-multi",
label="Active Rooms",
value="\n".join(account.rooms) or "(none)",
)
session["notes"] = [("info", "ForcePilot Bot — /help /status 可用")]
return session
async def handle_status(iq, session):
form = bot.plugin["xep_0004"].make_form(ftype="result")
form.add_field(var="connected", ftype="boolean", label="Connected", value=True)
form.add_field(
var="jid",
ftype="text-single",
label="JID",
value=str(bot.boundjid),
)
session["notes"] = [("info", "Bot 运行正常")]
return session
commands.add_command(node="help", name="Help", handler=handle_help)
commands.add_command(node="status", name="Status", handler=handle_status)
logger.info("XMPP Ad-Hoc commands registered: help, status")