MissKatyPyro/misskaty/__main__.py
deepsource-autofix[bot] 2aa93bb4d5
style: format code with isort, Ruff Formatter and Yapf (#300)
* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in f9f107e according to the output
from isort, Ruff Formatter and Yapf.

Details: None

* refactor: autofix issues in 2 files

Resolved issues in the following files with DeepSource Autofix:
1. misskaty/plugins/download_upload.py
2. misskaty/plugins/nightmodev2.py

* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in 1bc1345 according to the output
from isort, Ruff Formatter and Yapf.

Details: https://github.com/yasirarism/MissKatyPyro/pull/300

* refactor: autofix issues in 2 files

Resolved issues in the following files with DeepSource Autofix:
1. misskaty/plugins/dev.py
2. misskaty/plugins/misc_tools.py

* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in 58d2f1a according to the output
from isort, Ruff Formatter and Yapf.

Details: https://github.com/yasirarism/MissKatyPyro/pull/300

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Yasir Aris M <git@yasirdev.my.id>
2024-07-30 11:52:58 +07:00

106 lines
3.5 KiB
Python

"""
* @author yasir <yasiramunandar@gmail.com>
* @date 2022-12-01 09:12:27
* @projectName MissKatyPyro
* Copyright @YasirPedia All rights reserved
"""
import asyncio
import importlib
import os
import pickle
import traceback
from logging import getLogger
from pyrogram import __version__, idle
from pyrogram.raw.all import layer
from database import dbname
from misskaty import (
BOT_NAME,
BOT_USERNAME,
HELPABLE,
UBOT_NAME,
app,
get_event_loop,
scheduler,
)
from misskaty.plugins import ALL_MODULES
from misskaty.plugins.web_scraper import web
from misskaty.vars import SUDO, USER_SESSION
from utils import auto_clean
LOGGER = getLogger("MissKaty")
# Run Bot
async def start_bot():
for module in ALL_MODULES:
imported_module = importlib.import_module(f"misskaty.plugins.{module}")
if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__:
imported_module.__MODULE__ = imported_module.__MODULE__
if hasattr(imported_module, "__HELP__") and imported_module.__HELP__:
HELPABLE[imported_module.__MODULE__.lower()] = imported_module
bot_modules = ""
j = 1
for i in ALL_MODULES:
if j == 4:
bot_modules += "|{:<15}|\n".format(i)
j = 0
else:
bot_modules += "|{:<15}".format(i)
j += 1
LOGGER.info("+===============================================================+")
LOGGER.info("| MissKatyPyro |")
LOGGER.info("+===============+===============+===============+===============+")
LOGGER.info(bot_modules)
LOGGER.info("+===============+===============+===============+===============+")
LOGGER.info("[INFO]: BOT STARTED AS @%s!", BOT_USERNAME)
try:
LOGGER.info("[INFO]: SENDING ONLINE STATUS")
for i in SUDO:
if USER_SESSION:
await app.send_message(
i,
f"USERBOT AND BOT STARTED with Pyrogram v{__version__}..\nUserBot: {UBOT_NAME}\nBot: {BOT_NAME}\n\nwith Pyrogram v{__version__} (Layer {layer}) started on @{BOT_USERNAME}.\n\n<code>{bot_modules}</code>",
)
else:
await app.send_message(
i,
f"BOT STARTED with Pyrogram v{__version__} as {BOT_NAME}\n\nwith Pyrogram v{__version__} (Layer {layer}) started on @{BOT_USERNAME}.\n\n<code>{bot_modules}</code>",
)
except Exception as e:
LOGGER.error(str(e))
scheduler.start()
if "web" not in await dbname.list_collection_names():
webdb = dbname["web"]
for key, value in web.items():
await webdb.insert_one({key: value})
if os.path.exists("restart.pickle"):
with open("restart.pickle", "rb") as status:
chat_id, message_id = pickle.load(status)
os.remove("restart.pickle")
await app.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text="<b>Bot restarted successfully!</b>",
)
asyncio.create_task(auto_clean())
await idle()
if __name__ == "__main__":
try:
get_event_loop().run_until_complete(start_bot())
app.loop.run_forever()
except KeyboardInterrupt:
pass
except Exception:
err = traceback.format_exc()
LOGGER.info(err)
finally:
app.loop.stop()
LOGGER.info(
"------------------------ Stopped Services ------------------------"
)