Fixed reports ignorance
This commit is contained in:
parent
13f6286fd0
commit
e65d98deca
34
main.py
34
main.py
@ -8,9 +8,11 @@ import time
|
||||
import traceback
|
||||
import schedule
|
||||
|
||||
pid = os.getpid()
|
||||
|
||||
try:
|
||||
from pyrogram import Client, filters, idle # type: ignore
|
||||
from pyrogram.types import ChatPermissions, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton # type: ignore
|
||||
from pyrogram.types import ChatPermissions, ReplyKeyboardMarkup, InlineKeyboardMarkup, InlineKeyboardButton, BotCommand, BotCommandScopeChat # type: ignore
|
||||
except ModuleNotFoundError:
|
||||
print(f"Module pyrogram is not installed. Run 'pip3 install -r requirements.txt' and restart the program.", flush=True)
|
||||
sys.exit()
|
||||
@ -57,6 +59,7 @@ def send_content():
|
||||
candidate = configGet("queue", "locations")+os.sep+candidate_file
|
||||
else:
|
||||
logWrite(f"Could not send content due to queue folder empty with allowed extensions")
|
||||
if configGet("error", "reports"):
|
||||
app.send_message(configGet("admin", "reports"), f"Could not send content: `Queue folder is empty or contains only unsupported or already sent files.`") # type: ignore
|
||||
return
|
||||
|
||||
@ -86,15 +89,25 @@ def send_content():
|
||||
if configGet("move_sent", "posting"):
|
||||
shutil.move(candidate, configGet("sent", "locations")+os.sep+candidate_file)
|
||||
|
||||
if configGet("sent", "reports"):
|
||||
app.send_message(configGet("admin", "reports"), f"Posted `{candidate_file}`", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup([
|
||||
[InlineKeyboardButton("View in channel", url=sent.link)] # type: ignore
|
||||
])) # type: ignore
|
||||
|
||||
except Exception as exp:
|
||||
logWrite(f"Could not send content due to {exp}")
|
||||
if configGet("error", "reports"):
|
||||
app.send_message(configGet("admin", "reports"), f"Could not send content due to `{exp}`\n\nTraceback:\n```{traceback.format_exc()}```") # type: ignore
|
||||
|
||||
|
||||
@app.on_message(~ filters.scheduled & filters.command(["kill", "die", "reboot"], prefixes=["", "/"]))
|
||||
def kill(app, msg):
|
||||
|
||||
if msg.from_user.id == configGet("admin", "reports"):
|
||||
msg.reply_text(f"Shutting down bot with pid `{pid}`")
|
||||
os.system('kill -9 '+str(pid))
|
||||
|
||||
|
||||
for entry in configGet("time", "posting"):
|
||||
schedule.every().day.at(entry).do(send_content)
|
||||
|
||||
@ -111,22 +124,27 @@ def background_task():
|
||||
logWrite(f"Exception {exp} happened on task execution")
|
||||
except KeyboardInterrupt:
|
||||
logWrite('\nShutting down...')
|
||||
app.send_message(configGet("admin", "reports"), f"Shutting down with PID `{os.getpid()}`") # type: ignore
|
||||
os.system('kill -9 '+str(os.getpid()))
|
||||
app.send_message(configGet("admin", "reports"), f"Shutting down with PID `{pid}`") # type: ignore
|
||||
os.system('kill -9 '+str(pid))
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
logWrite(f'Starting with PID {os.getpid()}')
|
||||
logWrite(f'Starting with PID {pid}')
|
||||
|
||||
app.start() # type: ignore
|
||||
app.send_message(configGet("admin", "reports"), f"Starting with pid `{os.getpid()}`") # type: ignore
|
||||
app.send_message(configGet("admin", "reports"), f"Starting with pid `{pid}`") # type: ignore
|
||||
|
||||
t = Thread(target=background_task)
|
||||
t.start()
|
||||
|
||||
app.set_bot_commands([ # type: ignore
|
||||
BotCommand("reboot", "Reboot the bot"),
|
||||
],
|
||||
scope=BotCommandScopeChat(chat_id=configGet("admin", "reports")))
|
||||
|
||||
idle()
|
||||
|
||||
app.send_message(configGet("admin", "reports"), f"Shutting down with pid `{os.getpid()}`") # type: ignore
|
||||
logWrite(f'Shutting down with PID {os.getpid()}')
|
||||
app.send_message(configGet("admin", "reports"), f"Shutting down with pid `{pid}`") # type: ignore
|
||||
logWrite(f'Shutting down with PID {pid}')
|
||||
|
||||
subprocess.call(f'kill -9 {os.getpid()}', shell=True) # type: ignore
|
||||
subprocess.call(f'kill -9 {pid}', shell=True) # type: ignore
|
Reference in New Issue
Block a user