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

Dev #127

Merged
merged 20 commits into from
Jul 17, 2024
Merged

Dev #127

merged 20 commits into from
Jul 17, 2024

Conversation

5hojib
Copy link
Owner

@5hojib 5hojib commented Jul 10, 2024

Summary by Sourcery

This pull request includes significant refactoring to improve code readability and maintainability, removal of unused imports, and the addition of a new CI workflow for automatic code formatting using Ruff.

  • Enhancements:
    • Refactored torrent_select.py to improve code readability and maintainability by splitting large functions into smaller ones.
    • Removed unused imports and redundant code from multiple files to streamline the codebase.
    • Simplified string formatting in several files for consistency and readability.
  • CI:
    • Added a new GitHub Actions workflow (ruff.yml) to automatically format code using Ruff on push to the dev branch.

Copy link
Contributor

sourcery-ai bot commented Jul 10, 2024

Reviewer's Guide by Sourcery

This pull request refactors and optimizes several modules in the bot codebase, introduces new helper functions, and adds a GitHub Actions workflow for code formatting using Ruff. The changes include renaming functions, restructuring code for better readability, removing unused imports, and handling exceptions more gracefully.

File-Level Changes

Files Changes
bot/modules/torrent_select.py
bot/__main__.py
bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py
bot/helper/mirror_leech_utils/upload_utils/telegramEngine.py
bot/modules/users_settings.py
bot/helper/telegram_helper/message_utils.py
bot/modules/list.py
bot/helper/listeners/tasks_listener.py
bot/helper/ext_utils/task_manager.py
bot/modules/broadcast.py
bot/modules/cancel_mirror.py
bot/modules/executor.py
bot/modules/speedtest.py
web/nodes.py
Refactored code for better readability, removed unused imports, simplified string formatting, and handled exceptions more gracefully.
.github/workflows/ruff.yml Added a new GitHub Actions workflow for code formatting using Ruff.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@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.

Hey @5hojib - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 9 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

await message.delete()

async def handle_done_action(id_, download, message):
await query.answer()
Copy link
Contributor

Choose a reason for hiding this comment

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

question (bug_risk): Potential missing argument in query.answer()

The query.answer() method can take arguments like text and show_alert. Ensure that this call is intended to be without arguments.

else:
await handle_aria2_done(id_, download)

await sendStatusMessage(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Redundant message deletion

Since sendStatusMessage is followed by message.delete(), ensure that sendStatusMessage does not already delete the message to avoid redundant operations.

if file['selected'] == 'false' and await aiopath.exists(file['path']):
try:
await aioremove(file['path'])
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Avoid bare except

Catching all exceptions with a bare except: can hide unexpected errors. Consider catching specific exceptions or using except Exception:.

await message.delete()

if not download.queued:
await sync_to_async(client.torrents_resume, torrent_hashes=torrent_hash)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Error handling for torrents_resume

Consider adding error handling for the torrents_resume call to manage potential failures gracefully.

Suggested change
await sync_to_async(client.torrents_resume, torrent_hashes=torrent_hash)
try:
await sync_to_async(client.torrents_resume, torrent_hashes=torrent_hash)
except Exception as e:
# Handle the error, e.g., log it or notify the user
print(f"Failed to resume torrent: {e}")

@@ -1043,7 +1043,7 @@ def hubdrive(url):
gd_data = soup.select('a[class="btn btn-primary btn-user"]')
gd_link = gd_data[0]['href']
return gd_link
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Removed exception variable

Removing the exception variable e might make debugging harder. Consider keeping it for logging purposes.

Suggested change
except Exception as e:
except Exception as e:
raise DirectDownloadLinkException(f'ERROR: Download link not found try again: {e}')

@@ -82,7 +82,7 @@ async def execute_code(func, message):
try:
with redirect_stdout(stdout):
func_return = await func()
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Removed exception variable

Removing the exception variable e might make debugging harder. Consider keeping it for logging purposes.

Suggested change
except Exception as e:
except Exception as e:
raise DirectDownloadLinkException(f'ERROR: Download link not found try again: {e}')

@@ -25,7 +25,7 @@ def get_speedtest_results():
await editMessage(speed, "Speedtest failed to complete.")
return

string_speed = f"<b>SPEEDTEST INFO</b>\n\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

question (bug_risk): Removed f-string

The f-string was removed, but if any variables were intended to be included in the string, this change might cause issues.

Comment on lines +1046 to 1047
except Exception:
raise DirectDownloadLinkException('ERROR: Download link not found try again')
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Explicitly raise from a previous error (raise-from-previous-error)

Suggested change
except Exception:
raise DirectDownloadLinkException('ERROR: Download link not found try again')
except Exception as e:
raise DirectDownloadLinkException(
'ERROR: Download link not found try again'
) from e

Comment on lines 61 to 64
try:
await aioremove(f['path'])
await aioremove(file_path)
except:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Use except Exception: rather than bare except: (do-not-use-bare-except)

Comment on lines 74 to 77
try:
await aioremove(file['path'])
except:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Use except Exception: rather than bare except: (do-not-use-bare-except)

@5hojib 5hojib merged commit 9652868 into main Jul 17, 2024
3 checks passed
@5hojib 5hojib deleted the dev branch July 17, 2024 00:53
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.

1 participant