Fixed reports ignorance

This commit is contained in:
Profitroll 2022-08-09 10:01:02 +02:00
parent 13f6286fd0
commit e65d98deca
1 changed files with 31 additions and 13 deletions

44
main.py
View File

@ -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,7 +59,8 @@ 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")
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
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
if ext_type == "photo": # type: ignore
@ -86,13 +89,23 @@ def send_content():
if configGet("move_sent", "posting"):
shutil.move(candidate, configGet("sent", "locations")+os.sep+candidate_file)
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
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}")
app.send_message(configGet("admin", "reports"), f"Could not send content due to `{exp}`\n\nTraceback:\n```{traceback.format_exc()}```") # type: ignore
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"):
@ -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