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 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()