Optimized imports, removed scheduler

This commit is contained in:
Profitroll 2022-12-10 15:51:37 +01:00
parent dc92a3d82a
commit b5058c00e1
1 changed files with 30 additions and 24 deletions

54
main.py
View File

@ -1,10 +1,6 @@
from threading import Thread from os import getpid
from time import time
from os import getpid, path
from modules.birthdays import check_birthdays
from modules.utils import * from modules.utils import *
from modules.inline import * from modules.inline import *
from schedule import run_pending, every
from app import app from app import app
from modules.commands_register import commands_register 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.welcome import *
from modules.handlers.everything import * from modules.handlers.everything import *
from modules.scheduled import *
if __name__ == "__main__": if __name__ == "__main__":
logWrite(f"Starting up with pid {pid}") 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. # I did compare performance, almost no difference and it's much more useful this way. Change my mind.
app.start() 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 # # Background tasks checker
def background_task(): # def background_task():
try: # try:
while True: # while True:
try: # try:
run_pending() # run_pending()
#print('Checked') # #print('Checked')
time.sleep(1) # time.sleep(1)
except: # except:
pass # pass
except KeyboardInterrupt: # except KeyboardInterrupt:
print('\nShutting down') # print('\nShutting down')
killProc(pid) # killProc(pid)
t = Thread(target=background_task) # t = Thread(target=background_task)
t.start() # 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) commands_register(app)
scheduler.start()
idle() 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() app.stop()