-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.py
232 lines (205 loc) · 11.2 KB
/
view.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import discord
from discord.ext import commands
from discord.ui import button, View
from discord import Embed
import wavelink
import asyncio
class PlaylistView(View):
def __init__(self, ctx, player, playlist, track):
super().__init__(timeout=120)
self.player = player
self.user_id = ctx.author.id
self.track = track
self.ctx = ctx
self.playlist = playlist
async def on_timeout(self):
self.stop()
@button(label="ADD SONG", style=discord.ButtonStyle.grey, emoji="🎵")
async def add_one(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
await self.player.play(self.track)
embed = Embed(title="🎶 Now playing", description=f"`{self.track.title}`", color=discord.Color.blue())
embed.set_footer(text=f"{len(self.player.queue)} songs in the queue.")
embed.set_image(url=self.track.thumb)
await interaction.response.send_message(embed=embed, view=PlayingView(self.ctx, self.player))
self.stop()
@button(label="ADD ALL", style=discord.ButtonStyle.grey, emoji="🎶")
async def add_all_queue(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
self.player.queue(self.playlist)
await self.player.play(self.playlist.tracks[0])
embed = Embed(title=f"{len(self.playlist.tracks)} Songs", description=f"Added to queue from `{self.playlist.name.title()}` playlist.", color=discord.Color.blue())
embed.set_footer(text=f"{len(self.player.queue)} songs in the queue.")
embed.set_image(url=self.playlist.tracks[0].thumb)
await interaction.response.send_message(embed=embed)
self.stop()
class PlaylistPlayingView(View):
def __init__(self, ctx, player, playlist, track):
super().__init__(timeout=120)
self.player = player
self.track = track
self.user_id = ctx.author.id
self.playlist = playlist
async def on_timeout(self):
self.stop()
@button(label="ADD SONG", style=discord.ButtonStyle.grey, emoji="🎵")
async def add_one2(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
if self.player.is_paused():
self.player.queue(self.track)
else:
await self.player.play(self.track)
embed = Embed(title=f"➕ Added to queue", description=f"`{self.track.title}`", color=discord.Color.blue())
embed.set_image(url=self.track.thumb)
embed.set_footer(text=f"{len(self.player.queue)} songs in the queue.")
await interaction.response.send_message(embed=embed)
self.stop()
@button(label="ADD ALL", style=discord.ButtonStyle.grey, emoji="🎶")
async def add_all_queue2(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
if self.player.is_paused():
self.player.queue(self.playlist)
else:
self.player.queue(self.playlist)
await self.player.play(self.playlist.tracks[0])
self.player.queue(self.playlist)
embed = Embed(title=f"{len(self.playlist.tracks)} Songs", description=f"Added to queue from `{self.playlist.name.title()}` playlist.", color=discord.Color.blue())
embed.set_footer(text=f"{len(self.player.queue)} songs in the queue.")
embed.set_image(url=self.playlist.tracks[0].thumb)
await interaction.response.send_message(embed=embed)
self.stop()
class PlayingView(View):
def __init__(self, ctx, player):
super().__init__(timeout=None)
self.player = player
self.user_id = ctx.author.id
self.ctx = ctx
async def on_timeout(self):
self.stop()
@button(style=discord.ButtonStyle.grey, emoji="⏮️", row=0)
async def _previoustrack(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
try:
if self.player and len(self.player.queue.history) > 0:
prev_track = self.player.queue.history[-2] # Get the last song in the history
curr_track = self.player.current
self.player.queue.put_at_front(curr_track)
await self.player.play(prev_track)
await asyncio.sleep(1)
await interaction.response.send_message(f"```⏮️ Playing {prev_track.title}```", ephemeral=True)
except:
return await interaction.response.send_message("```⛔ Error! No previous track or not connected.```", ephemeral=True)
@button(style=discord.ButtonStyle.grey, emoji="⏯️", row=0)
async def play_pause(self, interaction: discord.Interaction, button: discord.ui.Button):
player: wavelink.Player = self.ctx.guild.voice_client
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
if not player.is_playing():
await player.resume()
await interaction.response.send_message("```▶️ Resumed.```", ephemeral=True)
elif player.is_playing():
await player.pause()
await interaction.response.send_message("```⏸️ Paused.```", ephemeral=True)
else:
return await interaction.response.send_message("```⛔ Error! No track or not connected.```", ephemeral=True)
@button(style=discord.ButtonStyle.grey, emoji="⏭️", row=0)
async def _nexttrack(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
if self.player and len(self.player.queue) > 0:
next_track = self.player.queue[0]
await self.player.stop(force=True)
await interaction.response.send_message(f"```⏭️ Playing {next_track.title}```", ephemeral=True)
await asyncio.sleep(1)
else:
return await interaction.response.send_message("```⛔ Error! No next track or not connected.```", ephemeral=True)
@button(style=discord.ButtonStyle.grey, emoji="🔀", row=0)
async def _shuffle(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
if self.player and len(self.player.queue) > 0:
self.player.queue.shuffle()
await interaction.response.send_message("```🔀 Queue Shuffled.```")
else:
return await interaction.response.send_message("```⛔ Error! No queue or not connected```", ephemeral=True)
@button(style=discord.ButtonStyle.grey, emoji="🔁", row=0)
async def _repeat(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
if self.player:
if self.player.queue.loop:
self.player.queue.loop = False
await interaction.response.send_message("```🔁 Repeat off.```", ephemeral=True)
else:
self.player.queue.loop = True
await interaction.response.send_message("```🔁 Repeat on.```", ephemeral=True)
else:
return await interaction.response.send_message("```⛔ Error! Not connected```", ephemeral=True)
@button(style=discord.ButtonStyle.grey, emoji="🔈", row=1)
async def _volumedown(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
volume = self.player.volume
new_volume = (volume - 10)
if new_volume < 0:
return await interaction.response.send_message("```0% Is Lowest```")
else:
await interaction.response.send_message(f"```🔈 Decreased to {new_volume}%```", ephemeral=True)
await self.player.set_volume(new_volume)
@button(style=discord.ButtonStyle.grey, emoji="🔊", row=1)
async def _volumeup(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("Only command caller can do that.", ephemeral=True)
volume = self.player.volume
new_volume = (volume + 10)
if new_volume > 100:
return await interaction.response.send_message("```100% Is Highest.```")
else:
await interaction.response.send_message(f"```🔊 Increased to {new_volume}%```", ephemeral=True)
await self.player.set_volume(new_volume)
@button(style=discord.ButtonStyle.grey, emoji="🧹", row=1)
async def _clearqueue(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("```Only command caller can do that.```", ephemeral=True)
self.player.queue.reset()
await interaction.response.send_message("```Queue cleared!```", ephemeral=True)
@button(style=discord.ButtonStyle.grey, emoji="🚫", row=1)
async def _dc(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message("```Only command caller can do that.```", ephemeral=True)
await self.player.disconnect()
await interaction.response.send_message("```🚫 Disconnected```", ephemeral=True)
class InviteButton(View):
def __init__(self, inv: str):
super().__init__()
self.inv = inv
self.add_item(discord.ui.Button(label = "Invite", url = self.inv))
@button(label="Support", style=discord.ButtonStyle.blurple)
async def supportButton(self, interaction: discord.Interaction, button: discord.ui.Button):
url = "https://discord.gg/atlasdev"
await interaction.response.send_message(url, ephemeral=True)
class QueueView(View):
def __init__(self, ctx, player):
super().__init__(timeout=None)
self.ctx = ctx
self.player = player
self.page = 0
async def show_queue_page(self):
queue = self.player.queue
total_pages = len(queue)
@button(style=discord.ButtonStyle.grey, emoji="⬅️")
async def prev_page(self):
if self.page > 0:
self.page -= 1
await self.show_queue_page()
@button(style=discord.ButtonStyle.grey, emoji="➡️")
async def next_page(self):
total_pages = (len(self.player.queue) - 1) // 10 + 1
if self.page < total_pages - 1:
self.page += 1
await self.show_queue_page()