Пример #1
0
    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
Пример #2
0
 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.")
Пример #3
0
    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.")
Пример #4
0
    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.")
Пример #5
0
    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