2023-05-24 15:20:21 +00:00
|
|
|
import pyrogram
|
|
|
|
import httpx
|
|
|
|
|
2023-12-01 14:23:51 +00:00
|
|
|
from defs.glover import api_id, api_hash, logtail_token
|
2023-05-24 15:20:21 +00:00
|
|
|
from scheduler import scheduler
|
2023-05-25 12:23:38 +00:00
|
|
|
from logging import getLogger, INFO, ERROR, StreamHandler, basicConfig, FileHandler, Formatter
|
2023-05-24 15:20:21 +00:00
|
|
|
from coloredlogs import ColoredFormatter
|
2023-12-01 14:23:51 +00:00
|
|
|
from logtail import LogtailHandler
|
2023-05-24 15:20:21 +00:00
|
|
|
|
|
|
|
# Enable logging
|
|
|
|
logs = getLogger("T2G")
|
|
|
|
logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s"
|
|
|
|
logging_handler = StreamHandler()
|
|
|
|
logging_handler.setFormatter(ColoredFormatter(logging_format))
|
2023-05-25 12:23:38 +00:00
|
|
|
file_handler = FileHandler("log.txt", mode="w", encoding="utf-8")
|
|
|
|
file_handler.setFormatter(Formatter(logging_format))
|
2023-12-01 14:23:51 +00:00
|
|
|
logtail_handler = LogtailHandler(source_token=logtail_token)
|
2023-05-24 15:20:21 +00:00
|
|
|
root_logger = getLogger()
|
|
|
|
root_logger.setLevel(ERROR)
|
|
|
|
root_logger.addHandler(logging_handler)
|
2023-05-25 12:23:38 +00:00
|
|
|
root_logger.addHandler(file_handler)
|
2023-12-01 14:23:51 +00:00
|
|
|
if logtail_token:
|
|
|
|
root_logger.addHandler(logtail_handler)
|
2023-05-24 15:20:21 +00:00
|
|
|
basicConfig(level=INFO)
|
|
|
|
logs.setLevel(INFO)
|
|
|
|
|
|
|
|
if not scheduler.running:
|
|
|
|
scheduler.start()
|
|
|
|
|
|
|
|
bot = pyrogram.Client(
|
|
|
|
"bot", api_id=api_id, api_hash=api_hash, plugins=dict(root="plugins")
|
|
|
|
)
|
|
|
|
headers = {
|
|
|
|
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.72 Safari/537.36"
|
|
|
|
}
|
|
|
|
request = httpx.AsyncClient(timeout=60.0, headers=headers)
|