1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-24 22:27:28 +00:00

Fix coroutine hanging on move command

This commit is contained in:
Myned 2022-03-04 13:21:24 -06:00
parent c638ca0956
commit 3de03eb47b
No known key found for this signature in database
GPG key ID: 33790F979F7A28B8

View file

@ -154,10 +154,10 @@ async def move(context):
@lightbulb.implements(lightbulb.SlashCommand) @lightbulb.implements(lightbulb.SlashCommand)
async def play(context): async def play(context):
if not context.options.query: if not context.options.query:
if not await running(context.guild_id): if not running(context.guild_id) or not await state(context.guild_id):
await context.respond("***Nothing to resume***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Nothing to resume***", flags=hikari.MessageFlag.EPHEMERAL)
return return
if (await plugin.d.queue[context.guild_id].track_handle.get_info()).playing == songbird.PlayMode.Play: if (await state(context.guild_id)).playing == songbird.PlayMode.Play:
await context.respond("***Already playing***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Already playing***", flags=hikari.MessageFlag.EPHEMERAL)
return return
@ -225,7 +225,7 @@ async def play(context):
embed.url = match["link"] embed.url = match["link"]
embed.set_thumbnail(match["thumbnails"][0]["url"]) embed.set_thumbnail(match["thumbnails"][0]["url"])
if await running(context.guild_id): if running(context.guild_id) and await state(context.guild_id):
plugin.d.queue[context.guild_id].extend(sources) plugin.d.queue[context.guild_id].extend(sources)
if len(sources) > 1: if len(sources) > 1:
@ -250,7 +250,7 @@ async def play(context):
@lightbulb.command("skip", "Skip the current or to a specific track") @lightbulb.command("skip", "Skip the current or to a specific track")
@lightbulb.implements(lightbulb.SlashCommand) @lightbulb.implements(lightbulb.SlashCommand)
async def skip(context): async def skip(context):
if not await running(context.guild_id): if not running(context.guild_id) or not await state(context.guild_id):
await context.respond("***Nothing to skip***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Nothing to skip***", flags=hikari.MessageFlag.EPHEMERAL)
return return
if len(plugin.d.queue[context.guild_id]) == 0: if len(plugin.d.queue[context.guild_id]) == 0:
@ -312,7 +312,7 @@ async def remove(context):
.set_footer(f"{len(sources)} track{'s' if len(sources) > 1 else ''}") .set_footer(f"{len(sources)} track{'s' if len(sources) > 1 else ''}")
) )
if not await running(context.guild_id): if not running(context.guild_id) or not await state(context.guild_id):
await context.respond("***Nothing to remove***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Nothing to remove***", flags=hikari.MessageFlag.EPHEMERAL)
return return
@ -363,7 +363,7 @@ async def remove(context):
@skip.autocomplete("position") @skip.autocomplete("position")
@remove.autocomplete("position") @remove.autocomplete("position")
async def position_autocomplete(option, interaction): async def position_autocomplete(option, interaction):
if not await running(interaction.guild_id): if not running(interaction.guild_id) or not await state(interaction.guild_id):
return return
suggestions = [] suggestions = []
@ -392,10 +392,10 @@ async def position_autocomplete(option, interaction):
@lightbulb.command("pause", "Pause the current track") @lightbulb.command("pause", "Pause the current track")
@lightbulb.implements(lightbulb.SlashCommand) @lightbulb.implements(lightbulb.SlashCommand)
async def pause(context): async def pause(context):
if not await running(context.guild_id): if not running(context.guild_id) or not await state(context.guild_id):
await context.respond("***Nothing to pause***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Nothing to pause***", flags=hikari.MessageFlag.EPHEMERAL)
return return
if (await plugin.d.queue[context.guild_id].track_handle.get_info()).playing == songbird.PlayMode.Pause: if (await state(context.guild_id)).playing == songbird.PlayMode.Pause:
await context.respond("***Already paused***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Already paused***", flags=hikari.MessageFlag.EPHEMERAL)
return return
@ -409,15 +409,11 @@ async def pause(context):
@lightbulb.command("stop", "Stop the current track and clear the queue") @lightbulb.command("stop", "Stop the current track and clear the queue")
@lightbulb.implements(lightbulb.SlashCommand) @lightbulb.implements(lightbulb.SlashCommand)
async def stop(context): async def stop(context):
if context.guild_id not in plugin.d.queue: if not running(context.guild_id):
await context.respond("***Nothing to stop***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Nothing to stop***", flags=hikari.MessageFlag.EPHEMERAL)
return return
try: try:
if (
plugin.d.queue[context.guild_id].track_handle
and await plugin.d.queue[context.guild_id].track_handle.get_info()
):
plugin.d.queue[context.guild_id].track_handle.stop() plugin.d.queue[context.guild_id].track_handle.stop()
except songbird.SongbirdError: except songbird.SongbirdError:
pass pass
@ -435,12 +431,10 @@ async def stop(context):
@lightbulb.command("nowplaying", "Show the current track", ephemeral=True) @lightbulb.command("nowplaying", "Show the current track", ephemeral=True)
@lightbulb.implements(lightbulb.SlashCommand) @lightbulb.implements(lightbulb.SlashCommand)
async def nowplaying(context): async def nowplaying(context):
if not await running(context.guild_id): if not running(context.guild_id) or not await state(context.guild_id):
await context.respond("***Nothing is playing***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Nothing is playing***", flags=hikari.MessageFlag.EPHEMERAL)
return return
state = await plugin.d.queue[context.guild_id].track_handle.get_info()
await context.respond( await context.respond(
hikari.Embed( hikari.Embed(
title=plugin.d.queue[context.guild_id].track_handle.metadata.title, title=plugin.d.queue[context.guild_id].track_handle.metadata.title,
@ -450,7 +444,7 @@ async def nowplaying(context):
.set_author(name="Now playing") .set_author(name="Now playing")
.set_thumbnail(plugin.d.queue[context.guild_id].track_handle.metadata.thumbnail) .set_thumbnail(plugin.d.queue[context.guild_id].track_handle.metadata.thumbnail)
.set_footer( .set_footer(
f"{convert(round(state.position))} / {convert(round(plugin.d.queue[context.guild_id].track_handle.metadata.duration))}" f"{convert(round((await state(context.guild_id)).position))} / {convert(round(plugin.d.queue[context.guild_id].track_handle.metadata.duration))}"
) )
) )
@ -476,7 +470,7 @@ async def queue(context):
) )
) )
if not await running(context.guild_id): if not running(context.guild_id) or not await state(context.guild_id):
await context.respond("***Nothing in the queue***", flags=hikari.MessageFlag.EPHEMERAL) await context.respond("***Nothing in the queue***", flags=hikari.MessageFlag.EPHEMERAL)
return return
@ -517,7 +511,7 @@ async def connect(context):
) )
# Reconstruct queue # Reconstruct queue
if await running(context.guild_id): if running(context.guild_id):
sources = [songbird.ytdl(plugin.d.queue[context.guild_id].track_handle.metadata.source_url)] + plugin.d.queue[ sources = [songbird.ytdl(plugin.d.queue[context.guild_id].track_handle.metadata.source_url)] + plugin.d.queue[
context.guild_id context.guild_id
] ]
@ -531,17 +525,19 @@ async def connect(context):
return driver return driver
# Return True if queue exists and is playing # Return track info if queue is playing
async def running(guild_id): async def state(guild_id):
try: try:
return ( return await plugin.d.queue[guild_id].track_handle.get_info()
guild_id in plugin.d.queue
and plugin.d.queue[guild_id].track_handle
and await plugin.d.queue[guild_id].track_handle.get_info()
)
# TrackError is not exposed, so use base songbird error # TrackError is not exposed, so use base songbird error
# Return empty TrackState
except songbird.SongbirdError: except songbird.SongbirdError:
return False return None
# Return True if queue exists and is running
def running(guild_id):
return guild_id in plugin.d.queue and plugin.d.queue[guild_id].track_handle
# Convert seconds into (HH:)MM:SS # Convert seconds into (HH:)MM:SS