MusicBot
MusicBot copied to clipboard
Simplify autopause logic
After creating your pull request, tick these boxes if they are applicable to you.
- [x] I have tested my changes against the
review
branch (the latest developmental version), and this pull request is targeting that branch as a base - [x] I have tested my changes on Python 3.5.3 or higher
- [x] Auto-formatted changes using
black
Description
The autopause logic in on_voice_state_update
is quite complex and distinguishes a lot of different cases, but in the end (as far as I can tell), there are just two possible scenarios: The channel is effectively empty, so we pause, or the channel is not empty, so we resume if we previously auto-paused (or we left the channel, but that's handled separately before).
This patch simplifies that logic and also re-uses existing functions to check for empty channels and perform the auto-pause. It should not change visible behaviour except for some slight changes in info log messages. I have verified that autopause continues to work as expected.
To be honest, I'm not entirely sure when the lines player.once("play", lambda player, **_: self._autopause(player))
(l.382 & l.736) trigger and what they do, but the code executed for those should not be changed by this patch.
Update: Figured it out, should work as expected. Also fixed an edge-case where summoning the bot to a deaf-only channel did not autopause.
Related issues (if applicable)
Related question: Is it safe to assume that MusicBot is always a bot? I.e. if member == guild.me
, is member.bot
always true?
Related question: Is it safe to assume that MusicBot is always a bot? I.e. if
member == guild.me
, ismember.bot
always true?
Yes, I believe that was added back when users could login with a email and password and just hasn't been touched since, but I might be wrong, it should always be true though.