Skip to content

Commit cfbdf84

Browse files
committed
Add a few comment + improve debugging
1 parent 44557c1 commit cfbdf84

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

bot/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
GITHUB_OAUTH_CLIENT_ID = os.getenv('GITHUB_OAUTH_CLIENT_ID')
1414
GITHUB_OAUTH_CLIENT_SECRET = os.getenv('GITHUB_OAUTH_CLIENT_SECRET')
1515
GITHUB_OAUTH_REDIRECT_URI = SERVER_URL_BASE + '/github/auth'
16+
DEBUG = os.getenv('DEBUG', False)

bot/main.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from telegram.ext import TypeHandler, CallbackContext, CommandHandler, MessageHandler, Filters
66

77
from bot import settings
8-
from bot.const import TELEGRAM_BOT_TOKEN, DATABASE_FILE
8+
from bot.const import TELEGRAM_BOT_TOKEN, DATABASE_FILE, DEBUG
99
from bot.github import GithubHandler
1010
from bot.githubapi import github_api
1111
from bot.githubupdates import GithubUpdate, GithubAuthUpdate
@@ -14,9 +14,10 @@
1414
from bot.utils import decode_first_data_entity, deep_link, reply_data_link_filter
1515
from bot.webhookupdater import WebhookUpdater
1616

17-
http.client.HTTPConnection.debuglevel = 5
17+
if DEBUG:
18+
http.client.HTTPConnection.debuglevel = 5
1819

19-
logging.basicConfig(level=logging.DEBUG,
20+
logging.basicConfig(level=logging.DEBUG if DEBUG else logging.INFO,
2021
# [%(filename)s:%(lineno)d]
2122
format='%(asctime)s %(levelname)-8s %(name)s - %(message)s')
2223

@@ -28,7 +29,9 @@ def error_handler(update, context: CallbackContext):
2829
def start_handler(update: Update, context: CallbackContext):
2930
msg = update.effective_message
3031

32+
# For deep linking
3133
if context.args:
34+
# Get the deep link argument and treat it as a command
3235
args = context.args[0].split('__')
3336
update.effective_message.text = '/' + ' '.join(args)
3437
update.effective_message.entities[0].length = len(args[0]) + 1
@@ -136,16 +139,22 @@ def reply_handler(update: Update, context: CallbackContext):
136139

137140

138141
if __name__ == '__main__':
142+
# Not strictly needed anymore since we no longer have custom persistent data
143+
# But since we likely will want it in the future, we keep our custom persistence
139144
persistence = Persistence(DATABASE_FILE)
145+
# Init our very custom webhook handler
140146
updater = WebhookUpdater(TELEGRAM_BOT_TOKEN,
141147
updater_kwargs={'use_context': True,
142148
'persistence': persistence})
143149
dp = updater.dispatcher
144150

151+
# See persistence note above
145152
CallbackContext.github_data = property(lambda self: persistence.github_data)
146153

154+
# Save data every five (5) min
147155
dp.job_queue.run_repeating(lambda *_: persistence.flush(), 5 * 60)
148156

157+
# Telegram updates
149158
dp.add_handler(CommandHandler('start', start_handler))
150159
dp.add_handler(CommandHandler('help', help_handler))
151160
dp.add_handler(CommandHandler('privacy', privacy_handler))
@@ -154,9 +163,11 @@ def reply_handler(update: Update, context: CallbackContext):
154163

155164
settings.add_handlers(dp)
156165

166+
# For commenting on issues/PR/reviews
157167
dp.add_handler(MessageHandler(Filters.reply & reply_data_link_filter, reply_handler,
158168
channel_post_updates=False, edited_updates=False))
159169

170+
# Non-telegram updates
160171
github_handler = GithubHandler(dp)
161172
dp.add_handler(TypeHandler(GithubUpdate, github_handler.handle_update))
162173
dp.add_handler(TypeHandler(GithubAuthUpdate, github_handler.handle_auth_update))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy