-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlaybackCM.py
200 lines (166 loc) · 8.41 KB
/
PlaybackCM.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from Helper import *
# Pausar -- pause
@bot.command(name='pause', help='Pausa la canción actual en el canal de voz: +pause')
async def pause(ctx):
if ctx.author.voice is None or ctx.author.voice.channel is None:
embed = discord.Embed(description='No estas en un canal de voz.', color=discord.Color.gold())
return await ctx.send(embed=embed)
vc = ctx.guild.voice_client
if vc and vc.is_playing():
vc.pause()
embed = discord.Embed(description='Pausando la cancion.', color=discord.Color.gold())
await ctx.send(embed=embed)
else:
embed = discord.Embed(description='No hay canción reproduciendose.', color=discord.Color.gold())
await ctx.send(embed=embed)
# Resumir -- +resume
@bot.command(name='resume', help='Reanuda la reproducción de la canción pausada: +resume')
async def resume(ctx):
if ctx.author.voice is None or ctx.author.voice.channel is None:
embed = discord.Embed(description='No estas en un canal de voz.', color=discord.Color.gold())
return await ctx.send(embed=embed)
vc = ctx.guild.voice_client
if vc and vc.is_paused():
vc.resume()
embed = discord.Embed(description='Resumiendo la canción.', color=discord.Color.gold())
await ctx.send(embed=embed)
else:
embed = discord.Embed(description='No hay canción en pausa.', color=discord.Color.gold())
await ctx.send(embed=embed)
# Saltar canción confirmando la accion con el cotejo. +skip
@bot.command(name='skip', help='Salta a la siguiente canción en la cola de reproducción: +skip')
async def skip(ctx):
global song_position
if ctx.author.voice is None or ctx.author.voice.channel is None:
embed = discord.Embed(description='No estas en un canal de voz.', color=discord.Color.gold())
return await ctx.send(embed=embed)
vc = ctx.guild.voice_client
if vc and vc.is_playing():
message = await ctx.send('¿Desea saltar a la siguiente canción? 🤖')
await message.add_reaction('✅')
await message.add_reaction('❌')
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['✅', '❌']
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
embed = discord.Embed(description='Tiempo agotado para saltar la canción.', color=discord.Color.gold())
await ctx.send(embed=embed)
else:
if str(reaction.emoji) == '✅':
vc.stop()
song_position -= 1
if song_position == 0:
song_position += 1
embed = discord.Embed(description='Saltando la canción.', color=discord.Color.gold())
await ctx.send(embed=embed)
elif str(reaction.emoji) == '❌':
embed = discord.Embed(description='No se saltó la canción.', color=discord.Color.gold())
await ctx.send(embed=embed)
else:
embed = discord.Embed(description='No hay canción reproduciendose.', color=discord.Color.gold())
await ctx.send(embed=embed)
# Parar confirmando la accion con el cotejo. +stop
@bot.command(name='stop', help='Detiene la canción actual: +stop')
async def stop(ctx):
global queue, search_result_global, song_position
if ctx.author.voice is None or ctx.author.voice.channel is None:
embed = discord.Embed(description='No estás en un canal de voz.', color=discord.Color.gold())
return await ctx.send(embed=embed)
vc = ctx.guild.voice_client
if vc and vc.is_connected():
if vc.is_playing():
msg = await ctx.send("¿Desea detener la canción? 🤖")
await msg.add_reaction("✅")
await msg.add_reaction("❌")
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["✅","❌"]
try:
reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await ctx.send("Tiempo de espera agotado.")
else:
if str(reaction.emoji) == "✅":
vc.stop()
queue = asyncio.Queue()
search_result_global = None
song_position = 1
embed = discord.Embed(description='Deteniendo...', color=discord.Color.gold())
await ctx.send(embed=embed)
else:
await ctx.send("Cancelado.")
else:
embed = discord.Embed(description='No hay ninguna canción reproduciéndose para detener.', color=discord.Color.gold())
await ctx.send(embed=embed)
else:
embed = discord.Embed(description='No estoy conectado a un canal de voz.', color=discord.Color.gold())
await ctx.send(embed=embed)
# Borrar cola o playlist confirmando la accion con el cotejo. +clearqueue
@bot.command(name='clearqueue', help='Vacia la cola de reproducción: +clearqueue')
async def clearqueue(ctx):
global queue, search_result_global, song_position
if queue.qsize() == 0:
embed = discord.Embed(description='No hay ninguna cola para vaciar.', color=discord.Color.gold())
await ctx.send(embed=embed)
return
embed = discord.Embed(description='¿Estás seguro que deseas vaciar la cola? 🤖', color=discord.Color.gold())
msg = await ctx.send(embed=embed)
await msg.add_reaction('✅')
await msg.add_reaction('❌')
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ('✅', '❌') and reaction.message.id == msg.id
try:
reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await ctx.send('Tiempo de espera alcanzado.')
return
if str(reaction.emoji) == '✅':
previous_queue = queue
queue = asyncio.Queue()
search_result_global = None
song_position = 1
if not previous_queue.empty():
current_song = await previous_queue.get()
queue.put_nowait(current_song)
embed = discord.Embed(description='La cola ha sido vaciada.', color=discord.Color.gold())
await ctx.send(embed=embed)
elif str(reaction.emoji) == '❌':
await ctx.send('Acción cancelada.')
# Desconectar al bot del canal de voz confirmando la accion con el cotejo. +leave
@bot.command(name='leave', help='Desconecta al bot del canal de voz actual: +leave')
async def leave(ctx):
global song_position
if ctx.author.voice is not None:
vc = ctx.author.voice.channel
else:
embed = discord.Embed(description='No estas en un canal de voz.', color=discord.Color.gold())
await ctx.send(embed=embed)
return
def check(reaction, user):
return user == ctx.author and (str(reaction.emoji) == '✅' or str(reaction.emoji) == '❌')
msg = await ctx.send('¿Estas seguro de que deseas desconectarme? 🤖')
await msg.add_reaction('✅')
await msg.add_reaction('❌')
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
embed = discord.Embed(description='Tiempo agotado.', color=discord.Color.gold())
await ctx.send(embed=embed)
return
if str(reaction.emoji) == '✅':
song_position = 1
await vc.guild.voice_client.disconnect()
embed = discord.Embed(description='Desconectando...', color=discord.Color.gold())
await ctx.send(embed=embed)
elif str(reaction.emoji) == '❌':
embed = discord.Embed(description='Cancelado.', color=discord.Color.gold())
await ctx.send(embed=embed)
@bot.command(name='help')
async def custom_help(ctx):
embed = discord.Embed(title='Comandos del Bot', color=0x42F56C)
# Añade el comando 'play' primero
embed.add_field(name=f"**play**", value=bot.get_command('play').help, inline=False)
for command in bot.commands:
if command.name not in ('play', 'help'):
embed.add_field(name=f"**{command.name}**", value=command.help, inline=False)
await ctx.send(embed=embed)