aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/music/skip.py
blob: f48218be7b1448e65a959d092f77277ad1d44423 (plain) (blame)
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
from discord.ext import commands
import discord

class Skip(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.queues = {}

    def get_queue(self, guild_id):
        return self.queues.setdefault(guild_id, [])

    def play_next(self, ctx, vc, guild_id):
        queue = self.get_queue(guild_id)
        if queue:
            _, _, file_path = queue[0]
            def after_playing(error=None):
                if queue:
                    queue.pop(0)
                if queue:
                    _, _, next_file = queue[0]
                    if not vc.is_playing():
                        vc.play(discord.FFmpegPCMAudio(next_file), after=after_playing)
            if not vc.is_playing():
                vc.play(discord.FFmpegPCMAudio(file_path), after=after_playing)

    @commands.slash_command(name="pomiń", description="przeskocz do nastepnej melodyji")
    async def pomin(self, ctx):
        guild_id = ctx.guild.id
        vc = ctx.voice_client
        if vc and vc.is_playing():
            queue = self.get_queue(guild_id)
            if queue:
                queue.pop(0)
                if queue:
                    vc.stop()
                    self.play_next(ctx, vc, guild_id)
                    await ctx.respond("przeskoczono do nastepnej melodyji")
                else:
                    await ctx.respond("koleyjka jest pustawa")
                    await vc.disconnect()
            else:
                await ctx.respond("nic nie gra")
        else:
            await ctx.respond("nic nie gra")

def setup(bot):
    bot.add_cog(Skip(bot))