62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
|
import asyncio
|
||
|
from os import getpid, listdir
|
||
|
from modules.utils import *
|
||
|
|
||
|
from pyrogram.client import Client
|
||
|
from pyrogram import filters
|
||
|
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, BotCommand, BotCommandScopeChat
|
||
|
from pyrogram import idle # type: ignore
|
||
|
from pyrogram.errors.exceptions import bad_request_400
|
||
|
|
||
|
pid = getpid()
|
||
|
|
||
|
app = Client("holochecker", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
|
||
|
|
||
|
@app.on_message(~ filters.scheduled & filters.command(["kill", "die", "reboot"], prefixes=["", "/"]))
|
||
|
async def cmd_kill(app, msg):
|
||
|
|
||
|
if (msg.from_user.id == configGet("owner")) or (msg.from_user.id in configGet("admins")):
|
||
|
logWrite(f"Shutting down bot with pid {pid}")
|
||
|
await msg.reply_text(f"Вимкнення бота з підом `{pid}`")
|
||
|
killProc(pid)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
|
||
|
logWrite(f"Starting up with pid {pid}")
|
||
|
|
||
|
# Yes, it should be in some kind of async main() function but I don't give a shit.
|
||
|
# I did compare performance and it's much more useful this way. Change my mind.
|
||
|
app.start() # type: ignore
|
||
|
|
||
|
app.send_message(configGet("owner"), f"Starting up with pid `{pid}`") # type: ignore
|
||
|
|
||
|
# Registering user commands for fallback locale
|
||
|
commands_list = []
|
||
|
for command in configGet("commands"):
|
||
|
commands_list.append(BotCommand(command, configGet("commands")[command]))
|
||
|
app.set_bot_commands(commands_list) # type: ignore
|
||
|
|
||
|
# Registering admin commands
|
||
|
commands_admin_list = []
|
||
|
for command in configGet("commands"):
|
||
|
commands_admin_list.append(BotCommand(command, configGet("commands")[command]))
|
||
|
|
||
|
for command in configGet("commands_admin"):
|
||
|
commands_admin_list.append(BotCommand(command, configGet("commands_admin")[command]))
|
||
|
|
||
|
for admin in configGet("admins"):
|
||
|
try:
|
||
|
app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=admin)) # type: ignore
|
||
|
except bad_request_400.PeerIdInvalid:
|
||
|
pass
|
||
|
|
||
|
app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=configGet("owner"))) # type: ignore
|
||
|
|
||
|
idle()
|
||
|
|
||
|
app.send_message(configGet("owner"), f"Shutting with pid `{pid}`") # type: ignore
|
||
|
|
||
|
app.stop() # type: ignore
|
||
|
|
||
|
killProc(pid)
|