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 Starbot ⭐ refactored CodexLink/discord-activity-badge #40

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

Conversation

sourcery-ai-bot
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

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

git fetch https://github.com/sourcery-ai-bot/discord-activity-badge latest
git merge --ff-only FETCH_HEAD
git reset HEAD^

suffix_req_cost: str = (
"Remaining Requests over Rate-Limit (%s/%s)"
% (
http_request.headers["X-RateLimit-Remaining"],
http_request.headers["X-RateLimit-Limit"],
)
)
suffix_req_cost: str = f'Remaining Requests over Rate-Limit ({http_request.headers["X-RateLimit-Remaining"]}/{http_request.headers["X-RateLimit-Limit"]})'
Copy link
Author

Choose a reason for hiding this comment

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

Function AsyncGithubAPILite.exec_api_actions refactored with the following changes:

This removes the following comments ( why? ):

# Same for this case, but we assert that the data received is malformed.
# So for this case, we special handle it by identifying the message.
# If any of those conditions weren't met, retry again.
# Whenever we tried too much, we don't know if we are rate-limited, because the request will make the ClientResponse.ok set to True.

Comment on lines -103 to +109
self.print_exception(GithubRunnerLevelMessages.ERROR, msg, None)
terminate(ExitReturnCodes.ILLEGAL_CONDITION_EXIT)

else:
msg = f"The given value in `ctx_inout` parameter is not a {Base64String.__name__}! Please contact the developer about this issue."
self.logger.error(msg)

self.print_exception(GithubRunnerLevelMessages.ERROR, msg, None)
terminate(ExitReturnCodes.ILLEGAL_CONDITION_EXIT)

self.print_exception(GithubRunnerLevelMessages.ERROR, msg, None)
terminate(ExitReturnCodes.ILLEGAL_CONDITION_EXIT)
Copy link
Author

Choose a reason for hiding this comment

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

Function BadgeConstructor._handle_b64 refactored with the following changes:

(
f"Badge with Identifier {identifier_name} found! Substituting the old badge."
)
f"Badge with Identifier {identifier_name} found! Substituting the old badge."
if self.envs["BADGE_IDENTIFIER_NAME"] == identifier_name
else "Badge with Identifier (%s) not found! New badge will append on the top of the contents of README.md. Please arrange/move the badge once changes has been pushed!"
% self.envs["BADGE_IDENTIFIER_NAME"]
else f'Badge with Identifier ({self.envs["BADGE_IDENTIFIER_NAME"]}) not found! New badge will append on the top of the contents of README.md. Please arrange/move the badge once changes has been pushed!'
Copy link
Author

Choose a reason for hiding this comment

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

Function BadgeConstructor.check_and_update_badge refactored with the following changes:

Comment on lines -296 to +298
f"Preferred Activity %s %s"
% (
self.envs["PREFERRED_ACTIVITY_TO_DISPLAY"],
"exists!"
if is_preferred_exists
else f"does not exists. Using other activity such as {picked_activity}.",
(
"Preferred Activity %s %s"
% (
self.envs["PREFERRED_ACTIVITY_TO_DISPLAY"],
"exists!"
if is_preferred_exists
else f"does not exists. Using other activity such as {picked_activity}.",
)
Copy link
Author

Choose a reason for hiding this comment

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

Function BadgeConstructor.construct_badge refactored with the following changes:

This removes the following comments ( why? ):

# Supposedly have to check for any activity, but we have to be specific here instead.
# ! Special handle for CustomActivity.
# Since activities can display time remaining or elapsed, check the context if timestamps exists so that it can display `remaining` instead of `elapsed`.
# * Also, since this mf doesn't like '+=', let's do the manual with type.
# ! This only works whenever there's an activity and PREFERRED_PRESENCE_CONTEXT or TIME_DISPLAY_OUTPUT is not disabled.
# Display the seperator instead.
# * Otherwise, we don't have to output anything since there's no context to seperate.
# Append the seperator. This one is a condition-hell since we have to consider two other values and the state of the badge.
# * Resolve for the case of `elapsed`.
# ! Seperator #2, Literally invoke the seperator since we assert that the time display is enabled.
# * Appends the User's State whenever presence_ctx is zero or otherwise, append the activity's application name.
# Append the spotify current music if the picked_activity is SPOTIFY_ACTIVITY or else...
# * Appends Activity or User's State if `STATIC_SUBJECT_STRING` is not None, otherwise, use the STATIC_SUBJECT_STRING.

"Discord User %s Fetched."
% (self.user_ctx["name"] + self.user_ctx["discriminator"])
f'Discord User {self.user_ctx["name"] + self.user_ctx["discriminator"]} Fetched.'
Copy link
Author

Choose a reason for hiding this comment

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

Function DiscordClientHandler._get_discord_user refactored with the following changes:

Comment on lines -167 to +175
# Once type checked, fetch the user from guild and fetch it as a member from that guild.
fetched_member: Optional[Member] = fetched_user.mutual_guilds[0].get_member(
if fetched_member := fetched_user.mutual_guilds[0].get_member(
fetched_user.id
)

if (
fetched_member
): # ! Since `get_member` enforce Optional, then we assert here that it will never be Optional or lead to None.
):
if not fetched_member.activities:
self.logger.warning(f"User {fetched_member} doesn't have any activity.")

else:
self.logger.info(
f"User {fetched_member} contains {len(fetched_member.activities)} activit%s."
% ("y" if not len(fetched_member.activities) > 1 else "ies")
% ("y" if len(fetched_member.activities) <= 1 else "ies")
Copy link
Author

Choose a reason for hiding this comment

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

Function DiscordClientHandler._get_activities_via_guild refactored with the following changes:

  • Use named expression to simplify assignment and conditional (use-named-expression)
  • Simplify logical expression using De Morgan identities [×2] (de-morgan)

This removes the following comments ( why? ):

# ! Since `get_member` enforce Optional, then we assert here that it will never be Optional or lead to None.
# Once type checked, fetch the user from guild and fetch it as a member from that guild.

f"Argument --rol / --running-on-local detected, `dotenv` packages were imported."
"Argument --rol / --running-on-local detected, `dotenv` packages were imported."
Copy link
Author

Choose a reason for hiding this comment

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

Function UtilityMethods.check_dotenv refactored with the following changes:

f"Out to Console (Render Log to Console) has been enabled. Expect more outputs here."
"Out to Console (Render Log to Console) has been enabled. Expect more outputs here."
Copy link
Author

Choose a reason for hiding this comment

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

Function UtilityMethods.init_logger refactored with the following changes:

"Fallback Value of %s for Optional | %s (is None?) -> %s"
% (
env_key,
ENV_STRUCT_CONSTRAINTS[env_key]["fallback_value"] is None,
ENV_STRUCT_CONSTRAINTS[env_key]["fallback_value"],
)
f'Fallback Value of {env_key} for Optional | {ENV_STRUCT_CONSTRAINTS[env_key]["fallback_value"] is None} (is None?) -> {ENV_STRUCT_CONSTRAINTS[env_key]["fallback_value"]}'
Copy link
Author

Choose a reason for hiding this comment

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

Function UtilityMethods.resolve_envs refactored with the following changes:

This removes the following comments ( why? ):

# If they are required (is_required -> False) then terminate the script.
# If the name matches, then set to `True` or otherwise.

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.

None yet

1 participant