From b5058c00e1ec8d350002c959b048688f96e8c65e Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Sat, 10 Dec 2022 15:51:37 +0100 Subject: [PATCH] Optimized imports, removed scheduler --- main.py | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/main.py b/main.py index a2c161f..b97befd 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,6 @@ -from threading import Thread -from time import time -from os import getpid, path -from modules.birthdays import check_birthdays +from os import getpid from modules.utils import * from modules.inline import * -from schedule import run_pending, every from app import app from modules.commands_register import commands_register @@ -38,6 +34,8 @@ from modules.handlers.group_join 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}") @@ -46,33 +44,41 @@ if __name__ == "__main__": # I did compare performance, almost no difference and it's much more useful this way. Change my mind. app.start() - if configGet("birthdays_notify"): + # if configGet("birthdays_notify"): - every().day.at(configGet("birthdays_time")).do(check_birthdays, app) + # every().day.at(configGet("birthdays_time")).do(check_birthdays, app) - # Background tasks checker - def background_task(): - try: - while True: - try: - run_pending() - #print('Checked') - time.sleep(1) - except: - pass - except KeyboardInterrupt: - print('\nShutting down') - killProc(pid) - t = Thread(target=background_task) - t.start() + # # Background tasks checker + # def background_task(): + # try: + # while True: + # try: + # run_pending() + # #print('Checked') + # time.sleep(1) + # except: + # pass + # except KeyboardInterrupt: + # print('\nShutting down') + # killProc(pid) + # t = Thread(target=background_task) + # t.start() - app.send_message(configGet("owner"), f"Starting up with pid `{pid}`") + try: + app.send_message(configGet("owner"), f"Starting up with pid `{pid}`") + except bad_request_400.PeerIdInvalid: + logWrite(f"Could not send startup message to bot owner. Perhaps user has not started the bot yet.") commands_register(app) + scheduler.start() + idle() - app.send_message(configGet("owner"), f"Shutting with pid `{pid}`") + try: + app.send_message(configGet("owner"), f"Shutting with pid `{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()