From 978376305c88adbadb1661ce601cbb5e0bb929f6 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sun, 22 Nov 2020 13:34:18 -0500 Subject: [PATCH] [+] Create command wrapper --- src/utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/utils.py b/src/utils.py index d98f202..950cf94 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,5 +1,24 @@ import json +from telegram.ext import CommandHandler + def toJson(obj): return json.dumps(obj, default=lambda o: o.__dict__, sort_keys=True, indent=4) + + +# Wrap command +def createCommand(method): + + # Create wrapper command + def command(update, context): + + # Run command and get return data + data = method(update, context) + + # Send back data if not null + if data is not None and data is not '': + context.bot.send_message(chat_id=update.effective_chat.id, text=data) + + # Create handler for the wrapper command + return CommandHandler(method.__name__, command, run_async=True)