Browse Source

skipping works woo

tags/v1.6.0
Roxie Gibson 6 years ago
parent
commit
4195796dae
1 changed files with 24 additions and 7 deletions
  1. +24
    -7
      Roxbot/cogs/voice.py

+ 24
- 7
Roxbot/cogs/voice.py View File

self.data = data self.data = data
self.title = data.get('title') self.title = data.get('title')
self.url = data.get('url') self.url = data.get('url')
self.webpage_url = data.get('webpage_url')
self.duration = data.get("duration") self.duration = data.get("duration")


@classmethod @classmethod
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.playlist = {} self.playlist = {}
self.is_skipped = {}
for guild in bot.guilds: for guild in bot.guilds:
self.playlist[guild.id] = [] self.playlist[guild.id] = []
self.now_playing = None self.now_playing = None


@play.after_invoke @play.after_invoke
async def while_playing(self, ctx): async def while_playing(self, ctx):
await asyncio.sleep(ctx.voice_client.source.duration)
if self.playlist[ctx.guild.id]:
if ctx.voice_client.source == self.now_playing:
count = 0
sleep_for = 0.5
while ctx.voice_client.is_playing(): while ctx.voice_client.is_playing():
await asyncio.sleep(.1) # Just in case of some lag or or something

player = self.playlist[ctx.guild.id].pop(0)
await ctx.invoke(self.play, url=player.url)
await asyncio.sleep(sleep_for)
count += sleep_for
if self.playlist[ctx.guild.id]:
player = self.playlist[ctx.guild.id].pop(0)
await ctx.invoke(self.play, url=player.webpage_url)


@commands.command() @commands.command()
async def stream(self, ctx, *, url): async def stream(self, ctx, *, url):
@commands.command() @commands.command()
async def stop(self, ctx): async def stop(self, ctx):
"""Stops and disconnects the bot from voice""" """Stops and disconnects the bot from voice"""
self.now_playing = None
await ctx.voice_client.disconnect() await ctx.voice_client.disconnect()


# TODO: Pause command # TODO: Pause command

@commands.command()
async def skip(self, ctx):
# This should be fine as the while_playing function should handle moving to the next song.
# TODO: Needs voting logic preferably in the future
if ctx.voice_client.is_playing():
self.now_playing = None
ctx.voice_client.stop()
# TODO: Title detection
return await ctx.send("Skipped song")
else:
await ctx.send("I'm not playing anything.")

# TODO: Skip command. That will also need to check for the waiting for the song to be over function # TODO: Skip command. That will also need to check for the waiting for the song to be over function


@play.before_invoke @play.before_invoke

Loading…
Cancel
Save