[Audio] Seek command can now seek to position (#2470)

- Seek can now seek to a specific position, formatted like 00:00:00 or 00:00. Using negative or positive ints still functions the same as previously and will seek ahead or behind by that value instead.
- This PR requires the `_time_convert` func added in #2465 and should be merged after that one.
This commit is contained in:
aikaterna 2019-03-09 23:27:23 -08:00 committed by Toby Harradine
parent 421043d923
commit 94c3a2fedd

View File

@ -2281,8 +2281,10 @@ class Audio(commands.Cog):
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
async def seek(self, ctx, seconds: int = 30): async def seek(self, ctx, seconds):
"""Seek ahead or behind on a track by seconds.""" """Seek ahead or behind on a track by seconds or a to a specific time.
Accepts seconds or a value formatted like 00:00:00 (`hh:mm:ss`) or 00:00 (`mm:ss`)."""
dj_enabled = await self.config.guild(ctx.guild).dj_enabled() dj_enabled = await self.config.guild(ctx.guild).dj_enabled()
vote_enabled = await self.config.guild(ctx.guild).vote_enabled() vote_enabled = await self.config.guild(ctx.guild).vote_enabled()
if not self._player_check(ctx): if not self._player_check(ctx):
@ -2308,7 +2310,16 @@ class Audio(commands.Cog):
if player.current.is_stream: if player.current.is_stream:
return await self._embed_msg(ctx, _("Can't seek on a stream.")) return await self._embed_msg(ctx, _("Can't seek on a stream."))
else: else:
time_sec = seconds * 1000 try:
int(seconds)
abs_position = False
except ValueError:
abs_position = True
seconds = int(await self._time_convert(seconds) / 1000)
if seconds == 0:
return await self._embed_msg(ctx, _("Invalid input for the time to seek."))
if not abs_position:
time_sec = int(seconds) * 1000
seek = player.position + time_sec seek = player.position + time_sec
if seek <= 0: if seek <= 0:
await self._embed_msg( await self._embed_msg(
@ -2321,7 +2332,15 @@ class Audio(commands.Cog):
num_seconds=seconds, time=lavalink.utils.format_time(seek) num_seconds=seconds, time=lavalink.utils.format_time(seek)
), ),
) )
return await player.seek(seek) await player.seek(seek)
else:
await self._embed_msg(
ctx,
_("Moved to {time}").format(
time=lavalink.utils.format_time(seconds * 1000)
),
)
await player.seek(seconds * 1000)
else: else:
await self._embed_msg(ctx, _("Nothing playing.")) await self._embed_msg(ctx, _("Nothing playing."))