This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/commands/reboot.py

35 lines
1016 B
Python
Raw Normal View History

2022-12-27 19:46:17 +02:00
from app import app
2023-01-05 14:08:08 +02:00
from os import getpid, makedirs, path
2022-12-11 20:52:02 +02:00
from sys import exit
2023-01-05 14:08:08 +02:00
from time import time
2022-12-05 19:49:51 +02:00
from pyrogram import filters
2022-12-27 14:36:54 +02:00
from pyrogram.types import Message
from pyrogram.client import Client
2023-01-05 14:08:08 +02:00
from modules.utils import configGet, jsonSave, locale, logWrite, should_quote
2022-12-11 20:52:02 +02:00
from modules.scheduled import scheduler
2022-12-27 19:46:17 +02:00
from modules import custom_filters
2022-12-05 19:49:51 +02:00
pid = getpid()
2023-03-09 17:25:06 +02:00
@app.on_message(
custom_filters.enabled_general
& ~filters.scheduled
& filters.private
& filters.command(["kill", "die", "reboot"], prefixes=["/"])
& custom_filters.admin
)
2022-12-27 14:36:54 +02:00
async def cmd_kill(app: Client, msg: Message):
2022-12-27 19:46:17 +02:00
logWrite(f"Shutting down bot with pid {pid}")
2023-03-09 17:25:06 +02:00
await msg.reply_text(
locale("shutdown", "message", locale=msg.from_user).format(pid),
quote=should_quote(msg),
)
2022-12-27 19:46:17 +02:00
scheduler.shutdown()
2023-01-05 14:08:08 +02:00
makedirs(configGet("cache", "locations"), exist_ok=True)
2023-03-09 17:25:06 +02:00
jsonSave(
{"timestamp": time()},
path.join(configGet("cache", "locations"), "shutdown_time"),
)
2022-12-27 19:46:17 +02:00
exit()