-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[Audio]: Add button support for [p]now
#6730
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
Open
Evanroby
wants to merge
7
commits into
Cog-Creators:V3/develop
Choose a base branch
from
Evanroby:now-button
base: V3/develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b69bd54
[Audio]: Add button support for `[p]now`
Evanroby 82096fd
black
Evanroby d3e4884
Merge branch 'V3/develop' into now-button
Jackenmen 8b2a2d0
Apply suggestions from code review
Evanroby 06a1405
rename file
Evanroby 662a5e8
Merge branch 'now-button' of https://github.com/Evanroby/Red-DiscordB…
Evanroby 4ea9435
add check for reactions
Evanroby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Evanroby marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import contextlib | ||
| from pathlib import Path | ||
|
|
||
| import discord | ||
|
|
||
| from redbot.core import commands | ||
| from redbot.core.i18n import Translator | ||
|
|
||
| _ = Translator("Audio", Path(__file__)) | ||
|
|
||
|
|
||
| class NowPlayingView(discord.ui.View): | ||
| """Button-based controls for the [p]now command. | ||
|
|
||
| Only shown when [p]set usebuttons is enabled. | ||
| When there is no queue and autoplay is off, prev and next are hidden. | ||
| """ | ||
|
|
||
| def __init__(self, ctx: commands.Context, cog, has_queue: bool): | ||
| super().__init__(timeout=30.0) | ||
| self.ctx = ctx | ||
| self.cog = cog | ||
| self.message: discord.Message = None | ||
|
|
||
| if not has_queue: | ||
| self.remove_item(self.button_prev) | ||
| self.remove_item(self.button_next) | ||
|
|
||
| async def interaction_check(self, interaction: discord.Interaction) -> bool: | ||
| if interaction.user != self.ctx.author: | ||
| await interaction.response.send_message( | ||
| _("You are not the one who requested this player."), ephemeral=True | ||
| ) | ||
| return False | ||
| return True | ||
|
|
||
| async def on_timeout(self) -> None: | ||
| if self.message: | ||
| with contextlib.suppress(discord.HTTPException): | ||
| await self.message.edit(view=None) | ||
|
|
||
| @discord.ui.button( | ||
| emoji="\N{BLACK LEFT-POINTING DOUBLE TRIANGLE WITH VERTICAL BAR}\N{VARIATION SELECTOR-16}", | ||
| style=discord.ButtonStyle.grey, | ||
| ) | ||
| async def button_prev(self, interaction: discord.Interaction, button: discord.ui.Button): | ||
| await interaction.response.defer() | ||
| self.stop() | ||
| with contextlib.suppress(discord.HTTPException): | ||
| await self.message.edit(view=None) | ||
| await self.ctx.invoke(self.cog.command_prev) | ||
|
|
||
| @discord.ui.button( | ||
| emoji="\N{BLACK SQUARE FOR STOP}\N{VARIATION SELECTOR-16}", | ||
| style=discord.ButtonStyle.grey, | ||
| ) | ||
| async def button_stop(self, interaction: discord.Interaction, button: discord.ui.Button): | ||
| await interaction.response.defer() | ||
| self.stop() | ||
| with contextlib.suppress(discord.HTTPException): | ||
| await self.message.edit(view=None) | ||
| await self.ctx.invoke(self.cog.command_stop) | ||
|
|
||
| @discord.ui.button( | ||
| emoji="\N{BLACK RIGHT-POINTING TRIANGLE WITH DOUBLE VERTICAL BAR}\N{VARIATION SELECTOR-16}", | ||
| style=discord.ButtonStyle.grey, | ||
| ) | ||
| async def button_pause(self, interaction: discord.Interaction, button: discord.ui.Button): | ||
| await interaction.response.defer() | ||
| self.stop() | ||
| with contextlib.suppress(discord.HTTPException): | ||
| await self.message.edit(view=None) | ||
| await self.ctx.invoke(self.cog.command_pause) | ||
|
|
||
| @discord.ui.button( | ||
| emoji="\N{BLACK RIGHT-POINTING DOUBLE TRIANGLE WITH VERTICAL BAR}\N{VARIATION SELECTOR-16}", | ||
| style=discord.ButtonStyle.grey, | ||
| ) | ||
| async def button_next(self, interaction: discord.Interaction, button: discord.ui.Button): | ||
| await interaction.response.defer() | ||
| self.stop() | ||
| with contextlib.suppress(discord.HTTPException): | ||
| await self.message.edit(view=None) | ||
| await self.ctx.invoke(self.cog.command_skip) | ||
|
|
||
| @discord.ui.button( | ||
| emoji="\N{CROSS MARK}", | ||
| style=discord.ButtonStyle.grey, | ||
| ) | ||
| async def button_close(self, interaction: discord.Interaction, button: discord.ui.Button): | ||
| await interaction.response.defer() | ||
| self.stop() | ||
| with contextlib.suppress(discord.HTTPException): | ||
| await self.message.delete() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.