-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Speed up adding tracks from playlist (Sourcery refactored) #21
base: main
Are you sure you want to change the base?
Conversation
…peeding up adding tracks from a playlist, changed youtube playlist looup function to avoid searching a known playlist url
return await ctx.send(f'{ctx.author.mention} This command has a cooldown, be sure to wait for '+str(jour)+ "day(s)") | ||
return await ctx.send( | ||
f'{ctx.author.mention} This command has a cooldown, be sure to wait for {str(jour)}day(s)' | ||
) | ||
if heure > 0: | ||
return await ctx.send(f'{ctx.author.mention} This command has a cooldown, be sure to wait for '+str(heure)+ " hour(s)") | ||
return await ctx.send( | ||
f'{ctx.author.mention} This command has a cooldown, be sure to wait for {str(heure)} hour(s)' | ||
) | ||
if minute > 0: | ||
return await ctx.send(f'{ctx.author.mention} This command has a cooldown, be sure to wait for '+ str(minute)+" minute(s)") | ||
return await ctx.send( | ||
f'{ctx.author.mention} This command has a cooldown, be sure to wait for {str(minute)} minute(s)' | ||
) |
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 EventsCog.on_command_error
refactored with the following changes:
- Use f-string instead of string concatenation [×6] (
use-fstring-for-concatenation
) - Replace f-string with no interpolated values with string [×3] (
remove-redundant-fstring
) - Replace call to format with f-string (
use-fstring-for-formatting
)
if (before.channel is not None) and (after.channel is None): | ||
if member == self.bot.user: | ||
|
||
player = self.bot.wavelink.get_player(before.channel.guild.id) | ||
if player.is_playing: | ||
await player.destroy() | ||
DBQueue(self.bot.dbConnection).clear(before.channel.guild.id) | ||
DBServer(self.bot.dbConnection).clearMusicParameters(before.channel.guild.id, False, False) | ||
if ( | ||
(before.channel is not None) | ||
and (after.channel is None) | ||
and member == self.bot.user | ||
): | ||
player = self.bot.wavelink.get_player(before.channel.guild.id) | ||
if player.is_playing: | ||
await player.destroy() | ||
DBQueue(self.bot.dbConnection).clear(before.channel.guild.id) | ||
DBServer(self.bot.dbConnection).clearMusicParameters(before.channel.guild.id, False, False) |
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 EventsCog.on_voice_state_update
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
if not trackLinks: # if len(trackLinks) == 0: | ||
return None | ||
return trackLinks | ||
return trackLinks or None |
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 searchSpotifyPlaylist
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
) - Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Simplify if expression by using or (
or-if-exp-identity
)
This removes the following comments ( why? ):
# if len(trackLinks) == 0:
if link is None: | ||
return None | ||
return link | ||
return None if link is None else link | ||
if "playlist" in response._real_url.path: | ||
links = await searchDeezerPlaylist(self, ctx, session, response) | ||
if links is None: | ||
return None | ||
return links | ||
return None if links is None else links |
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 searchDeezer
refactored with the following changes:
- Lift code into else after jump in control flow [×2] (
reintroduce-else
) - Replace if statement with if expression [×2] (
assign-if-exp
)
if not trackLinks: | ||
return None | ||
return trackLinks | ||
return trackLinks or None |
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 searchDeezerPlaylist
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
) - Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Simplify if expression by using or (
or-if-exp-identity
)
@@ -165,21 +157,27 @@ def check(message): | |||
messageContent = int(message.content) | |||
if ((messageContent >= 0) and (messageContent <= 5)): | |||
return message.content | |||
|
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 searchQuery
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
||
if not await Check().userInVoiceChannel(ctx, self.bot): return | ||
if not await Check().botInVoiceChannel(ctx, self.bot): return | ||
if not await Check().userInVoiceChannel(ctx, self.bot): return | ||
if not await Check().botInVoiceChannel(ctx, self.bot): return | ||
if not await Check().userAndBotInSameVoiceChannel(ctx, self.bot): return | ||
|
||
if not ctx.author.guild_permissions.administrator: | ||
|
||
users = DBSkip(self.bot.dbConnection).displayUsers(ctx.guild.id) | ||
usersCount = len(users) | ||
|
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 CogSkip.skip
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
queueSize = 0 | ||
queueDuration = "00:00" | ||
|
||
embed=discord.Embed(title="Song added in the queue", description=f"New song added : **[{trackTitle}]({track.uri})** ({trackDuration})", color=discord.Colour.random()) | ||
embed.add_field(name="Place in the queue : ", value=f"`{queueSize}`", inline=True) | ||
embed.add_field(name="Estimated time before playing :", value=f"`{queueDuration}`", inline=True) | ||
embed.set_thumbnail(url=track.thumb) | ||
await ctx.channel.send(embed=embed) | ||
trackDuration = await Utils().durationFormat(track.duration) | ||
trackTitle = track.title.replace("*", "\\*") | ||
|
||
if len(tracks) == 1: | ||
if queueSizeAndDuration := DBQueue( | ||
self.bot.dbConnection | ||
).queueSizeAndDuration(ctx.guild.id): |
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 addTrack
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression
) - Merge else clause's nested if statement into elif [×2] (
merge-else-if-into-elif
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
This removes the following comments ( why? ):
# If it's a playlist => Update the same message to do not spam the channel
# Queue size and duration
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.01%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
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! |
Pull Request #20 refactored by Sourcery.
Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.
To incorporate these changes, you can either:
Merge this Pull Request instead of the original, or
Ask your contributor to locally incorporate these commits and push them to
the original Pull Request
Incorporate changes via command line
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Help us improve this pull request!