from os import getpid, makedirs from time import time from modules.utils import * from modules.inline import * from app import app from pyrogram import idle pid = getpid() makedirs(f'{configGet("cache", "locations")}{sep}avatars', exist_ok=True) # Importing from modules.commands.application import * from modules.commands.applications import * from modules.commands.cancel import * from modules.commands.identify import * from modules.commands.label import * from modules.commands.message import * from modules.commands.nearby import * from modules.commands.reapply import * from modules.commands.reboot import * from modules.commands.resetcommands import * from modules.commands.rules import * from modules.commands.spoiler import * from modules.commands.sponsorship import * 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.sid import * from modules.callbacks.sponsorship import * 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 * from modules.handlers.welcome import * from modules.handlers.everything import * from modules.scheduled import * 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, almost no difference and it's much more useful this way. Change my mind. app.start() try: if path.exists(path.join(configGet("cache", "locations"), "shutdown_time")): downtime = relativedelta(datetime.now(), datetime.fromtimestamp(jsonLoad(path.join(configGet("cache", "locations"), "shutdown_time"))["timestamp"])) 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)) except bad_request_400.PeerIdInvalid: logWrite(f"Could not send startup message to bot owner. Perhaps user has not started the bot yet.") scheduler.start() idle() try: app.send_message(configGet("owner"), locale("shutdown", "message").format(pid)) except bad_request_400.PeerIdInvalid: logWrite(f"Could not send shutdown message to bot owner. Perhaps user has not started the bot yet.") app.stop() makedirs(configGet("cache", "locations"), exist_ok=True) jsonSave({"timestamp": time()}, path.join(configGet("cache", "locations"), "shutdown_time")) killProc(pid)