From caee06f877890d77c5085fc78479133d7f119ec1 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 18 Apr 2021 17:47:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20#1=20Add=20/man=20(/help)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- royalpack/__main__.py | 1 + royalpack/commands/__init__.py | 1 + royalpack/commands/man.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 royalpack/commands/man.py diff --git a/royalpack/__main__.py b/royalpack/__main__.py index 949c390c..72784f6d 100644 --- a/royalpack/__main__.py +++ b/royalpack/__main__.py @@ -57,6 +57,7 @@ register_telegram(commands.fortune, ["fortune"]) register_telegram(commands.pmots, ["pmots"]) register_telegram(commands.spell, ["spell"], "(?P.+)") register_telegram(commands.smecds, ["smecds"]) +register_telegram(commands.man, ["man", "help"], "(?P[A-Za-z]+)") pda.implementations["telethon.1"].register_conversation(r) diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index 5de40c9b..7d6c42b3 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -11,3 +11,4 @@ from .fortune import * from .pmots import * from .spell import * from .smecds import * +from .man import * diff --git a/royalpack/commands/man.py b/royalpack/commands/man.py new file mode 100644 index 00000000..80477c6f --- /dev/null +++ b/royalpack/commands/man.py @@ -0,0 +1,31 @@ +import royalnet.engineer as engi + + +@engi.TeleportingConversation +async def man(*, _msg: engi.Message, _router: engi.Router, commandname: str, **__): + """ + Visualizza aiuto per un comando. + + Non funziona ancora correttamente per i multicomandi, come /dog: https://github.com/Steffo99/royalnet/issues/11 ! + """ + + # TODO: Change this when royalnet/#11 is fixed! + + if not (command := _router.by_name.get(commandname)): + await _msg.reply(text="⚠️ Il comando che hai specificato non esiste.") + return + + try: + command = command.__getattribute__("bare_function") + except AttributeError: + pass + + msg = [ + f"ℹ️ Manuale di {commandname}:", + f"{command.__doc__}", + ] + + await _msg.reply(text="\n".join(msg)) + + +__all__ = ("man",)