2023-07-21 14:00:49 +00:00
|
|
|
from logging import getLogger, INFO, StreamHandler, basicConfig, CRITICAL, Formatter
|
2023-01-17 03:26:10 +00:00
|
|
|
|
2022-12-22 14:18:43 +00:00
|
|
|
import httpx
|
|
|
|
import pyrogram
|
|
|
|
|
2023-07-21 14:00:49 +00:00
|
|
|
from cashews import cache
|
|
|
|
|
2023-01-27 12:36:41 +00:00
|
|
|
from models.fix_topic import fix_topic
|
2023-07-21 14:00:49 +00:00
|
|
|
from glover import api_id, api_hash, ipv6, cache_uri
|
2023-01-27 12:36:41 +00:00
|
|
|
from models.services.scheduler import scheduler
|
|
|
|
from models.sqlite import Sqlite
|
2022-12-22 14:18:43 +00:00
|
|
|
|
2023-07-21 14:00:49 +00:00
|
|
|
# Set Cache
|
|
|
|
cache.setup(cache_uri)
|
2022-12-22 14:18:43 +00:00
|
|
|
# Enable logging
|
2023-07-21 10:26:12 +00:00
|
|
|
logs = getLogger(__name__)
|
2022-12-22 14:18:43 +00:00
|
|
|
logging_handler = StreamHandler()
|
2023-07-21 14:00:49 +00:00
|
|
|
dt_fmt = "%Y-%m-%d %H:%M:%S"
|
2023-07-21 10:26:12 +00:00
|
|
|
formatter = Formatter(
|
2023-07-21 14:00:49 +00:00
|
|
|
"[{asctime}] [{levelname:<8}] {name}: {message}", dt_fmt, style="{"
|
2023-07-21 10:26:12 +00:00
|
|
|
)
|
|
|
|
logging_handler.setFormatter(formatter)
|
|
|
|
root_logger = getLogger()
|
|
|
|
root_logger.setLevel(CRITICAL)
|
2022-12-22 14:18:43 +00:00
|
|
|
root_logger.addHandler(logging_handler)
|
2023-07-21 10:26:12 +00:00
|
|
|
pyro_logger = getLogger("pyrogram")
|
|
|
|
pyro_logger.setLevel(CRITICAL)
|
|
|
|
pyro_logger.addHandler(logging_handler)
|
2022-12-22 14:18:43 +00:00
|
|
|
basicConfig(level=INFO)
|
|
|
|
logs.setLevel(INFO)
|
|
|
|
|
|
|
|
if not scheduler.running:
|
|
|
|
scheduler.start()
|
|
|
|
# Init client
|
2023-07-03 14:39:52 +00:00
|
|
|
bot = pyrogram.Client(
|
|
|
|
"bot", api_id=api_id, api_hash=api_hash, ipv6=ipv6, plugins=dict(root="modules")
|
|
|
|
)
|
2023-01-17 03:26:10 +00:00
|
|
|
# fix topic group
|
|
|
|
setattr(pyrogram.types.Message, "old_parse", getattr(pyrogram.types.Message, "_parse"))
|
|
|
|
setattr(pyrogram.types.Message, "_parse", fix_topic)
|
|
|
|
|
2022-12-22 14:18:43 +00:00
|
|
|
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)
|
2023-01-27 12:36:41 +00:00
|
|
|
sqlite = Sqlite()
|