-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (35 loc) · 957 Bytes
/
main.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'ipetrash'
import os
import time
# pip install python-telegram-bot
from telegram.ext import Updater, Defaults
from config import TOKEN
from bot.common import log
from bot import commands
def main():
log.debug('Start')
cpu_count = os.cpu_count()
workers = cpu_count
log.debug(f'System: CPU_COUNT={cpu_count}, WORKERS={workers}')
updater = Updater(
TOKEN,
workers=workers,
defaults=Defaults(run_async=True),
)
bot = updater.bot
log.debug(f'Bot name {bot.first_name!r} ({bot.name})')
commands.setup(updater)
updater.start_polling()
updater.idle()
log.debug('Finish')
if __name__ == '__main__':
while True:
try:
main()
except:
log.exception('')
timeout = 15
log.info(f'Restarting the bot after {timeout} seconds')
time.sleep(timeout)