-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: latest
Are you sure you want to change the base?
Conversation
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"]})' |
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 AsyncGithubAPILite.exec_api_actions
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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.
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) |
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 BadgeConstructor._handle_b64
refactored with the following changes:
- Hoist repeated code outside conditional statement [×2] (
hoist-statement-from-if
)
( | ||
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!' |
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 BadgeConstructor.check_and_update_badge
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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}.", | ||
) |
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 BadgeConstructor.construct_badge
refactored with the following changes:
- Replace f-string with no interpolated values with string [×3] (
remove-redundant-fstring
) - Replace interpolated string formatting with f-string [×8] (
replace-interpolation-with-fstring
) - Use named expression to simplify assignment and conditional (
use-named-expression
) - Simplify numeric comparison (
simplify-numeric-comparison
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
)
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.' |
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 DiscordClientHandler._get_discord_user
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
# 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") |
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 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." |
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 UtilityMethods.check_dotenv
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
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." |
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 UtilityMethods.init_logger
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
"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"]}' |
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 UtilityMethods.resolve_envs
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
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.
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: