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 master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented May 12, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from YaMraaJ-debug May 12, 2022 18:59
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

aa = glob.glob('%s/*.json' % acc_dir)
aa = glob.glob(f'{acc_dir}/*.json')
Copy link
Author

Choose a reason for hiding this comment

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

Lines 60-60 refactored with the following changes:

Comment on lines -29 to +40
batch.add(service.projects().serviceAccounts().create(name='projects/' + project, body={'accountId': aid,
'serviceAccount': {
'displayName': aid}}))
batch.add(
service.projects()
.serviceAccounts()
.create(
name=f'projects/{project}',
body={
'accountId': aid,
'serviceAccount': {'displayName': aid},
},
)
)

Copy link
Author

Choose a reason for hiding this comment

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

Function _create_accounts refactored with the following changes:

Comment on lines -37 to +46
print('Creating accounts in %s' % project)
print(f'Creating accounts in {project}')
Copy link
Author

Choose a reason for hiding this comment

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

Function _create_remaining_accounts refactored with the following changes:

Comment on lines -61 to +70
print(str(exception))
print(exception)
Copy link
Author

Choose a reason for hiding this comment

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

Function _def_batch_resp refactored with the following changes:

Comment on lines -68 to +77
print(str(exception))
print(exception)
Copy link
Author

Choose a reason for hiding this comment

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

Function _pc_resp refactored with the following changes:

Comment on lines -309 to +301
if MEGAREST is True:
if MEGAREST:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 309-638 refactored with the following changes:

Comment on lines -78 to +84
Thread(target=auto_delete_message, args=(context.bot, update.message, message)).start()
return
else:
message = sendMarkup(
f'Dear {uname},\n\nIf You Want To Use Me, You Have To Join @{CHANNEL_USERNAME}\n\n',
context.bot, update, reply_markup)
Thread(target=auto_delete_message, args=(context.bot, update.message, message)).start()
return

Thread(target=auto_delete_message, args=(context.bot, update.message, message)).start()
return
Copy link
Author

Choose a reason for hiding this comment

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

Function start refactored with the following changes:

Comment on lines -290 to +291
text = "<b>Bot Restarted!</b>"
message = bot.sendMessage(chat_id=OWNER_ID, text=text, parse_mode=ParseMode.HTML)
if AUTHORIZED_CHATS:
text = "<b>Bot Restarted!</b>"
message = bot.sendMessage(chat_id=OWNER_ID, text=text, parse_mode=ParseMode.HTML)
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

rows = self.cur.fetchall() #returns a list ==> (uid, sudo, auth, media, doc, thumb)
if rows:
if rows := self.cur.fetchall():
Copy link
Author

Choose a reason for hiding this comment

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

Function DbManger.db_load refactored with the following changes:

This removes the following comments ( why? ):

#returns a list ==> (uid, sudo, auth, media, doc, thumb)
#returns a list ==> (name, feed_link, last_link, last_title, filters)

sql = 'INSERT INTO users (uid, auth) VALUES ({}, TRUE)'.format(chat_id)
sql = f'INSERT INTO users (uid, auth) VALUES ({chat_id}, TRUE)'
else:
sql = 'UPDATE users SET auth = TRUE WHERE uid = {}'.format(chat_id)
sql = f'UPDATE users SET auth = TRUE WHERE uid = {chat_id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function DbManger.user_auth refactored with the following changes:

Comment on lines -112 to +110
sql = 'UPDATE users SET auth = FALSE WHERE uid = {}'.format(chat_id)
sql = f'UPDATE users SET auth = FALSE WHERE uid = {chat_id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function DbManger.user_unauth refactored with the following changes:

sql = 'INSERT INTO users (uid, leechlog) VALUES ({}, TRUE)'.format(chat_id)
sql = f'INSERT INTO users (uid, leechlog) VALUES ({chat_id}, TRUE)'
else:
sql = 'UPDATE users SET leechlog = TRUE WHERE uid = {}'.format(chat_id)
sql = f'UPDATE users SET leechlog = TRUE WHERE uid = {chat_id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function DbManger.addleech_log refactored with the following changes:

Comment on lines -135 to +133
sql = 'UPDATE users SET leechlog = FALSE WHERE uid = {}'.format(chat_id)
sql = f'UPDATE users SET leechlog = FALSE WHERE uid = {chat_id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function DbManger.rmleech_log refactored with the following changes:

sql = 'INSERT INTO users (uid, leechlogalt) VALUES ({}, TRUE)'.format(chat_id)
sql = f'INSERT INTO users (uid, leechlogalt) VALUES ({chat_id}, TRUE)'
else:
sql = 'UPDATE users SET leechlogalt = TRUE WHERE uid = {}'.format(chat_id)
sql = f'UPDATE users SET leechlogalt = TRUE WHERE uid = {chat_id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function DbManger.addleech_log_alt refactored with the following changes:

Comment on lines -158 to +156
sql = 'UPDATE users SET leechlogalt = FALSE WHERE uid = {}'.format(chat_id)
sql = f'UPDATE users SET leechlogalt = FALSE WHERE uid = {chat_id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function DbManger.rmleech_log_alt refactored with the following changes:

Comment on lines -19 to +49
if STOP_DUPLICATE and dl is not None and not dl.getListener().isLeech:
LOGGER.info('Checking File/Folder if already in Drive...')
sname = download.name
if dl.getListener().isZip:
sname = sname + ".zip"
elif dl.getListener().extract:
try:
sname = get_base_name(sname)
except:
sname = None
if sname is not None:
smsg, button = GoogleDriveHelper().drive_list(sname, True)
if smsg:
dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n')
api.remove([download], force=True, files=True)
return sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
if dl is not None and (ZIP_UNZIP_LIMIT is not None or TORRENT_DIRECT_LIMIT is not None):
sleep(1)
limit = None
if ZIP_UNZIP_LIMIT is not None and (dl.getListener().isZip or dl.getListener().extract):
mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB'
limit = ZIP_UNZIP_LIMIT
elif TORRENT_DIRECT_LIMIT is not None:
mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB'
limit = TORRENT_DIRECT_LIMIT
if limit is not None:
LOGGER.info('Checking File/Folder Size...')
size = api.get_download(gid).total_length
if size > limit * 1024**3:
dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}')
return api.remove([download], force=True, files=True)
if STOP_DUPLICATE and dl is not None and not dl.getListener().isLeech:
LOGGER.info('Checking File/Folder if already in Drive...')
sname = download.name
if dl.getListener().isZip:
sname = f"{sname}.zip"
elif dl.getListener().extract:
try:
sname = get_base_name(sname)
except:
sname = None
if sname is not None:
smsg, button = GoogleDriveHelper().drive_list(sname, True)
if smsg:
dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n')
api.remove([download], force=True, files=True)
return sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
if dl is not None and (ZIP_UNZIP_LIMIT is not None or TORRENT_DIRECT_LIMIT is not None):
sleep(1)
limit = None
if ZIP_UNZIP_LIMIT is not None and (dl.getListener().isZip or dl.getListener().extract):
mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB'
limit = ZIP_UNZIP_LIMIT
elif TORRENT_DIRECT_LIMIT is not None:
mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB'
limit = TORRENT_DIRECT_LIMIT
if limit is not None:
LOGGER.info('Checking File/Folder Size...')
size = api.get_download(gid).total_length
if size > limit * 1024**3:
dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}')
return api.remove([download], force=True, files=True)
Copy link
Author

Choose a reason for hiding this comment

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

Function __onDownloadStarted refactored with the following changes:

dl = getDownloadByGid(gid)
if dl:
if dl := getDownloadByGid(gid):
Copy link
Author

Choose a reason for hiding this comment

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

Function __onDownloadStopped refactored with the following changes:

Comment on lines -146 to +147
file_link = 'https://uptobox.com/api/link?token=%s&file_code=%s' % (UPTOBOX_TOKEN, file_id)
file_link = f'https://uptobox.com/api/link?token={UPTOBOX_TOKEN}&file_code={file_id}'

Copy link
Author

Choose a reason for hiding this comment

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

Function uptobox refactored with the following changes:

Comment on lines -257 to +260
raise DirectDownloadLinkException("ERROR: Cant't download due {}.".format(resp["message"]))
raise DirectDownloadLinkException(
f"""ERROR: Cant't download due {resp["message"]}."""
)
Copy link
Author

Choose a reason for hiding this comment

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

Function pixeldrain refactored with the following changes:

Comment on lines -323 to 327
numbers = [int(word) for word in str(str_2).split() if word.isdigit()]
if not numbers:
raise DirectDownloadLinkException("ERROR: 1fichier is on a limit. Please wait a few minutes/hour.")
else:
if numbers := [
int(word) for word in str(str_2).split() if word.isdigit()
]:
raise DirectDownloadLinkException(f"ERROR: 1fichier is on a limit. Please wait {numbers[0]} minute.")
Copy link
Author

Choose a reason for hiding this comment

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

Function fichier refactored with the following changes:

Comment on lines -356 to +361
mainOptions = str(re.search(r'viewerOptions\'\,\ (.*?)\)\;', pageSource).group(1))
mainOptions = str(re.search(r'viewerOptions\'\,\ (.*?)\)\;', pageSource)[1])
Copy link
Author

Choose a reason for hiding this comment

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

Function solidfiles refactored with the following changes:

gname = name + ".zip"
gname = f"{name}.zip"
Copy link
Author

Choose a reason for hiding this comment

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

Function add_gd_download refactored with the following changes:

Comment on lines -74 to +82
if (dlInfo['state'] == constants.State.TYPE_STATE_COMPLETED or dlInfo[
'state'] == constants.State.TYPE_STATE_CANCELED or dlInfo[
'state'] == constants.State.TYPE_STATE_FAILED) and self.__periodic is not None:
if (
dlInfo['state']
in [
constants.State.TYPE_STATE_COMPLETED,
constants.State.TYPE_STATE_CANCELED,
constants.State.TYPE_STATE_FAILED,
]
and self.__periodic is not None
):
Copy link
Author

Choose a reason for hiding this comment

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

Function MegaDownloadeHelper.__onInterval refactored with the following changes:

self.listener.onDownloadError("RequestTempError: " + error.toString())
self.listener.onDownloadError(f"RequestTempError: {error.toString()}")
Copy link
Author

Choose a reason for hiding this comment

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

Function MegaAppListener.onRequestTemporaryError refactored with the following changes:

mname = mname + ".zip"
mname = f"{mname}.zip"
Copy link
Author

Choose a reason for hiding this comment

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

Function add_mega_download refactored with the following changes:

@@ -759,7 +755,6 @@ def count(self, link):
msg += f'\n\n<b>Size: </b>{get_readable_file_size(self.__total_bytes)}'
msg += '\n\n<b>Type: </b>Folder'
msg += f'\n<b>SubFolders: </b>{self.__total_folders}'
msg += f'\n<b>Files: </b>{self.__total_files}'
Copy link
Author

Choose a reason for hiding this comment

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

Function GoogleDriveHelper.count refactored with the following changes:

Comment on lines -835 to +830
if "File not found" in str(err):
if "File not found" in err:
Copy link
Author

Choose a reason for hiding this comment

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

Function GoogleDriveHelper.helper refactored with the following changes:

Comment on lines -864 to +861
if "downloadQuotaExceeded" in str(err):
if "downloadQuotaExceeded" in err:
err = "Download Quota Exceeded."
elif "File not found" in str(err):
elif "File not found" in err:
Copy link
Author

Choose a reason for hiding this comment

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

Function GoogleDriveHelper.download refactored with the following changes:

Comment on lines -884 to +879
path += folder_name + '/'
path += f'{folder_name}/'
Copy link
Author

Choose a reason for hiding this comment

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

Function GoogleDriveHelper.__download_folder refactored with the following changes:

Comment on lines -910 to +905
fh = FileIO('{}{}'.format(path, filename), 'wb')
fh = FileIO(f'{path}{filename}', 'wb')
Copy link
Author

Choose a reason for hiding this comment

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

Function GoogleDriveHelper.__download_file refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented May 12, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.38%.

Quality metrics Before After Change
Complexity 38.16 ⛔ 37.67 ⛔ -0.49 👍
Method Length 96.18 🙂 95.72 🙂 -0.46 👍
Working memory 13.36 😞 13.32 😞 -0.04 👍
Quality 42.35% 😞 42.73% 😞 0.38% 👍
Other metrics Before After Change
Lines 7445 7413 -32
Changed files Quality Before Quality After Quality Change
add_to_team_drive.py 32.72% 😞 32.70% 😞 -0.02% 👎
gen_sa_accounts.py 34.85% 😞 34.56% 😞 -0.29% 👎
nodes.py 54.66% 🙂 57.46% 🙂 2.80% 👍
wserver.py 56.34% 🙂 57.08% 🙂 0.74% 👍
bot/init.py 23.22% ⛔ 24.61% ⛔ 1.39% 👍
bot/main.py 57.26% 🙂 57.55% 🙂 0.29% 👍
bot/helper/ext_utils/db_handler.py 74.91% 🙂 75.36% ⭐ 0.45% 👍
bot/helper/ext_utils/fs_utils.py 63.37% 🙂 63.15% 🙂 -0.22% 👎
bot/helper/mirror_utils/download_utils/aria2_download.py 53.37% 🙂 54.92% 🙂 1.55% 👍
bot/helper/mirror_utils/download_utils/direct_link_generator.py 61.13% 🙂 61.16% 🙂 0.03% 👍
bot/helper/mirror_utils/download_utils/gd_downloader.py 35.90% 😞 35.82% 😞 -0.08% 👎
bot/helper/mirror_utils/download_utils/mega_download.py 85.51% ⭐ 86.62% ⭐ 1.11% 👍
bot/helper/mirror_utils/download_utils/mega_downloader.py 59.58% 🙂 59.56% 🙂 -0.02% 👎
bot/helper/mirror_utils/download_utils/qbit_downloader.py 15.80% ⛔ 15.80% ⛔ 0.00%
bot/helper/mirror_utils/download_utils/telegram_downloader.py 73.87% 🙂 76.13% ⭐ 2.26% 👍
bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py 64.47% 🙂 65.67% 🙂 1.20% 👍
bot/helper/mirror_utils/status_utils/qbit_download_status.py 89.82% ⭐ 89.52% ⭐ -0.30% 👎
bot/helper/mirror_utils/upload_utils/gdriveTools.py 44.26% 😞 44.58% 😞 0.32% 👍
bot/helper/mirror_utils/upload_utils/pyrogramEngine.py 32.54% 😞 32.86% 😞 0.32% 👍
bot/helper/telegram_helper/filters.py 79.26% ⭐ 82.55% ⭐ 3.29% 👍
bot/modules/authorize.py 38.83% 😞 40.16% 😞 1.33% 👍
bot/modules/cancel_mirror.py 53.83% 🙂 53.67% 🙂 -0.16% 👎
bot/modules/clone.py 3.54% ⛔ 3.68% ⛔ 0.14% 👍
bot/modules/leech_settings.py 50.24% 🙂 50.22% 🙂 -0.02% 👎
bot/modules/mirror.py 17.36% ⛔ 17.48% ⛔ 0.12% 👍
bot/modules/mirror_status.py 70.99% 🙂 70.37% 🙂 -0.62% 👎
bot/modules/rss.py 39.65% 😞 39.66% 😞 0.01% 👍
bot/modules/search.py 44.94% 😞 44.93% 😞 -0.01% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
bot/modules/mirror.py _mirror 105 ⛔ 1113 ⛔ 31 ⛔ 0.87% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
bot/modules/mirror.py MirrorListener.onUploadComplete 122 ⛔ 920 ⛔ 27 ⛔ 1.45% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
bot/helper/mirror_utils/download_utils/qbit_downloader.py _qb_listener 130 ⛔ 642 ⛔ 25 ⛔ 2.06% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
bot/modules/clone.py cloneNode 84 ⛔ 863 ⛔ 25 ⛔ 2.36% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
bot/modules/mirror.py MirrorListener.onDownloadComplete 93 ⛔ 711 ⛔ 22 ⛔ 3.35% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants