Parcourir la source

removed all the todos in voice because they were done and i just hadnt deleted them. Made duration formatter a static method because it was.

tags/v1.8.0
Roxie Gibson il y a 6 ans
Parent
révision
c9fbd2092c
1 fichiers modifiés avec 16 ajouts et 16 suppressions
  1. +16
    -16
      roxbot/cogs/voice.py

+ 16
- 16
roxbot/cogs/voice.py Voir le fichier

self.timer += 20 self.timer += 20
return super().read() return super().read()



class YTDLSource(discord.PCMVolumeTransformer): class YTDLSource(discord.PCMVolumeTransformer):
def __init__(self, source, *, data, volume): def __init__(self, source, *, data, volume):
self.source = source self.source = source
self.now_playing[guild.id] = None self.now_playing[guild.id] = None
self.queue_logic[guild.id] = None self.queue_logic[guild.id] = None


@staticmethod
def _format_duration(duration):
"""Static method to turn the duration of a file (in seconds) into something presentable for the user"""
if not duration:
return duration
hours = duration // 3600
minutes = (duration % 3600) // 60
seconds = duration % 60
format_me = {"second": int(seconds), "minute": int(minutes), "hour": int(hours)}
formatted = datetime.time(**format_me)
output = "{:%M:%S}".format(formatted)
if formatted.hour >= 1:
output = "{:%H}".format(formatted) + output
return output

async def _queue_logic(self, ctx): async def _queue_logic(self, ctx):
# TODO: This is broke it seems.
"""Background task designed to help the bot move on to the next video in the queue""" """Background task designed to help the bot move on to the next video in the queue"""
sleep_for = 0.5 sleep_for = 0.5
try: try:
self.playlist[ctx.guild.id].append(video) self.playlist[ctx.guild.id].append(video)
return video return video


def _format_duration(self, duration):
# TODO: Fix when duration returns nothing and the bot breaks here.
hours = duration // 3600
minutes = (duration % 3600) // 60
seconds = duration % 60
format_me = {"second": int(seconds), "minute": int(minutes), "hour": int(hours)}
formatted = datetime.time(**format_me)
output = "{:%M:%S}".format(formatted)
if formatted.hour >= 1:
output = "{:%H}".format(formatted) + output
return output

def _generate_np_embed(self, guild, playing_status): def _generate_np_embed(self, guild, playing_status):
np = self.now_playing[guild.id] np = self.now_playing[guild.id]
title = "{0}: '{1.title}' from {1.host}".format(playing_status, np) title = "{0}: '{1.title}' from {1.host}".format(playing_status, np)
@commands.command(hidden=True, enabled=False) @commands.command(hidden=True, enabled=False)
async def play_local(self, ctx, *, query): async def play_local(self, ctx, *, query):
"""Plays a file from the local filesystem.""" """Plays a file from the local filesystem."""
# TODO: Playlist stuff maybe
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(query)) source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(query))
ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None) ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None)




@commands.command() @commands.command()
async def skip(self, ctx, option=""): async def skip(self, ctx, option=""):
# TODO: Skipping isn't cleaned properly when successful
"""Skips or votes to skip the current video. Use option "--force" if your an admin and """ """Skips or votes to skip the current video. Use option "--force" if your an admin and """
voice = guild_settings.get(ctx.guild).voice voice = guild_settings.get(ctx.guild).voice
if ctx.voice_client.is_playing(): if ctx.voice_client.is_playing():
if self.now_playing[ctx.guild.id] is None: if self.now_playing[ctx.guild.id] is None:
return await ctx.send("Nothing is playing.") return await ctx.send("Nothing is playing.")
else: else:
np = ctx.voice_client.source
if ctx.voice_client.is_paused(): if ctx.voice_client.is_paused():
x = "Paused" x = "Paused"
else: else:

Chargement…
Annuler
Enregistrer