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 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_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_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 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 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 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.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 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 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 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 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 ct_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 = state.queue_ct if change1 > 0 and change2 > 0 and change1 <= len( queue) and change2 <= len(queue): squeue = state.queue if change1 == 1: if type(queue[change1 - 1]).__name__ == "YoutubeVideo": await ctx.send( "The numbers you entered are just as irrelevant as your existence." ) return else: for i in squeue: if i == f"--{queue[change1-1].title}--": vid = [x for x in state.queue if type(x) != str][0] squeue.remove(vid) squeue = [vid] + squeue queue = [vid] + queue change1 += 1 change2 += 1 break elif type(i).__name__ == "YoutubeVideo" or type( i).__name__ == "YoutubePlaylist": break if change2 == 1: if type(queue[change2 - 1]).__name__ == "YoutubeVideo": await ctx.send( "The numbers you entered are just as irrelevant as your existence." ) return else: for i in squeue: if i == f"--{queue[change1-1].title}--": vid = [x for x in state.queue if type(x) != str][0] squeue.remove(vid) squeue = [vid] + squeue queue = [vid] + queue change1 += 1 change1 += 1 break elif type(i).__name__ == "YoutubeVideo" or type( i).__name__ == "YoutubePlaylist": break temp1 = queue[change2 - 1] temp2 = queue[change1 - 1] queue[change1 - 1], queue[change2 - 1] = queue[change2 - 1], queue[change1 - 1] if type(temp1).__name__ == "YoutubeVideo": i11 = squeue.index(temp1) i12 = -1 else: i11 = squeue.index(f"--{temp1.title}--") i12 = squeue[i11 + 1:].index(f"--{temp1.title}--") if type(temp2).__name__ == "YoutubeVideo": i21 = squeue.index(temp2) i22 = -1 else: i21 = squeue.index(f"--{temp2.title}--") i22 = squeue[i21 + 1:].index(f"--{temp2.title}--") squeue[i11:i12 + i11 + 2], squeue[i21:i22 + i21 + 2] = squeue[i21:i22 + i21 + 2], squeue[i11:i12 + i11 + 2] state.queue = squeue state.queue_ct = queue await ctx.send( f">>> Switched the places of **{temp1.title}** and **{temp2.title}**" ) else: await ctx.send( "The numbers you entered are just as irrelevant as your existence." ) return