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
|
2022-01-26 13:36:11 +00:00
|
|
|
from pagermaid import bot, logs, working_dir, user_bot, redis, redis_status
|
2021-04-12 16:25:32 +00:00
|
|
|
from pagermaid.utils import lang
|
2022-01-26 13:36:11 +00:00
|
|
|
|
|
|
|
|
2021-10-03 16:42:16 +00:00
|
|
|
if not user_bot:
|
|
|
|
from pagermaid.modules import module_list, plugin_list
|
|
|
|
else:
|
|
|
|
from pagermaid.bots import module_list, plugin_list
|
|
|
|
|
2020-02-19 15:31:39 +00:00
|
|
|
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)
|
2022-01-26 13:36:11 +00:00
|
|
|
|
2020-02-19 15:31:39 +00:00
|
|
|
for module_name in module_list:
|
|
|
|
try:
|
2021-10-03 16:42:16 +00:00
|
|
|
if user_bot:
|
|
|
|
import_module("pagermaid.bots." + module_name)
|
|
|
|
else:
|
|
|
|
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}")
|
2022-01-26 13:36:11 +00:00
|
|
|
|
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)
|
2022-01-26 13:36:11 +00:00
|
|
|
|
2020-02-19 15:31:39 +00:00
|
|
|
if server is not None:
|
|
|
|
import_module("pagermaid.interface")
|
2022-01-26 13:36:11 +00:00
|
|
|
|
2021-04-12 16:25:32 +00:00
|
|
|
logs.info(lang('start'))
|
2022-01-26 13:36:11 +00:00
|
|
|
|
|
|
|
if redis_status():
|
|
|
|
async def _restart_complete_report():
|
|
|
|
restart_args = redis.get("restart_edit")
|
|
|
|
if restart_args:
|
|
|
|
redis.delete("restart_edit")
|
|
|
|
restart_args = restart_args.decode("utf-8")
|
|
|
|
restart_msg, restart_chat = restart_args.split("|")
|
|
|
|
await bot.edit_message(
|
|
|
|
restart_chat, restart_msg,
|
|
|
|
lang('restart_complete')
|
|
|
|
)
|
|
|
|
|
|
|
|
bot.loop.create_task(_restart_complete_report())
|
|
|
|
|
2020-02-19 15:31:39 +00:00
|
|
|
bot.run_until_disconnected()
|
2022-01-26 13:36:11 +00:00
|
|
|
|
2020-02-19 15:31:39 +00:00
|
|
|
if server is not None:
|
2021-04-04 03:04:11 +00:00
|
|
|
try:
|
|
|
|
server.stop()
|
|
|
|
except AttributeError:
|
|
|
|
pass
|