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/holochecker.py

85 lines
3.2 KiB
Python
Raw Normal View History

from os import getpid, makedirs
from time import time
2022-10-17 00:30:07 +03:00
from modules.utils import *
2022-10-26 15:54:55 +03:00
from modules.inline import *
from app import app
2022-10-17 00:30:07 +03:00
from pyrogram import idle
2022-10-17 00:30:07 +03:00
2022-10-21 15:00:03 +03:00
pid = getpid()
2022-10-17 00:30:07 +03:00
makedirs(f'{configGet("cache", "locations")}{sep}avatars', exist_ok=True)
2022-10-21 15:00:03 +03:00
2022-12-05 19:49:51 +02:00
# Importing
from modules.commands.application import *
from modules.commands.applications import *
2022-12-23 02:40:23 +02:00
from modules.commands.cancel import *
2023-01-03 15:30:16 +02:00
from modules.commands.identify import *
2023-01-23 15:39:38 +02:00
from modules.commands.issue import *
2022-12-10 18:29:06 +02:00
from modules.commands.label import *
2022-12-05 19:49:51 +02:00
from modules.commands.message import *
2022-12-15 16:12:41 +02:00
from modules.commands.nearby import *
2022-12-05 19:49:51 +02:00
from modules.commands.reapply import *
from modules.commands.reboot import *
2023-01-05 13:41:55 +02:00
from modules.commands.resetcommands import *
2022-12-05 19:49:51 +02:00
from modules.commands.rules import *
2023-01-04 20:58:54 +02:00
from modules.commands.spoiler import *
2022-12-10 11:42:56 +02:00
from modules.commands.sponsorship import *
2022-12-05 19:49:51 +02:00
from modules.commands.start import *
from modules.commands.warn import *
from modules.commands.warnings import *
from modules.callbacks.nothing import *
from modules.callbacks.reapply import *
from modules.callbacks.rules import *
from modules.callbacks.spoiler import *
2022-12-21 13:51:39 +02:00
from modules.callbacks.sponsorship import *
2022-12-05 19:49:51 +02:00
from modules.callbacks.sub import *
from modules.callbacks.sus import *
from modules.handlers.confirmation import *
from modules.handlers.contact import *
from modules.handlers.group_join import *
from modules.handlers.voice import *
2022-12-05 19:49:51 +02:00
from modules.handlers.welcome import *
from modules.handlers.everything import *
2022-10-23 17:22:38 +03:00
2022-12-10 16:51:37 +02:00
from modules.scheduled import *
2022-10-17 00:30:07 +03:00
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.
2022-10-20 13:24:32 +03:00
# I did compare performance, almost no difference and it's much more useful this way. Change my mind.
app.start()
2022-10-17 00:30:07 +03:00
2022-12-10 16:51:37 +02:00
try:
2023-01-05 14:08:08 +02:00
if path.exists(path.join(configGet("cache", "locations"), "shutdown_time")):
2023-01-05 14:16:11 +02:00
downtime = relativedelta(datetime.now(), datetime.fromtimestamp(jsonLoad(path.join(configGet("cache", "locations"), "shutdown_time"))["timestamp"]))
2023-01-05 14:08:08 +02:00
if downtime.days >= 1:
app.send_message(configGet("owner"), locale("startup_downtime_days", "message").format(pid, downtime.days))
elif downtime.hours >= 1:
app.send_message(configGet("owner"), locale("startup_downtime_hours", "message").format(pid, downtime.hours))
else:
app.send_message(configGet("owner"), locale("startup_downtime_minutes", "message").format(pid, downtime.minutes))
else:
app.send_message(configGet("owner"), locale("startup", "message").format(pid))
2022-12-10 16:51:37 +02:00
except bad_request_400.PeerIdInvalid:
logWrite(f"Could not send startup message to bot owner. Perhaps user has not started the bot yet.")
2022-10-17 00:30:07 +03:00
2022-12-10 16:51:37 +02:00
scheduler.start()
2022-10-17 00:30:07 +03:00
idle()
2022-12-10 16:51:37 +02:00
try:
2023-01-05 14:08:08 +02:00
app.send_message(configGet("owner"), locale("shutdown", "message").format(pid))
2022-12-10 16:51:37 +02:00
except bad_request_400.PeerIdInvalid:
logWrite(f"Could not send shutdown message to bot owner. Perhaps user has not started the bot yet.")
2022-10-17 00:30:07 +03:00
app.stop()
makedirs(configGet("cache", "locations"), exist_ok=True)
jsonSave({"timestamp": time()}, path.join(configGet("cache", "locations"), "shutdown_time"))
2022-10-17 00:30:07 +03:00
killProc(pid)