Move 'Now playing:' from embed to message content

This commit is contained in:
ekzyis 2022-09-26 22:49:46 +02:00
parent eb9f74ede0
commit 698ef7cf3c
3 changed files with 14 additions and 6 deletions

View File

@ -110,7 +110,7 @@ class Music(commands.Cog):
self.logger.info('Now playing: %s (%s)', song.title, song.webpage_url)
ctx.voice_client.play(audio, after=after)
embed = NowPlayingMessage(title=song.title, url=song.webpage_url, image_url=song.image_url)
msg = await ctx.send(embed=embed)
msg = await ctx.send(content=embed.content, embed=embed)
await self._add_skip_button(msg)
# pylint: disable=broad-except
except Exception as err:
@ -152,7 +152,7 @@ class Music(commands.Cog):
await self._queue.put((ctx, song))
if ctx.voice_client.is_playing():
embed = QueuedMessage(title=song.title, url=song.webpage_url, image_url=song.image_url)
await ctx.send(embed=embed)
await ctx.send(content=embed.content, embed=embed)
def _skip(self, voice_client):
"""Skip to next song."""

View File

@ -16,6 +16,8 @@ class BotMessage(discord.Embed):
image_url = kwargs.pop('image_url', None)
if image_url:
super().set_image(url=image_url)
# Message content before embed
self.content = kwargs.pop('content', None)
class ErrorMessage(BotMessage):
@ -36,7 +38,8 @@ class ErrorMessage(BotMessage):
class NowPlayingMessage(BotMessage):
def __init__(self, title, url, image_url):
super().__init__(
title=f'Now playing: {title}',
content='Now playing:',
title=title,
url=url,
image_url=image_url,
color=discord.Color.green()
@ -46,7 +49,8 @@ class NowPlayingMessage(BotMessage):
class QueuedMessage(BotMessage):
def __init__(self, title, url, image_url):
super().__init__(
title=f'Queued: {title}',
content='Queued:',
title=title,
url=url,
image_url=image_url,
color=discord.Color.blue()

View File

@ -64,8 +64,10 @@ async def test_bot_playback(mbot, ctx):
assert \
ctx.voice_client.play.call_args.args == (deliver_us_audio,), \
'Did not playback correct audio'
content = ctx.send.call_args.kwargs['content']
assert content == 'Now playing:', "Did not send 'Now playing:' message"
embed = ctx.send.call_args.kwargs['embed']
assert embed.title == f'Now playing: {title}', "Did not send 'Now playing:' message"
assert embed.title == title, "Did not send 'Now playing:' embed"
# TEST: Following songs are put inside a queue
ctx.voice_client.is_playing.return_value = True
@ -85,8 +87,10 @@ async def test_bot_playback(mbot, ctx):
assert \
not ctx.voice_client.play.call_args.args == (time_of_dying_audio,), \
'Did immediately playback audio instead of being queued'
content = ctx.send.call_args.kwargs['content']
assert content == 'Queued:', "Did not send 'Queued:' message"
embed = ctx.send.call_args.kwargs['embed']
assert embed.title == f'Queued: {title}', "Did not send 'Queued:' message"
assert embed.title == title, "Did not send 'Queued:' embed"
await asyncio.sleep(0)
# Assert that there is still no playback because previous song is not finished yet
assert \