-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buttons.py
135 lines (99 loc) · 4.96 KB
/
Buttons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from Helper import *
# Lógica para los botones.
class MusicButton(discord.ui.Button):
def __init__(self, label, style, custom_id):
super().__init__(label=label, style=style, custom_id=custom_id)
self.custom_callback = None
async def callback(self, interaction: discord.Interaction):
if self.custom_callback:
await self.custom_callback(interaction)
def set_callback(self, callback):
self.custom_callback = callback
class MusicView(discord.ui.View):
def __init__(self):
super().__init__()
self.pause_button = MusicButton(label="Pause", style=discord.ButtonStyle.primary, custom_id="pause")
self.stop_button = MusicButton(label="Stop", style=discord.ButtonStyle.danger, custom_id="stop")
self.queue_button = MusicButton(label="SNS" , style=discord.ButtonStyle.success, custom_id="queue") #SNS significa Show Next Song
self.skip_button = MusicButton(label="Skip", style=discord.ButtonStyle.primary, custom_id="skip")
self.add_item(self.pause_button)
self.add_item(self.stop_button)
self.add_item(self.queue_button)
self.add_item(self.skip_button)
self.is_paused = False
#Botones para controlar las canciones.
#Boton Pausa-Resumir
async def pause_resume(self, interaction: discord.Interaction):
vc = interaction.guild.voice_client
if vc:
if self.is_paused:
vc.resume()
self.is_paused = False
self.pause_button.label = "Pause"
await interaction.response.defer()
else:
vc.pause()
self.is_paused = True
self.pause_button.label = "Resume"
await interaction.response.defer()
await interaction.message.edit(view=self)
#Boton Stop
async def stop(self, interaction: discord.Interaction, ctx: commands.Context):
global queue, search_result_global, song_position
vc = interaction.guild.voice_client
if vc:
vc.stop()
queue = asyncio.Queue()
search_result_global = None
song_position = 1
embed = discord.Embed(description='Detenido', color=discord.Color.gold())
await ctx.send(embed=embed)
await interaction.response.defer()
#Boton Skip
async def skip(self, interaction: discord.Interaction):
global song_position
vc = interaction.guild.voice_client
if vc:
vc.stop()
song_position -= 1
if song_position == 0:
song_position += 1
await interaction.response.defer()
#Boton SNS, la función de este boton es solo para mostrar la canción actual y la siguiente canción, incluso si hay 3 canciones en la cola solo mostrará la siguiente cancion.
async def show_queue(self, interaction: discord.Interaction, current_song):
global queue
await interaction.response.defer()
queue_list = list(queue._queue)
embed = discord.Embed(title="💿 Ahora suena", color=random_color())
if current_song:
embed.set_thumbnail(url=current_song["thumbnail"])
title = current_song.get('title', 'No hay ninguna canción reproduciéndose.')
url = current_song.get('webpage_url', '')
if url:
embed.add_field(name="🔊 Canción Actual 🔊", value=f"[{title[:100]}]({url[:100]})", inline=False)
else:
embed.add_field(name="🔊 Canción Actual 🔊", value=title, inline=False)
else:
embed.add_field(name="🔊 Canción Actual 🔊", value="No hay ninguna canción reproduciéndose.", inline=False)
if not queue.empty() and len(queue_list) > 0: # Cambiado de 1 a 0 aquí
next_song = queue_list[0]['info'] # Cambiado de 1 a 0 aquí
embed.add_field(name="🎶 Siguiente Canción 🎶", value=f"{next_song['title']}", inline=False)
else:
embed.add_field(name="🎶 No hay siguiente canción. ¡Agrega una! 🎶", value=f"", inline=False)
embed.set_footer(text="Usa +skip para saltar la canción")
embed.set_footer(text="Usa +skip para saltar la canción")
msg = await interaction.channel.send(embed=embed)
await msg.add_reaction("❌")
def check(reaction, user):
return (
user == interaction.user
and reaction.message.id == msg.id
and str(reaction.emoji) == "❌"
)
try:
reaction, user = await bot.wait_for("reaction_add", check=check, timeout=60.0)
except asyncio.TimeoutError:
pass
else:
if str(reaction.emoji) == "❌":
await msg.delete()