PagerMaid-Modify/pagermaid/__main__.py
Xtao_dada a84e9633c8
🐛 Support bot and fix some bugs. (#135)
 支持通过 bot 登录来使用 pagermaid 功能。
🐛 批量修复错误。
2021-10-04 00:42:16 +08:00

53 lines
1.5 KiB
Python

""" PagerMaid launch sequence. """
from sys import path
from importlib import import_module
from telethon.errors.rpcerrorlist import PhoneNumberInvalidError
from pagermaid import bot, logs, working_dir, user_bot
from pagermaid.utils import lang
if not user_bot:
from pagermaid.modules import module_list, plugin_list
else:
from pagermaid.bots import module_list, plugin_list
try:
from pagermaid.interface import server
except TypeError:
logs.error(lang('web_TypeError'))
server = None
except KeyError:
logs.error(lang('web_KeyError'))
server = None
path.insert(1, f"{working_dir}/plugins")
try:
bot.start()
except PhoneNumberInvalidError:
print(lang('PhoneNumberInvalidError'))
exit(1)
for module_name in module_list:
try:
if user_bot:
import_module("pagermaid.bots." + module_name)
else:
import_module("pagermaid.modules." + module_name)
except BaseException as exception:
logs.info(f"{lang('module')} {module_name} {lang('error')}: {type(exception)}: {exception}")
for plugin_name in plugin_list:
try:
import_module("plugins." + plugin_name)
except BaseException as exception:
logs.info(f"{lang('module')} {plugin_name} {lang('error')}: {exception}")
plugin_list.remove(plugin_name)
if server is not None:
import_module("pagermaid.interface")
logs.info(lang('start'))
bot.run_until_disconnected()
if server is not None:
try:
server.stop()
except AttributeError:
pass