|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from os import sep, remove, getpid, listdir
|
|
|
|
|
from random import choice
|
|
|
|
|
from shutil import move
|
|
|
|
|
from sys import argv, exit
|
|
|
|
|
from threading import Thread
|
|
|
|
|
from sys import exit
|
|
|
|
|
from time import time
|
|
|
|
|
from traceback import format_exc
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
|
|
|
|
|
|
|
|
from modules.logging import logWrite
|
|
|
|
|
from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale
|
|
|
|
@ -86,6 +87,8 @@ except ModuleNotFoundError:
|
|
|
|
|
pid = getpid()
|
|
|
|
|
app = Client("duptsiaposter", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
|
|
|
|
|
|
|
|
|
|
if configGet("post", "mode"):
|
|
|
|
|
scheduler = AsyncIOScheduler()
|
|
|
|
|
|
|
|
|
|
# Work in progress
|
|
|
|
|
# def check_forwards(app):
|
|
|
|
@ -413,23 +416,25 @@ def callback_query_unblock(app, clb): # type: ignore
|
|
|
|
|
if configGet("post", "mode"):
|
|
|
|
|
|
|
|
|
|
for entry in configGet("time", "posting"):
|
|
|
|
|
schedule.every().day.at(entry).do(send_content)
|
|
|
|
|
|
|
|
|
|
def background_task():
|
|
|
|
|
try:
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
schedule.run_pending()
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
except Exception as exp:
|
|
|
|
|
logWrite(locale("exception_occured", "console", locale=configGet("locale")).format(exp))
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
logWrite(locale("keyboard_interrupt", "console", locale=configGet("locale")))
|
|
|
|
|
if configGet("shutdown", "reports"):
|
|
|
|
|
app.send_message(configGet("admin"), locale("shutdown", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
|
|
|
|
|
killProc(pid)
|
|
|
|
|
dt_obj = datetime.strptime(entry, "%H:%M")
|
|
|
|
|
scheduler.add_job(send_content, "cron", hour=dt_obj.hour, minute=dt_obj.minute)
|
|
|
|
|
# schedule.every().day.at(entry).do(send_content)
|
|
|
|
|
|
|
|
|
|
# def background_task():
|
|
|
|
|
# try:
|
|
|
|
|
# while True:
|
|
|
|
|
# try:
|
|
|
|
|
# schedule.run_pending()
|
|
|
|
|
# time.sleep(1)
|
|
|
|
|
# except:
|
|
|
|
|
# pass
|
|
|
|
|
# except Exception as exp:
|
|
|
|
|
# logWrite(locale("exception_occured", "console", locale=configGet("locale")).format(exp))
|
|
|
|
|
# except KeyboardInterrupt:
|
|
|
|
|
# logWrite(locale("keyboard_interrupt", "console", locale=configGet("locale")))
|
|
|
|
|
# if configGet("shutdown", "reports"):
|
|
|
|
|
# app.send_message(configGet("admin"), locale("shutdown", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
|
|
|
|
|
# killProc(pid)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
@ -439,9 +444,9 @@ if __name__ == "__main__":
|
|
|
|
|
if configGet("startup", "reports"):
|
|
|
|
|
app.send_message(configGet("admin"), locale("startup", "message", locale=configGet("locale")).format(str(pid))) # type: ignore
|
|
|
|
|
|
|
|
|
|
if configGet("post", "mode"):
|
|
|
|
|
t = Thread(target=background_task)
|
|
|
|
|
t.start()
|
|
|
|
|
# if configGet("post", "mode"):
|
|
|
|
|
# t = Thread(target=background_task)
|
|
|
|
|
# t.start()
|
|
|
|
|
|
|
|
|
|
if configGet("submit", "mode"):
|
|
|
|
|
# Registering user commands
|
|
|
|
|