-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
async def count_users(): | ||
users = await user_db.count_documents({}) | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
async def count_banned_users(): | ||
users = await b_user_db.count_documents({}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
tmp = progress + "{0} of {1}\n**Speed:** {2}/s\n**ETA:** {3}\n".format( | ||
humanbytes(current), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
elif query.data.startswith("extract_file"): | ||
user_id = query.from_user.id | ||
download_path = f"{Config.DOWNLOAD_LOCATION}/{user_id}" | ||
|
@@ -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!`") | ||
|
@@ -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) | ||
|
@@ -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], | ||
|
@@ -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" | ||
|
@@ -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 😂!**") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
## Extract with 7z | ||
async def _extract_with_7z_helper(path, archive_path, password=None): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
# Get files in directory as a list | ||
def get_files(path): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
i_kbd.add(*data) | ||
return i_kbd | ||
|
||
|
There was a problem hiding this comment.
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:boolean-if-exp-identity
)assign-if-exp
)