|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | - |
| 2 | +import json |
3 | 3 | import logging.handlers |
4 | 4 | import os |
5 | 5 | import re |
|
12 | 12 | from telegram.inline.inlinekeyboardmarkup import InlineKeyboardMarkup |
13 | 13 |
|
14 | 14 | import own_filters |
15 | | -from config import BOT_TOKEN |
| 15 | +from config import BOT_TOKEN, USE_WEBHOOK, WEBHOOK_PORT, WEBHOOK_URL, CERTPATH |
16 | 16 | from database.db_wrapper import DBwrapper |
17 | 17 | from database.statistics import get_user_stats |
18 | 18 | from game.blackJackGame import BlackJackGame |
|
35 | 35 | logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO, |
36 | 36 | handlers=[logfile_handler]) |
37 | 37 |
|
38 | | -if not re.match("[0-9]+:[a-zA-Z0-9\-_]+", BOT_TOKEN): |
| 38 | +if not re.match(r"[0-9]+:[a-zA-Z0-9\-_]+", BOT_TOKEN): |
39 | 39 | logging.error("Bot token not correct - please check.") |
40 | 40 | exit(1) |
41 | 41 |
|
@@ -150,7 +150,7 @@ def error(bot, update, error): |
150 | 150 |
|
151 | 151 | db = DBwrapper.get_instance() |
152 | 152 | for admin_id in db.get_admins(): |
153 | | - send_message(admin_id, "Update '{0}' caused error '{1}'".format(update, error)) |
| 153 | + send_message(admin_id, "Update '{0}' caused error '{1}'".format(json.dumps(update.to_dict(), indent=2), error)) |
154 | 154 |
|
155 | 155 |
|
156 | 156 | def stop_and_restart(): |
@@ -477,6 +477,11 @@ def restart(bot, update): |
477 | 477 |
|
478 | 478 | dispatcher.add_error_handler(error) |
479 | 479 |
|
480 | | -updater.start_polling() |
| 480 | +if USE_WEBHOOK: |
| 481 | + updater.start_webhook(listen="127.0.0.1", port=WEBHOOK_PORT, url_path=BOT_TOKEN, cert=CERTPATH, webhook_url=WEBHOOK_URL) |
| 482 | + updater.bot.set_webhook(WEBHOOK_URL) |
| 483 | +else: |
| 484 | + updater.start_polling() |
| 485 | + |
481 | 486 | logger.info("Bot started as @{}".format(updater.bot.username)) |
482 | 487 | updater.idle() |
0 commit comments