Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #1

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions IDNCoderX/helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ async def del_user(user_id):
async def is_user_in_db(user_id):
u_id = int(user_id)
is_exist = await user_db.find_one({"user_id": u_id})
if is_exist:
return True
else:
return False
return bool(is_exist)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_user_in_db refactored with the following changes:


async def count_users():
users = await user_db.count_documents({})
Expand Down Expand Up @@ -66,10 +63,7 @@ async def del_banned_user(user_id):
async def is_user_in_bdb(user_id):
u_id = int(user_id)
is_exist = await b_user_db.find_one({"banned_user_id": u_id})
if is_exist:
return True
else:
return False
return bool(is_exist)
Comment on lines -69 to +66
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_user_in_bdb refactored with the following changes:


async def count_banned_users():
users = await b_user_db.count_documents({})
Expand Down
6 changes: 4 additions & 2 deletions IDNCoderX/helpers/unzip_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ async def progress_for_pyrogram(current, total, ud_type, message, start):

progress = "[{0}{1}] \n**Process**: {2}%\n".format(
''.join(["█" for i in range(math.floor(percentage / 5))]),
''.join(["░" for i in range(20 - math.floor(percentage / 5))]),
round(percentage, 2))
''.join(["░" for _ in range(20 - math.floor(percentage / 5))]),
round(percentage, 2),
)

Comment on lines -27 to +30
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function progress_for_pyrogram refactored with the following changes:


tmp = progress + "{0} of {1}\n**Speed:** {2}/s\n**ETA:** {3}\n".format(
humanbytes(current),
Expand Down
31 changes: 15 additions & 16 deletions IDNCoderX/modules/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
async def unzipper_cb(unzip_bot: Client, query: CallbackQuery):
if query.data == "megoinhome":
await query.edit_message_text(text=Messages.START_TEXT.format(query.from_user.mention), reply_markup=Buttons.START_BUTTON)

elif query.data == "helpcallback":
await query.edit_message_text(text=Messages.HELP_TXT, reply_markup=Buttons.ME_GOIN_HOME)

elif query.data == "aboutcallback":
await query.edit_message_text(text=Messages.ABOUT_TXT, reply_markup=Buttons.ME_GOIN_HOME, disable_web_page_preview=True)

Comment on lines -26 to +32
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function unzipper_cb refactored with the following changes:

elif query.data.startswith("extract_file"):
user_id = query.from_user.id
download_path = f"{Config.DOWNLOAD_LOCATION}/{user_id}"
Expand Down Expand Up @@ -72,7 +72,7 @@ async def unzipper_cb(unzip_bot: Client, query: CallbackQuery):
else:
await query.message.edit("**Sorry I can't download that URL 🥺!**")
return

elif splitted_data[1] == "tg_file":
if r_message.document is None:
return await query.message.edit("`Give me an Archive to extract lamo!`")
Expand All @@ -89,30 +89,29 @@ async def unzipper_cb(unzip_bot: Client, query: CallbackQuery):
e_time = time()
else:
await query.answer("Can't Find Details! Please contact support group!", show_alert=True)

try:
await query.message.edit(Messages.AFTER_OK_DL_TXT.format(TimeFormatter(round(e_time-s_time) * 1000)))
except:
await query.answer("Successfully Downloaded! Extracting Now 😊!", show_alert=True)



if splitted_data[2] == "with_pass":
password = await unzip_bot.ask(chat_id=query.message.chat.id ,text="**Please send me the password 🔑:**")
ext_s_time = time()
extractor = await extr_files(path=ext_files_dir, archive_path=archive, password=password.text)
ext_e_time = time()
else:
ext_s_time = time()
extractor = await extr_files(path=ext_files_dir, archive_path=archive)
ext_e_time = time()
ext_e_time = time()
# Checks if there is an error happend while extracting the archive
if any(err in extractor for err in ERROR_MSGS):
return await query.message.edit(Messages.EXT_FAILED_TXT)

await query.message.edit(Messages.EXT_OK_TXT.format(TimeFormatter(round(ext_e_time-ext_s_time) * 1000)))


# Upload extracted files
paths = get_files(path=ext_files_dir)
i_e_buttons = await make_keyboard(paths=paths, user_id=user_id, chat_id=query.message.chat.id)
Expand All @@ -134,7 +133,7 @@ async def unzipper_cb(unzip_bot: Client, query: CallbackQuery):
if os.path.isdir(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}"):
shutil.rmtree(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}")
return await query.message.edit("`I've already sent you those files 😐, Don't ask me to resend 😒!`")

await query.answer("Send that file to you. Please wait!")
await send_file(unzip_bot=unzip_bot,
c_id=spl_data[2],
Expand All @@ -155,8 +154,8 @@ async def unzipper_cb(unzip_bot: Client, query: CallbackQuery):
return await query.message.edit("`I've already sent you those files 😐, Don't ask me to resend 😒!`")
i_e_buttons = await make_keyboard(paths=rpaths, user_id=query.from_user.id, chat_id=query.message.chat.id)
await query.message.edit("Select Files to Upload!", reply_markup=i_e_buttons)


elif query.data.startswith("ext_a"):
spl_data = query.data.split("|")
file_path = f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}/extracted"
Expand All @@ -180,13 +179,13 @@ async def unzipper_cb(unzip_bot: Client, query: CallbackQuery):
shutil.rmtree(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}")
except Exception as e:
await query.message.edit(Messages.ERROR_TXT.format(e))

elif query.data == "cancel_dis":
try:
shutil.rmtree(f"{Config.DOWNLOAD_LOCATION}/{query.from_user.id}")
await query.message.edit(Messages.CANCELLED_TXT.format("Process Cancelled"))
except:
return await query.answer("There is nothing to remove lmao!", show_alert=True)

elif query.data == "nobully":
await query.message.edit("**Ok Ok! I won't delete those files 😂!**")
23 changes: 7 additions & 16 deletions IDNCoderX/modules/ext_script/ext_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
## Run commands in shell
async def __run_cmds_unzipper(command):
ext_cmd = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
ext_out = ext_cmd.stdout.read()[:-1].decode("utf-8")
return ext_out
return ext_cmd.stdout.read()[:-1].decode("utf-8")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function __run_cmds_unzipper refactored with the following changes:


## Extract with 7z
async def _extract_with_7z_helper(path, archive_path, password=None):
Expand All @@ -29,13 +28,10 @@ async def _extract_with_zstd(path, archive_path):
# Main function to extract files
async def extr_files(path, archive_path, password=None):
file_path = os.path.splitext(archive_path)[1]
if file_path == ".zst":
os.mkdir(path)
ex = await _extract_with_zstd(path, archive_path)
return ex
else:
ex = await _extract_with_7z_helper(path, archive_path, password)
return ex
if file_path != ".zst":
return await _extract_with_7z_helper(path, archive_path, password)
os.mkdir(path)
return await _extract_with_zstd(path, archive_path)
Comment on lines -32 to +34
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function extr_files refactored with the following changes:


# Get files in directory as a list
def get_files(path):
Expand All @@ -47,20 +43,15 @@ def get_files(path):

# Make keyboard
async def make_keyboard(paths, user_id, chat_id):
num = 0
i_kbd = InlineKeyboard(row_width=1)
data = []
data.append(
InlineKeyboardButton(f"Upload All ♻️", f"ext_a|{user_id}|{chat_id}")
)
data = [InlineKeyboardButton('Upload All ♻️', f"ext_a|{user_id}|{chat_id}")]
data.append(
InlineKeyboardButton("Cancel ❌", "cancel_dis")
)
for file in paths:
for num, file in enumerate(paths):
data.append(
InlineKeyboardButton(f"{num} - {os.path.basename(file)}", f"ext_f|{user_id}|{chat_id}|{num}")
)
num += 1
Comment on lines -50 to -63
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function make_keyboard refactored with the following changes:

i_kbd.add(*data)
return i_kbd

Expand Down