From 30bdbe36c159253cb0b76ff207f33da926566f63 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 5 Aug 2020 22:53:17 -0700 Subject: [PATCH] refactor to use module script execution --- tipbot/__main__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tipbot/__main__.py diff --git a/tipbot/__main__.py b/tipbot/__main__.py new file mode 100644 index 0000000..de6b5a8 --- /dev/null +++ b/tipbot/__main__.py @@ -0,0 +1,24 @@ +import logging +from tipbot import commands, wownero, config +from os import environ +from telegram.ext import Updater, CommandHandler + +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' +) + +if __name__ == '__main__': + token = config.TG_TOKEN + if token: + logging.info('Starting bot.') + updater = Updater(token=token, use_context=True) + dispatcher = updater.dispatcher + for cmd in commands.all_commands: + logging.info(f'registering command: {cmd}') + handler = CommandHandler(cmd, commands.all_commands[cmd]['func']) + dispatcher.add_handler(handler) + updater.start_polling() + else: + logging.error('No token provided. Quitting!') + exit(2)