-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
61 lines (47 loc) · 1.62 KB
/
bot.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
#!/usr/bin/env python3
"""
This is the main file for the bot.
"""
import os
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import ApplicationBuilder
from telegram.request import HTTPXRequest
from plugins.commands.convert_to_pdf import pdf_conv_handler
from plugins.commands.help import help_handler
from plugins.commands.rename import conv_handler
from plugins.commands.docx_pdf import docx_to_pdf_handler
from plugins.commands.start import start_handler
from plugins.commands.analyze_colors import analyze_callback
from plugins.commands.url_upload import url_conv_handler
from plugins.helpers.logger import logger
# Load environment variables
try:
load_dotenv()
except FileNotFoundError:
logger.info("No .env file found. Ignore if you are using a production bot")
BOT_TOKEN = os.getenv("BOT_TOKEN")
logger.info("Starting Bot...")
def main() -> None:
"""
Register handlers and run the bot
"""
# Create an HTTPXRequest object with increased timeout settings
request = HTTPXRequest(
connect_timeout=10.0, # Increase connection timeout
read_timeout=20.0 # Increase read timeout
)
app = ApplicationBuilder().token(BOT_TOKEN).request(request).build()
# Command Handlers
app.add_handler(start_handler)
app.add_handler(help_handler)
# Message Handlers
app.add_handler(analyze_callback)
# conv Handlers
app.add_handler(conv_handler)
app.add_handler(url_conv_handler)
app.add_handler(pdf_conv_handler)
app.add_handler(docx_to_pdf_handler)
app.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
main()