forked from zeshuaro/telegram-pdf-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·47 lines (34 loc) · 1.22 KB
/
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
import os
from dotenv import load_dotenv
from loguru import logger
from telegram.ext import Updater
from telegram.ext import messagequeue as mq
from telegram.utils.request import Request
import pdf_bot.dispatcher as dp
import pdf_bot.logging as pdf_bot_logging
from pdf_bot.mq_bot import MQBot
load_dotenv()
TELEGRAM_TOKEN = os.environ.get("TELEGRAM_TOKEN")
TIMEOUT = 20
def main():
# Setup logging
pdf_bot_logging.setup_logging()
q = mq.MessageQueue(all_burst_limit=3, all_time_limit_ms=3000)
request = Request(con_pool_size=8)
pdf_bot = MQBot(TELEGRAM_TOKEN, request=request, mqueue=q)
# Create the EventHandler and pass it your bot's token.
updater = Updater(
bot=pdf_bot,
use_context=True,
request_kwargs={"connect_timeout": TIMEOUT, "read_timeout": TIMEOUT},
)
dispatcher = updater.dispatcher
dp.setup_dispatcher(dispatcher)
updater.start_polling()
logger.info("Bot started 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__":
main()