PagerMaid-Pyro/pagermaid/__init__.py

66 lines
1.7 KiB
Python
Raw Normal View History

2022-05-23 12:40:30 +00:00
from coloredlogs import ColoredFormatter
2022-05-27 15:09:24 +00:00
from logging import getLogger, StreamHandler, CRITICAL, INFO, basicConfig, DEBUG
2022-05-23 12:40:30 +00:00
from datetime import datetime
from os import getcwd
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from pagermaid.config import Config
import pyromod.listen
from pyrogram import Client
2022-05-25 04:19:25 +00:00
import sys
2022-05-23 12:40:30 +00:00
2022-06-07 14:33:33 +00:00
pgm_version = "1.0.7"
2022-05-23 12:40:30 +00:00
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()
# solve same process
read_context = {}
help_messages = {}
all_permissions = []
2022-05-25 11:26:50 +00:00
scheduler = AsyncIOScheduler(timezone="Asia/ShangHai")
2022-05-23 12:40:30 +00:00
if not scheduler.running:
scheduler.start()
logs = getLogger(__name__)
logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s"
logging_handler = StreamHandler()
logging_handler.setFormatter(ColoredFormatter(logging_format))
root_logger = getLogger()
2022-05-27 15:09:24 +00:00
root_logger.setLevel(DEBUG if Config.DEBUG else CRITICAL)
2022-05-23 12:40:30 +00:00
root_logger.addHandler(logging_handler)
2022-05-27 15:09:24 +00:00
basicConfig(level=DEBUG if Config.DEBUG else INFO)
logs.setLevel(DEBUG if Config.DEBUG else INFO)
2022-05-23 12:40:30 +00:00
# easy check
if not Config.API_ID:
logs.error("Api-ID Not Found!")
2022-05-25 04:19:25 +00:00
sys.exit(1)
2022-05-23 12:40:30 +00:00
elif not Config.API_HASH:
logs.error("Api-Hash Not Found!")
2022-05-25 04:19:25 +00:00
sys.exit(1)
2022-05-23 12:40:30 +00:00
start_time = datetime.utcnow()
2022-05-27 15:09:24 +00:00
try:
import uvloop
uvloop.install()
except ImportError:
pass
2022-05-25 11:26:50 +00:00
bot = Client("pagermaid",
session_string=Config.STRING_SESSION,
api_id=Config.API_ID,
api_hash=Config.API_HASH,
ipv6=Config.IPV6,
proxy=Config.PROXY)
2022-05-23 12:40:30 +00:00
async def log(message):
logs.info(
message.replace('`', '\"')
)
if not Config.LOG:
return
await bot.send_message(
Config.LOG_ID,
message
)