Skip to content

Commit

Permalink
Merge pull request #77 from d-Rickyy-b/dev
Browse files Browse the repository at this point in the history
Update Webhook config
  • Loading branch information
d-Rickyy-b committed Jun 10, 2019
2 parents e69e496 + 2c629ae commit 1bf5090
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions config.sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BOT_TOKEN = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
USE_WEBHOOK = False
WEBHOOK_PORT = 9001
WEBHOOK_URL = "https://domain.example.com/" + BOT_TOKEN
CERTPATH = "/etc/certs/example.com/fullchain.cer"
15 changes: 10 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

import json
import logging.handlers
import os
import re
Expand All @@ -12,7 +12,7 @@
from telegram.inline.inlinekeyboardmarkup import InlineKeyboardMarkup

import own_filters
from config import BOT_TOKEN
from config import BOT_TOKEN, USE_WEBHOOK, WEBHOOK_PORT, WEBHOOK_URL, CERTPATH
from database.db_wrapper import DBwrapper
from database.statistics import get_user_stats
from game.blackJackGame import BlackJackGame
Expand All @@ -35,7 +35,7 @@
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO,
handlers=[logfile_handler])

if not re.match("[0-9]+:[a-zA-Z0-9\-_]+", BOT_TOKEN):
if not re.match(r"[0-9]+:[a-zA-Z0-9\-_]+", BOT_TOKEN):
logging.error("Bot token not correct - please check.")
exit(1)

Expand Down Expand Up @@ -150,7 +150,7 @@ def error(bot, update, error):

db = DBwrapper.get_instance()
for admin_id in db.get_admins():
send_message(admin_id, "Update '{0}' caused error '{1}'".format(update, error))
send_message(admin_id, "Update '{0}' caused error '{1}'".format(json.dumps(update.to_dict(), indent=2), error))


def stop_and_restart():
Expand Down Expand Up @@ -477,6 +477,11 @@ def restart(bot, update):

dispatcher.add_error_handler(error)

updater.start_polling()
if USE_WEBHOOK:
updater.start_webhook(listen="127.0.0.1", port=WEBHOOK_PORT, url_path=BOT_TOKEN, cert=CERTPATH, webhook_url=WEBHOOK_URL)
updater.bot.set_webhook(WEBHOOK_URL)
else:
updater.start_polling()

logger.info("Bot started as @{}".format(updater.bot.username))
updater.idle()

0 comments on commit 1bf5090

Please sign in to comment.