compiling after refactoring
This commit is contained in:
@ -9,19 +9,35 @@ from telegram import Bot
|
||||
from telegram.constants import ParseMode
|
||||
from config import TELEGRAM_BOT_TOKEN, DEVELOPER_CHAT_ID, BOT_NAME
|
||||
|
||||
# Initialize Telegram Bot
|
||||
# Create a custom connection pool
|
||||
conn_pool = aiohttp.TCPConnector(limit=100) # Increase the connection limit
|
||||
timeout = aiohttp.ClientTimeout(total=30) # Set a longer timeout
|
||||
class TelegramUtils:
|
||||
def __init__(self):
|
||||
self.bot = None
|
||||
self.conn_pool = None
|
||||
self.timeout = None
|
||||
|
||||
# bot = Bot(TELEGRAM_BOT_TOKEN) # , request=aiohttp.ClientSession(connector=conn_pool, timeout=timeout).request)
|
||||
bot = Bot(token=TELEGRAM_BOT_TOKEN)
|
||||
async def initialize(self):
|
||||
# Create a custom connection pool
|
||||
self.conn_pool = aiohttp.TCPConnector(limit=100) # Increase the connection limit
|
||||
self.timeout = aiohttp.ClientTimeout(total=30) # Set a longer timeout
|
||||
|
||||
async def send_telegram_message(message):
|
||||
try:
|
||||
await bot.send_message(chat_id=DEVELOPER_CHAT_ID, text=f"[{BOT_NAME}] {message}", parse_mode=ParseMode.HTML)
|
||||
logging.info(f"Telegram message sent: {message}")
|
||||
except Exception as e:
|
||||
logging.error(f"Error sending Telegram message: {str(e)}")
|
||||
# Initialize Telegram Bot
|
||||
self.bot = Bot(token=TELEGRAM_BOT_TOKEN)
|
||||
|
||||
# You can add more Telegram-related functions here if needed
|
||||
async def send_telegram_message(self, message):
|
||||
if not self.bot:
|
||||
await self.initialize()
|
||||
|
||||
try:
|
||||
await self.bot.send_message(chat_id=DEVELOPER_CHAT_ID, text=f"[{BOT_NAME}] {message}", parse_mode=ParseMode.HTML)
|
||||
logging.info(f"Telegram message sent: {message}")
|
||||
except Exception as e:
|
||||
logging.error(f"Error sending Telegram message: {str(e)}")
|
||||
|
||||
async def close(self):
|
||||
if self.conn_pool:
|
||||
await self.conn_pool.close()
|
||||
|
||||
# Create a global instance of TelegramUtils
|
||||
telegram_utils = TelegramUtils()
|
||||
|
||||
# You can add more Telegram-related methods to the TelegramUtils class if needed
|
Reference in New Issue
Block a user