Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Music Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
devbutlazy committed Jan 1, 2024
1 parent 5cd0f18 commit 262ddfd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
4 changes: 1 addition & 3 deletions src/cogs/DevCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ async def callback(self, interaction: disnake.Interaction) -> None:
and i.user == interaction.user,
)

if interaction.user.id not in self.bot.owner_ids:
return

await modal_response.response.defer(ephemeral=True)
pending_embed = disnake.Embed(description='Code is processing...', color=disnake.Colour.from_rgb(255, 255, 0))
message = await modal_response.followup.send(embed=pending_embed, ephemeral=True)
Expand Down Expand Up @@ -219,6 +216,7 @@ def __init__(self, bot: commands.Bot):
# TODO: BLACKLIST SETTINGS

@commands.slash_command(name="panel", description="Panel menu", guild_ids=[1109511263509291098])
@commands.is_owner()
async def panel_menu(self, interaction):
embed=disnake.Embed(color=disnake.Color.blurple())
embed.title="Control panel for Synth"
Expand Down
25 changes: 11 additions & 14 deletions src/cogs/MusicCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,17 @@ async def _volume(
check=lambda i: i.custom_id == "volume" and i.user == interaction.user,
)
new_volume = int(response_modal.text_values["new_volume"])
try:
await player.set_volume(new_volume)
embed = disnake.Embed(
title=f"Set volume to {new_volume}", color=disnake.Color.green()
)
await response_modal.response.send_message(embed=embed, ephemeral=True)
except (Exception, BaseException, disnake.Forbidden):
embed = disnake.Embed(color=disnake.Color.red())
if new_volume > 100 or new_volume < 1:
embed.title = f"Please enter a number, between `1` and `100`"
else:
embed.title = f"Sorry, something went wrong"

error_embed = disnake.Embed(color=disnake.Color.red())
if new_volume > 100 or new_volume < 1:
error_embed.title = f"Please enter a number, between `1` and `100`"
return await response_modal.response.send_message(embed=error_embed, ephemeral=True)

await response_modal.response.send_message(embed=embed, ephemeral=True)
await player.set_volume(new_volume)
embed = disnake.Embed(
title=f"Set volume to {new_volume}", color=disnake.Color.green()
)
await response_modal.response.send_message(embed=embed, ephemeral=True)

@disnake.ui.button(label="Queue", style=disnake.ButtonStyle.blurple, row=1)
async def queue(
Expand All @@ -131,7 +128,7 @@ async def queue(
f"`{index}.` **{music.author} - {music.title}**\n"
)

embed.set_footer(text="Page 1")
embed.set_footer(text="Page 0")

paginator = EmbedPaginator(
interaction, interaction.user, embed, player.queue[10:], None, 10
Expand Down
47 changes: 38 additions & 9 deletions src/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,15 @@ async def send_message(
disnake.MessageCommandInteraction,
disnake.MessageInteraction,
],
) -> Union[Message, Any]:
) -> Union[disnake.Message, Any]:

self.prev_page.disabled = True
self.next_page.disabled = False

if isinstance(
ctx, (disnake.MessageCommandInteraction, disnake.MessageInteraction)
):
return await ctx.response.send_message(embed=self.embed, view=self)
return await ctx.response.send_message(embed=self.embed, view=self, ephemeral=True)
return await ctx.send(embed=self.embed, view=self)

async def _create_embed(
Expand All @@ -370,8 +374,8 @@ async def _create_embed(

music: mafic.Track
embed.description += f"`{index}.` **{music.author} - {music.title}**\n"

all_pages = math.ceil(len(self.data) / self.separate)
all_pages = (math.ceil(len(self.data) / self.separate) - 1)
embed.set_footer(text=f"Page {self.current_page} of {all_pages}")

return embed
Expand All @@ -387,25 +391,50 @@ async def update(
async def prev_page(
self, _: disnake.ui.Button, interaction: disnake.MessageInteraction
) -> None:
if self.current_page <= 0:
self.prev_page.disabled = True
self.next_page.disabled = False

return await self.update(self.interaction, self.embed)

await interaction.response.defer()

self.current_page -= 1

start = self.current_page * self.separate
data = self.data[start:]
await self.update(self.interaction, await self._create_embed(self.embed, data))
if self.current_page <= 0:
self.prev_page.disabled = True
self.next_page.disabled = False
return await self.update(self.interaction, self.embed)
else:
self.prev_page.disabled = False if self.current_page > 0 else True
self.next_page.disabled = False if self.current_page < (math.ceil(len(self.data) / self.separate) - 1) else True

start = self.current_page * self.separate
data = self.data[start:]
return await self.update(self.interaction, await self._create_embed(self.embed, data))
# await self.update_buttons()

@disnake.ui.button(label="▶️", style=disnake.ButtonStyle.blurple)
async def next_page(
self, _: disnake.ui.Button, interaction: disnake.MessageInteraction
) -> None:
if self.current_page >= (math.ceil(len(self.data) / self.separate) - 1):
self.next_page.disabled = True
self.prev_page.disabled = False

return await self.update(self.interaction, self.embed)

await interaction.response.defer()
self.current_page += 1

self.prev_page.disabled = False if self.current_page > 0 else True
self.next_page.disabled = False if self.current_page < (math.ceil(len(self.data) / self.separate) - 1) else True
start = self.current_page * self.separate
data = self.data[start:]
await self.update(self.interaction, await self._create_embed(self.embed, data))
return await self.update(self.interaction, await self._create_embed(self.embed, data))
# await self.update_buttons()

async def interaction_check(self, interaction: MessageInteraction) -> bool:
async def interaction_check(self, interaction: disnake.MessageInteraction) -> bool:
if interaction.user.id != self.author.id:
await interaction.send(
content="You are not allowed to use this buttons!", ephemeral=True
Expand Down

0 comments on commit 262ddfd

Please sign in to comment.