2020-05-13 22:11:48 +00:00
|
|
|
|
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:
|
2020-07-18 01:11:28 +00:00
|
|
|
|
if len(args) == 0:
|
|
|
|
|
message = [
|
|
|
|
|
"ℹ️ Comandi disponibili:"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for command in sorted(list(set(self.serf.commands.values())), key=lambda c: c.name):
|
2020-08-20 01:20:53 +00:00
|
|
|
|
message.append(f"- [c]{self.serf.prefix}{command.name}[/c]")
|
2020-07-18 01:11:28 +00:00
|
|
|
|
|
|
|
|
|
await data.reply("\n".join(message))
|
|
|
|
|
else:
|
2020-08-20 01:20:53 +00:00
|
|
|
|
name: str = args[0].lstrip(self.serf.prefix)
|
2020-07-18 01:11:28 +00:00
|
|
|
|
|
|
|
|
|
try:
|
2020-08-20 01:20:53 +00:00
|
|
|
|
command: rc.Command = self.serf.commands[f"{self.serf.prefix}{name}"]
|
2020-07-18 01:11:28 +00:00
|
|
|
|
except KeyError:
|
|
|
|
|
raise rc.InvalidInputError("Il comando richiesto non esiste.")
|
|
|
|
|
|
|
|
|
|
message = [
|
2020-08-20 01:20:53 +00:00
|
|
|
|
f"ℹ️ [c]{self.serf.prefix}{command.name} {command.syntax}[/c]",
|
2020-07-18 01:11:28 +00:00
|
|
|
|
"",
|
|
|
|
|
f"{command.description}"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
await data.reply("\n".join(message))
|