2020-02-19 15:31:39 +00:00
|
|
|
""" 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
|
2021-04-12 16:25:32 +00:00
|
|
|
from pagermaid.utils import lang
|
2020-02-19 15:31:39 +00:00
|
|
|
from pagermaid.modules import module_list, plugin_list
|
|
|
|
try:
|
|
|
|
from pagermaid.interface import server
|
|
|
|
except TypeError:
|
2021-04-12 16:25:32 +00:00
|
|
|
logs.error(lang('web_TypeError'))
|
2020-02-19 15:31:39 +00:00
|
|
|
server = None
|
|
|
|
except KeyError:
|
2021-04-12 16:25:32 +00:00
|
|
|
logs.error(lang('web_KeyError'))
|
2020-02-19 15:31:39 +00:00
|
|
|
server = None
|
|
|
|
|
|
|
|
|
|
|
|
path.insert(1, f"{working_dir}/plugins")
|
|
|
|
|
|
|
|
try:
|
|
|
|
bot.start()
|
|
|
|
except PhoneNumberInvalidError:
|
2021-04-12 16:25:32 +00:00
|
|
|
print(lang('PhoneNumberInvalidError'))
|
2020-02-19 15:31:39 +00:00
|
|
|
exit(1)
|
|
|
|
for module_name in module_list:
|
|
|
|
try:
|
|
|
|
import_module("pagermaid.modules." + module_name)
|
2020-08-09 15:46:25 +00:00
|
|
|
except BaseException as exception:
|
2021-04-12 16:25:32 +00:00
|
|
|
logs.info(f"{lang('module')} {module_name} {lang('error')}: {type(exception)}: {exception}")
|
2020-02-19 15:31:39 +00:00
|
|
|
for plugin_name in plugin_list:
|
|
|
|
try:
|
|
|
|
import_module("plugins." + plugin_name)
|
|
|
|
except BaseException as exception:
|
2021-04-12 16:25:32 +00:00
|
|
|
logs.info(f"{lang('module')} {plugin_name} {lang('error')}: {exception}")
|
2020-02-19 15:31:39 +00:00
|
|
|
plugin_list.remove(plugin_name)
|
|
|
|
if server is not None:
|
|
|
|
import_module("pagermaid.interface")
|
2021-04-12 16:25:32 +00:00
|
|
|
logs.info(lang('start'))
|
2020-02-19 15:31:39 +00:00
|
|
|
bot.run_until_disconnected()
|
|
|
|
if server is not None:
|
2021-04-04 03:04:11 +00:00
|
|
|
try:
|
|
|
|
server.stop()
|
|
|
|
except AttributeError:
|
|
|
|
pass
|