-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathqBit_remote.py
606 lines (554 loc) · 30.2 KB
/
qBit_remote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Simple bot for using qBit client via Telegram.
import bot_auth
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, ConversationHandler)
import logging
import re
import json
from qbittorrentv2 import Client
from qbittorrentv2 import client
from requests import exceptions
class Bot:
qb = None
download_folder = "./downloads"
logged_in = False
TOKEN = bot_auth.token
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(name=__name__)
IP = 0
ADD_FILE = 0
ADD_MAGNET_LINK = 0
ip_port_text = None
username_password = None
def start(self, bot, update):
self.ip_port_text = None
self.username_password = None
self.logged_in = False
user = update.message.from_user
if str(user.id) in bot_auth.user_id:
self.logger.info("Authorized usage tried by: %s -- %s" % (user.username, user.id))
with open('logins.json', 'r') as f:
logins = json.load(f)
list_of_logins = ""
for key in logins:
list_of_logins += key + "\n"
update.message.reply_text(
"Hello, I'm QBitTorrent Remote controller.\n\n"
"List of available servers\n\n" +
list_of_logins)
return self.IP
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
return ConversationHandler.END
def ip(self, bot, update):
self.login_info = update.message.text
with open('logins.json', 'r') as f:
logins = json.load(f)
for key in logins:
if key in self.login_info:
self.ip_port_text = logins[key]['ip_port']
self.username = logins[key]['username']
self.password = logins[key]['password']
user = update.message.from_user
if re.match('^(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}|localhost):\d{1,5}$', self.ip_port_text):
self.logger.info("User %s entered a right IP and PORT" % user.id)
self.logger.info("Trying to connect to client")
try:
self.qb = Client("http://%s" % self.ip_port_text)
try:
self.qb.torrents()
self.logger.info("Logging in was successful.")
update.message.reply_text("Logged in! Now you can use me.\n"
"To get info about commands type /help")
self.logged_in = True
except client.LoginRequired:
self.logger.info("Login required.")
if not self.username and self.password:
update.message.reply_text("Login info missing.\n"
"Please add in logins.json")
return ConversationHandler.END
else:
self.logger.info("Trying to login with given username and password")
try:
self.qb.login(username=self.username, password=self.password)
self.qb.torrents()
self.logger.info("Logging in was successful.")
update.message.reply_text("Logged in! Now you can use me.\n"
"To get info about commands type /help")
self.logged_in = True
except client.LoginRequired:
self.logger.info("Username or Password was wrong")
update.message.reply_text("Username or Password was wrong\n"
"Please edit the username or password in logins.json.")
return ConversationHandler.END
except exceptions.ConnectionError:
self.logger.info("Connection refused.")
update.message.reply_text("Connection to given IP address is refused."
"\nPlease try again by typing /start")
self.ip_port_text = None
else:
self.logger.info("User %s entered a wrong IP and PORT" % user.id)
update.message.reply_text("Please enter a proper ip and port in logins.json.\nYou can restart by typing /start")
return ConversationHandler.END
def reconnect(self, bot, update):
user = update.message.from_user
if self.ip_port_text is not None and not self.logged_in and str(user.id) in bot_auth.user_id:
try:
self.qb = Client("http://%s/" % self.ip_port_text)
try:
self.qb.torrents()
self.logger.info("Logging in was successful.")
update.message.reply_text("Logged in! Now you can use me.\n"
"To get info about commands type /help")
self.logged_in = True
except client.LoginRequired:
self.logger.info("Trying to log in using previous info")
username_password_split = self.username_password.split(" ")
self.qb.login(username=username_password_split[0], password=username_password_split[1])
try:
self.qb.torrents()
self.logger.info("Logging in was successful.")
update.message.reply_text("Logged in! Now you can use me.\n"
"To get info about commands type /help")
self.logged_in = True
except client.LoginRequired:
self.logger.info("Logging in with old info was unsuccessful.")
update.message.reply_text("Logging in with old info was unsuccessful.\n"
"You can try again later (/reconnect)\nor type new info using /start")
except exceptions.ConnectionError:
self.logger.info("Connection refused.")
update.message.reply_text("Connection to client IP address is refused."
"\nPlease try again by typing /start"
"\nOr try to /reconnect later.")
elif str(user) not in bot_auth.user_id:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
elif self.logged_in:
self.logger.info("User tried to use reconnect while already logged in.")
update.message.reply_text("You are already logged in. You don't need to reconnect")
elif self.ip_port_text is None:
self.logger.info("User tried to use reconnect without any previous info.")
update.message.reply_text("You don't have any previous info. \nPlease type /start to connect")
def cancel(self, bot, update):
user = update.message.from_user
self.logger.info("User %s canceled the conversation." % user.first_name)
update.message.reply_text('Bye! I hope we can talk again some day.')
self.ip_port_text = None
return ConversationHandler.END
def list_downloading_torrents(self, bot, update):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id and self.logged_in:
output = ""
self.logger.info("%s tried listing downloading." % update.message.from_user)
if len(self.qb.torrents()) > 0:
for torrent in self.qb.torrents(filter="downloading"):
output += "--%s, %s%%\n" % (torrent["name"], int(torrent["progress"]*100))
update.message.reply_text("Torrents currently downloading:\n%s" % output)
else:
update.message.reply_text("There is no torrents to list.")
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
return self.reconnect(bot=bot, update=update)
def list(self, bot, update):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id and self.logged_in:
output = ""
self.logger.info("%s tried listing." % update.message.from_user)
if len(self.qb.torrents()) > 0:
for torrent in self.qb.torrents():
output += "--%s, %s, %s%%\n" % (torrent["name"],torrent["state"].upper(),int(torrent["progress"]*100))
update.message.reply_text("Torrents currently downloading:\n%s" % output)
else:
update.message.reply_text("There is no torrents to list.")
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
return self.reconnect(bot=bot, update=update)
def pause(self, bot, update, args):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id and self.logged_in:
torrents_to_pause = []
torrents_copy = self.qb.torrents().copy()
for arg in args:
for torrent in torrents_copy:
if re.match(arg, torrent["name"], re.IGNORECASE):
torrents_copy.remove(torrent)
torrents_to_pause.append(str(torrent["hash"]))
self.qb.pause(torrents_to_pause)
self.logger.info("Paused following: %s" % args)
output = ""
for torrent in torrents_to_pause:
output += "--%s, %s%%\n" % (torrent["name"], int(torrent["progress"]*100))
update.message.reply_text("Following torrents paused:\n%s" % output)
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
return self.reconnect(bot=bot, update=update)
def pause_all(self, bot, update):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id:
self.qb.pause_all()
self.logger.info("Paused all")
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
return self.reconnect(bot=bot, update=update)
def resume(self, bot, update, args):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id:
torrents_to_resume = []
torrents_copy = self.qb.torrents().copy()
for arg in args:
for torrent in torrents_copy:
if re.match(arg, torrent["name"], re.IGNORECASE):
torrents_copy.remove(torrent)
torrents_to_resume.append(str(torrent["hash"]))
self.qb.resume(torrents_to_resume)
self.logger.info("Paused following: %s" % args)
output = ""
for torrent in torrents_to_resume:
output += "--%s, %s%%\n" % (torrent["name"], int(torrent["progress"]*100))
update.message.reply_text("Following torrents resumed:\n%s" % output)
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
return self.reconnect(bot=bot, update=update)
def resume_all(self, bot, update, args):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id:
self.qb.resume_all()
self.logger.info("Resumed all")
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
return self.reconnect(bot=bot, update=update)
def add(self, bot, update):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id:
update.message.reply_text("Send .torrent file you want to download.")
return self.ADD_FILE
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
return ConversationHandler.END
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
self.reconnect(bot=bot, update=update)
return ConversationHandler.END
def add_magnet(self, bot, update):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id:
update.message.reply_text("Send magnet you want to download.")
return self.ADD_MAGNET_LINK
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
return ConversationHandler.END
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
self.reconnect(bot=bot, update=update)
return ConversationHandler.END
def add_file(self, bot, update):
try:
user = update.message.from_user
if str(user.id) in bot_auth.user_id:
update.message.reply_text("File received. ")
file = bot.get_file(file_id=update.message.document.file_id)
# print(file)
document = update.message.document
file_extension = document.file_name.split(".")[-1]
if re.match("^torrent$", file_extension, re.IGNORECASE):
# file.
file.download(custom_path="%s/%s" % (self.download_folder, document.file_name))
file_read = open("%s/%s" % (self.download_folder, document.file_name), "rb")
self.logger.info("Torrent file downloaded to %s" % self.download_folder)
self.qb.download_from_file(file_read)
self.logger.info("Started downloading %s" % document.file_name)
update.message.reply_text("Downloading the file.")
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
return ConversationHandler.END
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
self.reconnect(bot=bot, update=update)
return ConversationHandler.END
def add_magnet_link(self, bot, update):
try:
user = update.message.from_user
if str(user.id) in bot_auth.user_id:
update.message.reply_text("Link received.")
magnet_link = update.message.text
self.qb.download_from_link(magnet_link)
update.message.reply_text("Downloading the file.")
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
return ConversationHandler.END
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
self.reconnect(bot=bot, update=update)
return ConversationHandler.END
def add_feed(self, bot, update):
user = update.message.from_user
try:
if str(user.id) in bot_auth.user_id:
update.message.reply_text("Send feed url to add.")
return self.feed
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
return ConversationHandler.END
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
self.reconnect(bot=bot, update=update)
return ConversationHandler.END
def feed(self, bot, update):
try:
user = update.message.from_user
if str(user.id) in bot_auth.user_id:
feed_url = update.message.text
self.qb.add_feed(feed_url)
self.logger.info("Feed url '%s' added" % feed_url)
update.message.reply_text("Feed url added")
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
return ConversationHandler.END
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
self.reconnect(bot=bot, update=update)
return ConversationHandler.END
def get_item(self, bot, update):
try:
user = update.message.from_user
if str(user.id) in bot_auth.user_id:
item = self.qb.get_item()
update.message.reply_text(item)
elif not self.logged_in:
self.logger.info("Usage without logging in tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You should first login by typing /start")
else:
self.logger.info("Unauthorized usage tried by: %s -- %s" % (user.username, user.id))
update.message.reply_text(
"You don't have rights to use me! Who the f*** are you?")
return ConversationHandler.END
except exceptions.ConnectionError:
self.logger.info("Connection is lost. Retrying to connect...")
self.logged_in = False
update.message.reply_text(
"Ups. Connection to qBit Client is lost. \nRetrying to connect with previous info.")
self.reconnect(bot=bot, update=update)
return ConversationHandler.END
def help(self, bot, update):
update.message.reply_text("Simple bot for using qBit client via Telegram.\n"
"Available commands:\n"
"/start\n"
"--- Start logging in process with new info.\n"
"/reconnect\n"
"--- Try to reconnect using previously entered info.\n"
"/pause NAME1 NAME2 NAME3 ...\n"
"--- Pause torrents : NAME1, NAME2 etc.\n"
"/pause_all\n"
"--- Pause all torrents.\n"
"/resume NAME1 NAME2 NAME3 ...\n"
"--- Resume torrents : NAME1, NAME2 etc.\n"
"/resume_all\n"
"--- Resume all torrents. \n"
"/list\n"
"--- List all torrents.\n"
"/downloading\n"
"--- List all torrents with Downloading status\n"
"/add\n"
"--- Start downloading of a new .torrent file.\n"
"/add_magnet\n"
"--- Start downloading of a new magnet link.\n"
"/help\n"
"--- Display this message.\n"
"PS: NAME1 NAME2 etc. does *NOT* have to be FULL name.")
def error(self, bot, update, error):
self.logger.warn('Update "%s" caused error "%s"' % (update, error))
def main(self):
# Create the EventHandler and pass it your bot's token.
updater = Updater(self.TOKEN)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# Add conversation handler with the states GENDER, PHOTO, LOCATION and BIO
conv_handler_start = ConversationHandler(
entry_points=[CommandHandler('start', self.start)],
states={
self.IP: [MessageHandler(Filters.text, self.ip)],
},
fallbacks=[CommandHandler('cancel', self.cancel)]
)
conv_handler_torrent = ConversationHandler(
entry_points=[CommandHandler("add", self.add)],
states={
self.ADD_FILE: [MessageHandler(Filters.document, self.add_file)]
},
fallbacks=[CommandHandler('cancel', self.cancel)]
)
conv_handler_magnet = ConversationHandler(
entry_points=[CommandHandler("add_magnet", self.add_magnet)],
states={
self.ADD_MAGNET_LINK: [MessageHandler(Filters.text, self.add_magnet_link)]
},
fallbacks=[CommandHandler('cancel', self.cancel)]
)
conv_handler_feed = ConversationHandler(
entry_points=[CommandHandler("add_feed", self.add_feed)],
states={
self.feed: [MessageHandler(Filters.text, self.feed)]
},
fallbacks=[CommandHandler('cancel', self.cancel)]
)
# dp.add_handler()
dp.add_handler(conv_handler_start)
dp.add_handler(conv_handler_torrent)
dp.add_handler(conv_handler_magnet)
dp.add_handler(conv_handler_feed)
dp.add_handler(CommandHandler("get_item", self.get_item))
dp.add_handler(CommandHandler("downloading", self.list_downloading_torrents))
dp.add_handler(CommandHandler("list", self.list))
dp.add_handler(CommandHandler("pause", self.pause, pass_args=True))
dp.add_handler(CommandHandler("resume", self.resume, pass_args=True))
dp.add_handler(CommandHandler("pause_all", self.pause_all))
dp.add_handler(CommandHandler("resume_all", self.resume_all, pass_args=True))
dp.add_handler(CommandHandler("reconnect", self.reconnect))
dp.add_handler(CommandHandler("help", self.help))
# log all errors
dp.add_error_handler(self.error)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
if __name__ == '__main__':
bot = Bot()
bot.main()