5
5
from telegram .ext import TypeHandler , CallbackContext , CommandHandler , MessageHandler , Filters
6
6
7
7
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
9
9
from bot .github import GithubHandler
10
10
from bot .githubapi import github_api
11
11
from bot .githubupdates import GithubUpdate , GithubAuthUpdate
14
14
from bot .utils import decode_first_data_entity , deep_link , reply_data_link_filter
15
15
from bot .webhookupdater import WebhookUpdater
16
16
17
- http .client .HTTPConnection .debuglevel = 5
17
+ if DEBUG :
18
+ http .client .HTTPConnection .debuglevel = 5
18
19
19
- logging .basicConfig (level = logging .DEBUG ,
20
+ logging .basicConfig (level = logging .DEBUG if DEBUG else logging . INFO ,
20
21
# [%(filename)s:%(lineno)d]
21
22
format = '%(asctime)s %(levelname)-8s %(name)s - %(message)s' )
22
23
@@ -28,7 +29,9 @@ def error_handler(update, context: CallbackContext):
28
29
def start_handler (update : Update , context : CallbackContext ):
29
30
msg = update .effective_message
30
31
32
+ # For deep linking
31
33
if context .args :
34
+ # Get the deep link argument and treat it as a command
32
35
args = context .args [0 ].split ('__' )
33
36
update .effective_message .text = '/' + ' ' .join (args )
34
37
update .effective_message .entities [0 ].length = len (args [0 ]) + 1
@@ -136,16 +139,22 @@ def reply_handler(update: Update, context: CallbackContext):
136
139
137
140
138
141
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
139
144
persistence = Persistence (DATABASE_FILE )
145
+ # Init our very custom webhook handler
140
146
updater = WebhookUpdater (TELEGRAM_BOT_TOKEN ,
141
147
updater_kwargs = {'use_context' : True ,
142
148
'persistence' : persistence })
143
149
dp = updater .dispatcher
144
150
151
+ # See persistence note above
145
152
CallbackContext .github_data = property (lambda self : persistence .github_data )
146
153
154
+ # Save data every five (5) min
147
155
dp .job_queue .run_repeating (lambda * _ : persistence .flush (), 5 * 60 )
148
156
157
+ # Telegram updates
149
158
dp .add_handler (CommandHandler ('start' , start_handler ))
150
159
dp .add_handler (CommandHandler ('help' , help_handler ))
151
160
dp .add_handler (CommandHandler ('privacy' , privacy_handler ))
@@ -154,9 +163,11 @@ def reply_handler(update: Update, context: CallbackContext):
154
163
155
164
settings .add_handlers (dp )
156
165
166
+ # For commenting on issues/PR/reviews
157
167
dp .add_handler (MessageHandler (Filters .reply & reply_data_link_filter , reply_handler ,
158
168
channel_post_updates = False , edited_updates = False ))
159
169
170
+ # Non-telegram updates
160
171
github_handler = GithubHandler (dp )
161
172
dp .add_handler (TypeHandler (GithubUpdate , github_handler .handle_update ))
162
173
dp .add_handler (TypeHandler (GithubAuthUpdate , github_handler .handle_auth_update ))
0 commit comments