PagerMaid-Pyro/pagermaid/__main__.py

48 lines
1.4 KiB
Python
Raw Normal View History

2022-05-23 12:40:30 +00:00
from sys import path, platform
from os import sep
from importlib import import_module
from pyrogram import idle
from pagermaid import bot, logs, working_dir
2022-06-27 13:42:24 +00:00
from pagermaid.hook import Hook
2022-05-23 12:40:30 +00:00
from pagermaid.modules import module_list, plugin_list
2022-08-01 16:04:45 +00:00
from pagermaid.single_utils import safe_remove
2022-06-07 12:44:45 +00:00
from pagermaid.utils import lang, process_exit
2022-05-23 12:40:30 +00:00
path.insert(1, f"{working_dir}{sep}plugins")
2022-05-27 15:09:24 +00:00
async def main():
logs.info(lang('platform') + platform + lang('platform_load'))
await bot.start()
me = await bot.get_me()
2022-08-01 16:04:45 +00:00
if me.is_bot:
safe_remove("pagermaid.session")
exit()
logs.info(f"{lang('save_id')} {me.first_name}({me.id})")
2022-05-27 15:09:24 +00:00
for module_name in module_list:
try:
2022-06-20 13:55:14 +00:00
import_module(f"pagermaid.modules.{module_name}")
2022-05-27 15:09:24 +00:00
except BaseException as exception:
logs.info(f"{lang('module')} {module_name} {lang('error')}: {type(exception)}: {exception}")
for plugin_name in plugin_list:
try:
2022-06-20 13:55:14 +00:00
import_module(f"plugins.{plugin_name}")
2022-05-27 15:09:24 +00:00
except BaseException as exception:
logs.info(f"{lang('module')} {plugin_name} {lang('error')}: {exception}")
plugin_list.remove(plugin_name)
2022-06-07 12:44:45 +00:00
await process_exit(start=True, _client=bot)
2022-05-27 15:09:24 +00:00
logs.info(lang('start'))
2022-11-14 14:11:27 +00:00
await Hook.load_success_exec()
2022-06-27 13:42:24 +00:00
await Hook.startup()
2022-05-27 15:09:24 +00:00
await idle()
await bot.stop()
bot.run(main())