[+] Create command wrapper

This commit is contained in:
Hykilpikonna
2020-11-22 13:34:18 -05:00
parent 1885da1e61
commit 978376305c
+19
View File
@@ -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)