1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00
royalnet/royalpack/commands/help.py

52 lines
1.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import royalnet.engineer as engi
@engi.PartialCommand.new(syntax=r"")
async def help_cmd(*, _sentry: engi.Sentry, _imp: engi.PDAImplementation, _msg: engi.Message, **__):
if not isinstance(_imp, engi.ConversationListImplementation):
await _msg.reply(text="⚠️ Questa implementazione gestisce i comandi con un metodo sconosciuto.")
commands = [command for command in _imp.conversations if isinstance(command, engi.FullCommand)]
names = set([command.name() for command in commands])
text = [" Comandi disponibili:"]
for name in names:
text.append(f"- {name}")
text = "\n".join(text)
await _msg.reply(text=text)
@engi.PartialCommand.new(syntax=r"(?P<cmd>\S+)")
async def help_single(*, _sentry: engi.Sentry, _imp: engi.PDAImplementation, _msg: engi.Message, cmd: str, **__):
if not isinstance(_imp, engi.ConversationListImplementation):
await _msg.reply(text="⚠️ Questa implementazione gestisce i comandi con un metodo sconosciuto.")
commands = [
command
for command in _imp.conversations
if isinstance(command, engi.FullCommand)
and cmd in command.names
]
text = [f" Sottocomandi di {cmd} disponibili:"]
for command in commands:
text.append("")
text.append("")
text.append(f"{command}")
text.append(f" {command.pattern.pattern}")
text.append("")
if ht := command.help():
text.append(ht.strip())
else:
text.append("Questo comando non ha un help text.")
text = "\n".join(text)
await _msg.reply(text=text)
__all__ = (
"help_cmd",
"help_single",
)