Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
- Fixed bot crashing if FSUB_CHAT_ID env var is left empty
- Added seprate warning if AUTO_DELETE_UPLOAD_MESSAGE_DURATION env var is not added
- Improve logging
- Many misc improvements
  • Loading branch information
arshsisodiya committed May 2, 2022
1 parent 16a2792 commit 0f4957f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
21 changes: 12 additions & 9 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_client():
for chats in achats:
MIRROR_LOGS.add(int(chats))
except:
logging.warning('Logs Chat Details not provided!')
logging.warning('Mirror Logs Chat Details not provided! Proceeding Without it')
pass

if ospath.exists("link_logs.txt"):
Expand Down Expand Up @@ -212,7 +212,7 @@ def get_client():
for chats in achats:
LEECH_LOG.add(int(chats))
except:
logging.warning('Leech Log Channel ID not Provided!')
logging.warning('Leech Log Channel ID not Provided! You will not be able to use leech features')
pass

try:
Expand All @@ -221,7 +221,6 @@ def get_client():
for chats in achats:
LEECH_LOG_ALT.add(int(chats))
except:
logging.warning('Leech Log alt Channel ID not Provided!')
pass
try:
BOT_TOKEN = getConfig('BOT_TOKEN')
Expand All @@ -232,13 +231,16 @@ def get_client():
DOWNLOAD_STATUS_UPDATE_INTERVAL = int(getConfig('DOWNLOAD_STATUS_UPDATE_INTERVAL'))
OWNER_ID = int(getConfig('OWNER_ID'))
AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION'))
AUTO_DELETE_UPLOAD_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_UPLOAD_MESSAGE_DURATION'))
TELEGRAM_API = getConfig('TELEGRAM_API')
TELEGRAM_HASH = getConfig('TELEGRAM_HASH')
except KeyError as e:
LOGGER.error("One or more env variables missing! Exiting now")
LOGGER.error("One or more Required env variables missing! Exiting now")
exit(1)
try:
AUTO_DELETE_UPLOAD_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_UPLOAD_MESSAGE_DURATION'))
except KeyError as e:
LOGGER.error("AUTO_DELETE_UPLOAD_MESSAGE_DURATION var missing! Exiting now")
exit(1)

LOGGER.info("Generating BOT_STRING_SESSION")
app = Client('pyrogram', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN, no_updates=True)

Expand Down Expand Up @@ -586,9 +588,10 @@ def aria2c_init():

try:
FSUB_CHANNEL_ID = int(getConfig('FSUB_CHANNEL_ID'))
except KeyError:
FSUB_CHANNEL_ID = ""

except Exception as error:
LOGGER.warning(f"FSUB_CHANNEL_ID env is empty:\n{error}")
FSUB_CHANNEL_ID = "-1001576780814"
pass
try:
CHANNEL_USERNAME: str = getConfig('CHANNEL_USERNAME').replace("@", "")
if len(CHANNEL_USERNAME) == 0:
Expand Down
32 changes: 16 additions & 16 deletions bot/helper/mirror_utils/upload_utils/pyrogramEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def __upload_file(self, up_path, file_, dirpath):
if BOT_PM:
try:
app.send_video(chat_id=self.__user_id, video=self.__sent_msg.video.file_id, caption=cap_mono)
except Exception as f:
LOGGER.error(f"Failed To Send Video in PM:\n{f}")
except Exception as err:
LOGGER.error(f"Failed To Send Video in PM:\n{err}")
if LEECH_LOG_ALT:
try:
for i in self.__leech_log_alt:
Expand All @@ -143,13 +143,13 @@ def __upload_file(self, up_path, file_, dirpath):
if BOT_PM:
try:
app.send_audio(chat_id=self.__user_id, audio=self.__sent_msg.audio.file_id, caption=cap_mono)
except Exception as f:
LOGGER.error(f"Failed To Send Audio in PM:\n{f}")
except Exception as err:
LOGGER.error(f"Failed To Send Audio in PM:\n{err}")
if LEECH_LOG_ALT:
try:
for i in self.__leech_log_alt:
app.send_audio(chat_id=i, audio=self.__sent_msg.audio.file_id, caption=cap_mono)
except Exception as f:
except Exception as err:
LOGGER.error(f"Failed to send Audio in Alt Leech Log:\n{err}")

elif file_.upper().endswith(IMAGE_SUFFIXES):
Expand All @@ -166,18 +166,18 @@ def __upload_file(self, up_path, file_, dirpath):
try:
app.send_photo(chat_id=self.__user_id, photo=self.__sent_msg.photo.file_id,
caption=cap_mono)
except Exception as f:
LOGGER.error(f"Failed To Send Image in PM:\n{f}")
except Exception as err:
LOGGER.error(f"Failed To Send Image in PM:\n{err}")
if LEECH_LOG_ALT:
try:
app.send_photo(chat_id=i, photo=self.__sent_msg.photo.file_id,
caption=cap_mono)
except Exception as f:
LOGGER.error(f"Failed To Send Image in Alt Leech Log:\n{f}")
except Exception:
LOGGER.warning("Image Leech is Blocked by Owner")
except Exception as err:
LOGGER.error(f"Failed To Send Image in Alt Leech Log:\n{err}")
except Exception as err:
LOGGER.warning(f"Image Leech is Blocked by Owner:\n{err}")
else:
LOGGER.warning("Image Leech is Blocked by Owner")
LOGGER.warning(f"Image Leech is Blocked by Owner")
pass

elif file_.upper().endswith(TEXT_SUFFIXES):
Expand All @@ -204,14 +204,14 @@ def __upload_file(self, up_path, file_, dirpath):
if BOT_PM:
try:
app.send_document(chat_id=self.__user_id, document=self.__sent_msg.document.file_id, caption=cap_mono)
except Exception as f:
LOGGER.error(f"Failed To Send Document in PM:\n{f}")
except Exception as err:
LOGGER.error(f"Failed To Send Document in PM:\n{err}")
if LEECH_LOG_ALT:
try:
for i in self.__leech_log_alt:
app.send_document(chat_id=i, document=self.__sent_msg.document.file_id, caption=cap_mono)
except Exception as f:
LOGGER.error(f"Failed To Send Document in Alt Leech Log:\n{f}")
except Exception as err:
LOGGER.error(f"Failed To Send Document in Alt Leech Log:\n{err}")
except FloodWait as f:
LOGGER.warning(str(f))
sleep(f.x)
Expand Down
3 changes: 2 additions & 1 deletion bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def cloneNode(update, context):
message = sendMarkup(str(f"️<b>Dear {uname}, You haven't join our Updates Channel yet.</b>\n\nKindly Join @{CHANNEL_USERNAME} To Use Bots. "), bot, update, reply_markup)
Thread(target=auto_delete_upload_message, args=(bot, update.message, message)).start()
return
except:
except Exception as error:
LOGGER.warning(error)
pass
if BOT_PM:
try:
Expand Down
15 changes: 10 additions & 5 deletions bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ def onDownloadError(self, error):
if reply_to is not None:
try:
reply_to.delete()
except:
except Exception as error:
LOGGER.warning(error)
pass
error = error.replace('<', ' ').replace('>', ' ')
with download_dict_lock:
Expand Down Expand Up @@ -246,7 +247,8 @@ def onUploadComplete(self, link: str, size, files, folders, typ, name: str):
if reply_to is not None:
try:
reply_to.delete()
except:
except Exception as error:
LOGGER.warning(error)
pass
auto_delete_message = int(AUTO_DELETE_UPLOAD_MESSAGE_DURATION / 60)
if self.message.chat.type == 'private':
Expand Down Expand Up @@ -375,7 +377,8 @@ def onUploadComplete(self, link: str, size, files, folders, typ, name: str):
if self.isZip:
try:
osremove(f'{DOWNLOAD_DIR}{self.uid}/{name}')
except:
except Exception as error:
LOGGER.warning(error)
pass
msg = sendMarkup(msg + uploader + pmwarn_mirror + warnmsg, self.bot, self.update, InlineKeyboardMarkup(buttons.build_menu(2)))
Thread(target=auto_delete_upload_message, args=(bot, self.message, msg)).start()
Expand All @@ -400,7 +403,8 @@ def onUploadError(self, error):
if reply_to is not None:
try:
reply_to.delete()
except:
except Exception as error:
LOGGER.warning(error)
pass
e_str = error.replace('<', '').replace('>', '')
with download_dict_lock:
Expand Down Expand Up @@ -433,7 +437,8 @@ def _mirror(bot, update, isZip=False, extract=False, isQbit=False, isLeech=False
bot, update, reply_markup)
Thread(target=auto_delete_upload_message, args=(bot, update.message, message)).start()
return
except:
except Exception as error:
LOGGER.warning(error)
pass
if isLeech and length_of_leechlog == 0:
try:
Expand Down

0 comments on commit 0f4957f

Please sign in to comment.