1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/royalpack/commands/help.py

37 lines
1.1 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.

from typing import *
import royalnet
import royalnet.commands as rc
class HelpCommand(rc.Command):
name: str = "help"
description: str = "Visualizza informazioni su un comando."
syntax: str = "{comando}"
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
if len(args) == 0:
message = [
" Comandi disponibili:"
]
for command in sorted(list(set(self.serf.commands.values())), key=lambda c: c.name):
message.append(f"- [c]{self.interface.prefix}{command.name}[/c]")
await data.reply("\n".join(message))
else:
name: str = args[0].lstrip(self.interface.prefix)
try:
command: rc.Command = self.serf.commands[f"{self.interface.prefix}{name}"]
except KeyError:
raise rc.InvalidInputError("Il comando richiesto non esiste.")
message = [
f" [c]{self.interface.prefix}{command.name} {command.syntax}[/c]",
"",
f"{command.description}"
]
await data.reply("\n".join(message))