async def f_ct_add(self, ctx, start_index, last_index=None): '''adds a sub queue of fullqueue to the end of the queue. if not last_index then only 1 song added''' state = TempState(ctx.author.guild) if not last_index: last_index = start_index try: start_index, last_index = int(start_index), int(last_index) except: await ctx.send("NUMBERS GODDAMN NUMBERS") return queue = state.full_queue if start_index > 0 and last_index > 0 and start_index <= len( queue) and last_index <= len( queue) and last_index >= start_index: temp = queue[start_index - 1:last_index] queue = state.queue queue_ct = state.queue_ct queue_ct += temp for i in temp: if type(i).__name__ == "YoutubePlaylist": queue += [f"--{i.title}--" ] + i._entries + [f"--{i.title}--"] else: queue += [i] state.queue = queue state.queue_ct = queue_ct else: await ctx.send( "The number you entered is just as irrelevant as your existence." ) return
async def replace(self, ctx, change1, change2): '''Replaces two queue members.''' state = TempState(ctx.author.guild) try: change1, change2 = int(change1), int(change2) except: await ctx.send("NUMBERS GODDAMN NUMBERS") return queue = [x for x in state.queue if type(x) != str] if change1 > 1 and change2 > 1 and change1 <= len( queue) and change2 <= len(queue): squeue = state.queue squeue[squeue.index(queue[change1 - 1])], squeue[squeue.index( queue[change2 - 1])] = squeue[squeue.index( queue[change2 - 1])], squeue[squeue.index(queue[change1 - 1])] state.queue = squeue await ctx.send( f">>> Switched the places of **{queue[change2-1].title}** and **{queue[change1-1].title}**" ) else: await ctx.send( "The numbers you entered are just as irrelevant as your existence." ) return
async def f_add(self, ctx, start_index, last_index=None): '''adds a sub queue of fullqueue to the end of the queue. if not last_index then only 1 song added''' state = TempState(ctx.author.guild) if not last_index: last_index = start_index try: start_index, last_index = int(start_index), int(last_index) except: await ctx.send("NUMBERS GODDAMN NUMBERS") return queue = state.full_queue if start_index > 0 and last_index > 0 and start_index <= len( queue) and last_index <= len( queue) and last_index >= start_index: temp = queue[start_index - 1:last_index] queue = state.queue queue_ct = state.queue_ct queue += temp queue_ct += temp state.queue = queue state.queue_ct = queue_ct else: await ctx.send( "The number you entered is just as irrelevant as your existence." ) return
async def f_now(self, ctx, start_index, last_index=None): '''Plays a sub queue Now. if not last_index then only 1 song played''' state = TempState(ctx.author.guild) if not last_index: last_index = start_index try: start_index, last_index = int(start_index), int(last_index) except: await ctx.send("NUMBERS GODDAMN NUMBERS") return queue = state.full_queue if start_index > 0 and last_index > 0 and start_index <= len( queue) and last_index <= len( queue) and last_index >= start_index: temp = queue[start_index - 1:last_index] queue = state.queue queue_ct = state.queue_ct if type(queue_ct[0]).__name__ == "YoutubeVideo": queue_ct.pop(0) queue.remove([x for x in queue if type(x) != str][0]) queue = temp + queue queue_ct = temp + queue_ct state.queue = queue state.queue_ct = queue_ct else: await ctx.send( "The number you entered is just as irrelevant as your existence." ) return await ctx.invoke(self.client.get_command("restart"))
async def generic_play(self, ctx, url): """This commands tries its hardest to play any video (not just YouTube), provided the link""" if not (await ctx.invoke(self.client.get_command("join"))): return voice = get(self.client.voice_clients, guild=ctx.guild) ydl_opts = {"quiet": True, "no_warnings": True} try: info = youtube_dl.YoutubeDL(ydl_opts).extract_info(url, download=False) except: await ctx.send("cant play that") return need = [ "id", "uploader", "upload_date", "title", "thumbnail", "duration", "description", "webpage_url", "view_count", "like_count", "dislike_count", "thumbnails", "format_id", "url", "ext" ] info2 = {} for i in need: if i in info: info2[i] = info[i] else: info2[i] = "0" try: vid = self.client.get_cog("Play").ytvid(info2["id"], info2, ctx.author.name) embed = discord.Embed( title=f"{vid.title} ({vid.duration}) - {vid.uploader}", url=vid.url, description=vid.description, color=discord.Colour.blurple()) embed.set_author(name="Me!Me!Me!", icon_url=self.client.user.avatar_url) embed.set_footer( text=f"Requested By: {ctx.message.author.display_name}", icon_url=ctx.message.author.avatar_url) embed.set_thumbnail(url=vid.thumbnail) embed.add_field(name="Date of Upload", value=vid.date) embed.add_field(name="Views", value=vid.views) embed.add_field(name="Likes/Dislikes", value=f"{vid.likes}/{vid.dislikes}") await ctx.send(embed=embed) if TempState(ctx.guild).queue == []: TempState(ctx.guild).queue += [vid] await self.client.get_cog("Play").player(ctx, voice) else: TempState(ctx.guild).queue += [vid] except: await ctx.send("cant play that") return
async def seek(self, ctx, time): """Go to a timestamp in the current song""" state = TempState(ctx.author.guild) queue = [x for x in state.queue if type(x) != str] voice = get(self.client.voice_clients, guild=ctx.guild) time = await self.int_time(ctx, time) if time: voice.source = discord.FFmpegPCMAudio(queue[0].audio_url, executable="./Bin/ffmpeg.exe", before_options=f"-loglevel quiet -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5 -ss {time}") state.time = time else: return
async def lyrics(self, ctx: commands.Context): """Get lyrics to the currently playing song (or not, depends on the song)""" state = TempState(ctx.author.guild) queue = [x for x in state.queue if type(x) != str] vid = queue[0] song = genius.search_song(vid.title) if not song: await ctx.send( "Can't Find lyrics. Try using choose-lyrics command.") return lyrics = song.lyrics embed = discord.Embed(title=f"LYRICS - {song.title}", url=song.url, color=discord.Colour.blurple()) embed.set_author(name="Me!Me!Me!", icon_url=self.client.user.avatar_url) embed.set_footer( text=f"Requested By: {ctx.message.author.display_name}", icon_url=ctx.message.author.avatar_url) embed_msg = await ctx.send(embed=embed) await self.client.get_cog("Queue").embed_pages(ctx=ctx, _content=lyrics, embed_msg=embed_msg, wait_time=120)
async def next(self, ctx): '''Skips the current song and plays the next song in the queue. Requires atleast 50% of people to vote yes ''' state = TempState(ctx.author.guild) voice = get(self.client.voice_clients, guild=ctx.guild) if voice and voice.is_playing(): state.skip_song = True self.log("Playing next song") voice.stop() await ctx.send(">>> ***Song skipped.***") else: self.log("Skip failed") await ctx.send(">>> Wat you even trynna skip? There is ***nothing to*** skip, I am surrounded by idiots")
async def duration_check(self, ctx, time): state = TempState(ctx.author.guild) queue = [x for x in state.queue if type(x) != str] try: if ":" in time: tl = list(map(int, time.split(":"))) if tl[-1] > 59 or tl[-2] > 59 or tl[-1] < 0 or tl[-2] < 0: await ctx.send("Seek in the format HH:MM:SS or S or something i don't know but this is incorrect.") return False elif time.count(":") > 2: await ctx.send("Seek in the format HH:MM:SS or S or something i don't know but this is incorrect.") return False elif time.count(":") == 2: sec = queue[0].seconds if tl[0]*60*60 + tl[1]*60 + tl[2] > sec: await ctx.send("Entered a wrong time I guess.") return False elif time.count(":") == 1: sec = queue[0].seconds if tl[0]*60 + tl[1] > sec: await ctx.send("Entered a wrong time I guess.") return False else: if int(time) > queue[0].seconds: await ctx.send("Entered a wrong time I guess.") return False except Exception as e: await ctx.send("Seek in the format HH:MM:SS or S or something i don't know but this is incorrect.") return False else: return True
async def fullct(self, ctx): state = TempState(ctx.author.guild) if ctx.invoked_subcommand is None: i = 0 desc = "" while i < len(state.full_queue_ct): desc += f"{i+1}. {state.full_queue_ct[i].title} ({state.full_queue_ct[i].duration}) \n" i += 1 desc_l = [] for chunk in list(self.chunks(desc.split("\n"), n=5)): desc_l.append("\n".join(chunk)) embed = discord.Embed(title="QUEUE", color=discord.Colour.dark_purple()) embed.set_author(name="Me!Me!Me!", icon_url=self.client.user.avatar_url) embed.set_thumbnail(url=self.music_logo) embed.set_footer( text=f"Requested By: {ctx.message.author.display_name}", icon_url=ctx.message.author.avatar_url) embed_msg = await ctx.send(embed=embed) await self.embed_pages(_content=desc_l, ctx=ctx, embed_msg=embed_msg, wait_time=120)
async def ct_remove(self, ctx, remove): '''Removes the Queue member.''' state = TempState(ctx.author.guild) try: remove = int(remove) except: await ctx.send("NUMBERS GODDAMN NUMBERS") return queue = state.queue_ct squeue = state.queue if remove > 0 and remove <= len(queue): temp = queue[remove - 1] queue.remove(temp) if type(temp).__name__ == "YoutubeVideo": if remove == 1: await ctx.send( "The number you entered is just as irrelevant as your existence." ) return squeue.remove(temp) await ctx.send( f">>> Removed **{(temp.title)}** from the queue.") else: if remove == 1: for i in squeue: if i == f"--{temp.title}--": vid = [x for x in state.queue if type(x) != str][0] squeue = [vid] + squeue queue = [vid] + queue break elif type(i).__name__ == "YoutubeVideo" or type( i).__name__ == "YoutubePlaylist": break i1 = squeue.index(f"--{temp.title}--") i2 = squeue[i1 + 1:].index(f"--{temp.title}--") squeue[i1:i1 + i2 + 2] = [] state.queue = squeue state.queue_ct = queue else: await ctx.send( "The number you entered is just as irrelevant as your existence." ) return
async def restart(self, ctx): '''Restarts the current song.''' state = TempState(ctx.author.guild) voice = get(self.client.voice_clients, guild=ctx.guild) if voice: temp = state.loop_song state.loop_song = True voice.stop() if ctx.author.guild in gen.time_l: gen.time_l.remove(ctx.author.guild) state.time = 0 await asyncio.sleep(0.01) state.loop_song = temp else: self.log("Restart failed") await ctx.send(">>> Ya know to restart stuff, stuff also needs to be playing first.")
async def back(self, ctx): '''Plays previous song.''' state = TempState(ctx.author.guild) voice = get(self.client.voice_clients, guild=ctx.guild) if voice: state.queue = [state.full_queue[-1]] + state.queue if not voice.is_playing(): if len(state.queue) == 1: play = self.client.get_cog("Play") await play.player(ctx, voice) elif voice.is_paused(): voice.resume() await ctx.invoke(self.client.get_command("restart")) else: await ctx.invoke(self.client.get_command("restart"))
async def remove(self, ctx, remove): '''Removes the Queue member.''' state = TempState(ctx.author.guild) try: remove = int(remove) except: await ctx.send("NUMBERS GODDAMN NUMBERS") return queue = [x for x in state.queue if type(x) != str] if remove > 1 and remove <= len(queue): queue2 = state.queue queue2.remove(queue[remove - 1]) state.queue = queue2 await ctx.send( f">>> Removed **{(queue[remove - 1].title)}** from the queue.") else: await ctx.send( "The number you entered is just as irrelevant as your existence." ) return
async def ct_now(self, ctx, change): '''Plays a queue member NOW.''' state = TempState(ctx.author.guild) try: change = int(change) except: await ctx.send("NUMBERS GODDAMN NUMBERS") return queue = state.queue_ct squeue = state.queue if change > 1 and change <= len(queue): temp1 = queue[change - 1] temp2 = queue[0] queue.pop(change - 1) queue.insert(0, temp1) squeue.remove([x for x in squeue if type(x) != str][0]) if type(temp1).__name__ == "YoutubeVideo": squeue.remove(temp1) squeue.insert(0, temp1) else: i11 = squeue.index(f"--{temp1.title}--") i12 = squeue[i11 + 1:].index(f"--{temp1.title}--") pl = squeue[i11:i12 + i11 + 2] squeue[i11:i12 + i11 + 2] = [] squeue = pl + squeue if type(temp2).__name__ == "YoutubeVideo": queue.remove(temp2) state.queue = squeue state.queue_ct = queue else: await ctx.send( "The number you entered is just as irrelevant as your existence." ) return await ctx.invoke(self.client.get_command("restart"))
async def now(self, ctx, change): '''Plays a queue member NOW.''' state = TempState(ctx.author.guild) try: change = int(change) except: await ctx.send("NUMBERS GODDAMN NUMBERS") return queue = [x for x in state.queue if type(x) != str] if change > 1 and change <= len(queue): temp = queue[change - 1] queue2 = state.queue queue2.remove(temp) queue2.remove(queue[0]) queue2.insert(0, temp) state.queue = queue2 else: await ctx.send( "The number you entered is just as irrelevant as your existence." ) return await ctx.invoke(self.client.get_command("restart"))
async def auto_voice_handler(self): for guild in self.client.guilds: state = TempState(guild) voice = get(self.client.voice_clients, guild=guild) if voice: if self.disconnect_check(voice): awoo_channel = GuildState(guild).voice_text_channel if voice.is_playing(): state.voice_handler_time += 1 if state.voice_handler_time == int(GuildState(guild).auto_pause_time): voice.pause() if guild in gen.time_l: gen.time_l.remove(guild) self.log("Player AUTO paused") state.paused_by_handler = True if awoo_channel: await awoo_channel.send(f"Everyone left `{voice.channel.name}`, player paused.") elif voice.is_paused(): state.voice_handler_time += 1 if state.voice_handler_time == int(GuildState(guild).auto_disconnect_time): state.queue = [] state.full_queue = [] state.queue_ct = [] state.full_queue_ct = [] await voice.disconnect() self.log("Player AUTO Disconnected") if awoo_channel: await awoo_channel.send(f"player disconnected.") else: if state.voice_handler_time > 0: state.voice_handler_time = 0 if state.paused_by_handler: state.voice_handler_time = 0 voice.resume() if guild not in gen.time_l: gen.time_l.append(guild) state.paused_by_handler = False
async def shuffle(self, ctx, amount: int = None): state = TempState(ctx.author.guild) """Shuffle the current queue""" state.queue = [x for x in state.queue if type(x) != str] state.queue_ct = state.queue[:] next_queue = state.queue[1:] random.shuffle(next_queue) state.queue = [state.queue[0]] + next_queue if amount and amount > 0: state.shuffle_lim = amount
async def rewind(self, ctx, time): """Go back by given seconds in the current song""" state = TempState(ctx.author.guild) queue = [x for x in state.queue if type(x) != str] voice = get(self.client.voice_clients, guild=ctx.guild) time = await self.int_time(ctx, time) if time: if time <= state.time: voice.source = discord.FFmpegPCMAudio( queue[0].audio_url,executable="./Bin/ffmpeg.exe", before_options=f"-loglevel quiet -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5 -ss {state.time - time}") state.time -= time else: await ctx.send("The seek is greater than the song limit.") else: return
async def leave(self, ctx): '''Leaves the voice channel.''' state = TempState(ctx.author.guild) voice = get(self.client.voice_clients, guild=ctx.guild) if voice and voice.is_connected(): state.queue = [] state.full_queue = [] state.queue_ct = [] state.full_queue_ct = [] if voice.is_playing(): voice.stop() await voice.disconnect() if ctx.author.guild in gen.time_l: gen.time_l.remove(ctx.author.guild) state.time = 0 state.shuffle_lim = None await ctx.send(f">>> Left ```{voice.channel.name}```") else: await ctx.send(">>> I cannot leave a voice channel I have not joined, thought wouldn't need to explain basic shit like this.")
async def _import(self, ctx, url): """Have your playlist saved as text, provide a pastebin url to play the playlist""" if not (await ctx.invoke(self.client.get_command("join"))): return voice = get(self.client.voice_clients, guild=ctx.guild) response = requests.get(url) content = response.content.decode("utf-8") try: content = json.loads(content) except: await ctx.send("Please recheck your link.") return if type(content) != list: await ctx.send("Please recheck your link.") return for i in content: if type(i) != dict: await ctx.send("Please recheck your link.") return if "title" not in i or "url" not in i: await ctx.send("Please recheck your link.") return for i in content: query = i["url"] if "http" in query: if "www.youtube.com" in query: split_list = re.split("/|=|&", query) if "watch?v" in split_list: vid = self.client.get_cog("Play").ytvid( split_list[split_list.index("watch?v") + 1], requested_by=ctx.author.name) state = TempState(ctx.author.guild) state.queue += [vid] state.queue_ct += [vid] if len(state.queue) == 1: await self.client.get_cog("Play").player( ctx, voice)
async def hard_stop(self, ctx): '''Stops the current music AND clears the current queue.''' state = TempState(ctx.author.guild) voice = get(self.client.voice_clients, guild=ctx.guild) state.queue = [] state.full_queue = [] state.queue_ct = [] state.full_queue_ct = [] if voice and voice.is_playing: self.log("Player stopped") voice.stop() if ctx.author.guild in gen.time_l: gen.time_l.remove(ctx.author.guild) state.time = 0 state.shuffle_lim = None await ctx.send(">>> Music stopped") else: self.log("Stop failed") await ctx.send(">>> Ya know to stop stuff, stuff also needs to be playing first.")
async def download(self, ctx, *, query=None): '''Downloads a song for you, so your pirated ass doesn't have to look for it online.''' if query: if "http" in query: if "www.youtube.com" in query: split_list = re.split("/|=|&", query) if "watch?v" in split_list: vid = self.client.get_cog("Play").ytvid( split_list[split_list.index("watch?v") + 1], requested_by=ctx.author.name) else: vid = await self.client.get_cog("Play").searching(ctx, query) else: vid = TempState(ctx.guild).queue[0] if not os.path.exists(self.DPATH): os.makedirs(self.DPATH) if vid.seconds > 420: await ctx.send("Song you requested was too mega for me uwu.") return async with aiohttp.ClientSession() as cs: async with cs.get(vid.audio_url) as r: data = await r.read() filename = f"{self.DPATH}\\{vid.id}.{vid.ext}" with open(filename, 'wb+') as temp: temp.write(b"") temp.write(data) file = discord.File(filename, filename=f'{vid.title}.mp3') try: await ctx.send(file=file) except discord.Forbidden: await ctx.send( "Song you requested was too mega, only files less than 8MB can be sent." ) os.remove(filename)
async def export(self, ctx, isFull="queue"): """Convert your playlist to text, gives a pastebin url""" if not (isFull.lower() == "full" or isFull.lower() == "queue" or isFull.lower() == "q"): await ctx.send("only full or q or queue") return state = TempState(ctx.guild) if isFull.lower() == "full": queue = state.full_queue else: queue = [x for x in state.queue if type(x) != str] for i in range(len(queue)): queue[i] = {"url": queue[i].url, "title": queue[i].title} url = "https://hastebin.com/documents" response = requests.post(url, data=json.dumps(queue)) try: the_page = "https://hastebin.com/raw/" + response.json()['key'] await ctx.send(f"Here is your page Master, {the_page}") except: await ctx.send(f"Cant export")
async def loop_queue(self, ctx, toggle=""): '''Loops the queue. If on/off not passed it will toggle it.''' state = TempState(ctx.author.guild) if toggle.lower() == "on": state.loop_q = True await ctx.send(">>> **Looping queue now**") elif toggle.lower() == 'off': state.loop_q = False await ctx.send(">>> **NOT Looping queue now**") else: if state.loop_q: state.loop_q = False await ctx.send(">>> **NOT Looping queue now**") else: state.loop_q = True await ctx.send(">>> **Looping queue now**")
async def loop(self, ctx, toggle=""): state = TempState(ctx.author.guild) '''Loops the current song, doesn't affect the skip command tho. If on/off not passed it will toggle it.''' if toggle.lower() == "on": state.loop_song = True await ctx.send(">>> **Looping current song now**") elif toggle.lower() == 'off': state.loop_song = False await ctx.send(">>> **NOT Looping current song now**") else: if state.loop_song: state.loop_song = False await ctx.send(">>> **NOT Looping current song now**") else: state.loop_song = True await ctx.send(">>> **Looping current song now**")
async def clyrics(self, ctx: commands.Context, query=None): """Get the lyrics not ANY(susceptible to terms and conditions) song.""" state = TempState(ctx.author.guild) if not query and state.queue == []: await ctx.send("no song sad lyf") elif not query: query = state.queue[0].title title = query response = genius.search_genius_web(title) hits = response['sections'][0]['hits'] sections = sorted(response['sections'], key=lambda sect: sect['type'] == "song", reverse=True) hits = [ hit for section in sections for hit in section['hits'] if hit['type'] == "song" ][0:5] if hits == []: await ctx.send("Can't Find lyrics. Use different name of the song." ) return async def reactions_add(message, reactions): for reaction in reactions: await message.add_reaction(reaction) wait_time = 60 reactions = {"1️⃣": 1, "2️⃣": 2, "3️⃣": 3, "4️⃣": 4, "5️⃣": 5} embed = discord.Embed(title="Search returned the following", color=discord.Colour.dark_green()) embed.set_author(name="Me!Me!Me!", icon_url=self.client.user.avatar_url) embed.set_footer( text=f"Requested By: {ctx.message.author.display_name}", icon_url=ctx.message.author.avatar_url) embed.set_thumbnail(url=self.music_logo) embed_msg = await ctx.send(embed=embed) for index, result in enumerate(hits): result = result["result"] embed.add_field( name=f"*{index + 1}.*", value= f"**{result['title_with_featured']} - {result['primary_artist']['name']}**", inline=False) await embed_msg.edit(content="", embed=embed) self.client.loop.create_task( reactions_add(embed_msg, list(reactions.keys())[:len(hits)])) while True: try: reaction, user = await self.client.wait_for( 'reaction_add', timeout=wait_time, check=lambda reaction, user: user == ctx.author and reaction.message.id == embed_msg.id) except TimeoutError: await ctx.send( f">>> I guess no ones wants to see some sweet lyrics.") await embed_msg.delete() return None else: await embed_msg.remove_reaction(str(reaction.emoji), ctx.author) if str(reaction.emoji) in reactions.keys(): await embed_msg.delete(delay=3) hit = hits[reactions[str(reaction.emoji)] - 1] song_info = hit["result"] lyrics = genius._scrape_song_lyrics_from_url( song_info['url']) song = Song(song_info, lyrics) embed = discord.Embed( title= f"LYRICS - {song.title} - {song.artist}", # TODO make a function url=song.url, description="", color=discord.Colour.blurple()) embed.set_author(name="Me!Me!Me!", icon_url=self.client.user.avatar_url) embed.set_footer( text=f"Requested By: {ctx.message.author.display_name}", icon_url=ctx.message.author.avatar_url) embed_msg = await ctx.send(embed=embed) await self.client.get_cog("Queue").embed_pages( ctx=ctx, _content=lyrics, embed_msg=embed_msg, wait_time=120)
async def player(self, ctx, voice): #! checks queue and plays the song accordingly state = TempState(ctx.guild) def check_queue(): #! deletes 1st element of list if (not state.loop_song) or (state.skip_song): if state.skip_song: state.skip_song = False try: queue = [x for x in state.queue if not type(x) == str] temp = queue[0] queue2 = state.queue queue2.remove(temp) state.queue = queue2 if state.full_queue == []: state.full_queue += [temp] elif state.full_queue[-1] != temp: state.full_queue += [temp] if state.loop_q: state.queue += [temp] if temp in state.queue_ct: queue2 = state.queue_ct queue2.remove(temp) state.queue_ct = queue2 if state.full_queue_ct == []: state.full_queue_ct += [temp] elif state.full_queue_ct[-1] != temp: state.full_queue_ct += [temp] if state.loop_q: state.queue_ct += [temp] clear_pl(state) except: pass fut = asyncio.run_coroutine_threadsafe( self.player(ctx, voice), ctx.bot.loop) try: fut.result() except: pass flag = True while flag: queue = [x for x in state.queue if not type(x) == str] #! plays the song if queue != []: try: ch = ctx.States.Guild.voice_text_channel if ch is not None and not ch == "disabled": await ch.send(f"{queue[0].title} playing now.") else: if ch == "disabled": pass else: await ctx.send(f"{queue[0].title} playing now.") self.log("Downloaded song.") voice.play(discord.FFmpegPCMAudio(queue[0].audio_url, executable="./Bin/ffmpeg.exe", before_options="-loglevel quiet -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5"), after=lambda e: check_queue()) state.time = 0 if ctx.author.guild not in gen.time_l: gen.time_l.append(ctx.guild) if state.shuffle_lim: state.shuffle_var += 1 if state.shuffle_var == state.shuffle_lim: await ctx.invoke(self.client.get_command("shuffle")) state.shuffle_var = 0 self.log(f"{queue[0].title} is playing.") voice.source = discord.PCMVolumeTransformer(voice.source) except Exception as e: print(e.error) self.log(e) self.log(f"{queue[0].title} cannot be played.") ch = ctx.States.Guild.voice_text_channel if ch is not None and not ch == "disabled": await ch.send(f"{queue[0].title} cannot be played.") else: if ch == "disabled": pass else: await ctx.send(f"{queue[0].title} cannot be played.") queue2 = state.queue queue2.remove(queue[0]) state.queue = queue2 if queue[0] in state.queue_ct: queue2 = state.queue_ct queue2.remove(queue[0]) state.queue_ct = queue2 queue.pop(0) else: flag = False else: ch = ctx.States.Guild.voice_text_channel if ch is not None and not ch == "disabled": await ch.send(">>> All songs played. No more songs to play.") else: if ch == "disabled": pass else: await ctx.send(">>> All songs played. No more songs to play.") self.log("Ending the queue") if ctx.author.guild in gen.time_l: gen.time_l.remove(ctx.guild) state.time = 0 break
async def juke_update(self): for guild in self.client.guilds: state = GuildState(guild) voice = get(self.client.voice_clients, guild=guild) if state.jb_channel and voice: tstate = TempState(guild) queue = [x for x in tstate.queue if type(x) != str] if state.jb_embed_id: embed_msg = await state.jb_channel.fetch_message( state.jb_embed_id) if embed_msg: if tstate.old_queue_embed != tstate.queue: tstate.old_queue_embed = tstate.queue if queue == []: embed = discord.Embed( title="Not Playing Anything right now.", color=discord.Colour.from_rgb(0, 255, 255)) embed.set_image(url=self.juke_box_url) await embed_msg.edit(embed=embed) else: vid = queue[0] embed = discord.Embed( title=vid.title, color=discord.Colour.from_rgb(0, 255, 255)) embed.set_image(url=vid.thumbnail) await embed_msg.edit(embed=embed) else: state.jb_embed_id = None if state.jb_queue_id: queue_msg = await state.jb_channel.fetch_message( state.jb_queue_id) if queue_msg: if tstate.old_queue_queue != tstate.queue: tstate.old_queue_queue = tstate.queue if queue == []: await queue_msg.edit(content="__QUEUE LIST__") else: string = "__QUEUE__\n" for index in range(len(tstate.queue)): i = tstate.queue[index] ostring = string[:] string += f"{index+1}. {i.title} ({i.duration}) - Requested by `{i.requester}`\n" if len(string) > 2000: string = ostring break await queue_msg.edit(content=string) else: state.jb_queue_id = None if state.jb_loading_id: loading_msg = await state.jb_channel.fetch_message( state.jb_loading_id) if loading_msg: if voice.is_playing(): if queue != []: vid = queue[0] def two_dig(number): if number < 10: return f"0{number}" else: return str(number) if vid.duration.count(":") == 1: ntime = f"{tstate.time//60}:{two_dig(tstate.time%60)}" else: ntime = f"{tstate.time//3600}:{two_dig(tstate.time%3600//60)}:{two_dig(tstate.time//60)}" ntime = str(timedelta(seconds=tstate.time)) amt = int(tstate.time / vid.seconds * 10) if vid.seconds != 0 else 0 ntime = ntime.split(":") for i in range(3 - len(vid.duration.split(":"))): ntime.pop(i) ntime = ":".join(ntime) await loading_msg.edit( content= f"{ntime}/{vid.duration} {':black_square_button:'*amt +':black_large_square:'*(10-amt)}" ) else: await loading_msg.edit( content= f"0:00/0:00 - {':black_large_square:'*10}") else: state.jb_loading_id = None
async def now_playing(self, ctx): """Tells you the currently playing song.""" state = TempState(ctx.author.guild) queue = [x for x in state.queue if type(x) != str] if queue == []: await ctx.send("Nothing playing right now, use the play command to play something so it shows up here.") return vid = queue[0] embed = discord.Embed(title="NOW PLAYING", url=vid.url, color=discord.Colour.blurple()) embed.set_author(name="Me!Me!Me!", icon_url=self.client.user.avatar_url) voice = ctx.voice_client volume = round(voice.source.volume * 100) VOLUME_LOWER = 33 VOLUME_UPPER = 66 footer = "" if not voice.is_playing(): footer += " ⏸" else: footer += " ▶" if state.loop_song: footer += " 🔂" if state.loop_q: footer += " 🔁" if state.shuffle_lim is not None: footer += f" 🔀 {state.shuffle_lim}" if volume <= VOLUME_LOWER: footer += " 🔈" elif volume <= VOLUME_UPPER and volume > VOLUME_LOWER: footer += " 🔉" elif volume <= 100 and volume > VOLUME_UPPER: footer += " 🔊" footer += f" {volume}" embed.set_footer(text=footer, icon_url=ctx.message.author.avatar_url) embed.set_thumbnail(url=vid.thumbnail) def two_dig(number): if number < 10: return f"0{number}" else: return str(number) if vid.duration.count(":") == 1: ntime = f"{state.time//60}:{two_dig(state.time%60)}" else: ntime = f"{state.time//3600}:{two_dig(state.time%3600//60)}:{two_dig(state.time//60)}" ntime = str(timedelta(seconds=state.time)) embed.add_field(name=f"{vid.title}", value="** **", inline=False) amt = int(state.time/vid.seconds*10) if vid.seconds != 0 else 0 ntime = ntime.split(":") for i in range(3 - len(vid.duration.split(":"))): ntime.pop(i) ntime = ":".join(ntime) embed.add_field( name=f"{ntime}/{vid.duration} {':black_square_button:'*amt +':black_large_square:'*(10-amt) }", value="** **", inline=False) await ctx.send(embed=embed)