mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
[Audio] Embed colours respect user settings (#2046)
* Embed colours now respect what the user set * Formatting * Get embed colour when ctx is unavailable
This commit is contained in:
parent
9af58d3abf
commit
0aca00b245
@ -73,6 +73,13 @@ class Audio:
|
|||||||
)
|
)
|
||||||
lavalink.register_event_listener(self.event_handler)
|
lavalink.register_event_listener(self.event_handler)
|
||||||
|
|
||||||
|
async def _get_embed_colour(self, channel: discord.abc.GuildChannel):
|
||||||
|
# Unfortunately we need this for when context is unavailable.
|
||||||
|
if await self.bot.db.guild(channel.guild).use_bot_colour():
|
||||||
|
return channel.guild.me.color
|
||||||
|
else:
|
||||||
|
return self.bot.color
|
||||||
|
|
||||||
async def event_handler(self, player, event_type, extra):
|
async def event_handler(self, player, event_type, extra):
|
||||||
notify = await self.config.guild(player.channel.guild).notify()
|
notify = await self.config.guild(player.channel.guild).notify()
|
||||||
status = await self.config.status()
|
status = await self.config.status()
|
||||||
@ -102,7 +109,7 @@ class Audio:
|
|||||||
except discord.errors.NotFound:
|
except discord.errors.NotFound:
|
||||||
pass
|
pass
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=notify_channel.guild.me.top_role.colour,
|
colour=(await self._get_embed_colour(notify_channel)),
|
||||||
title="Now Playing",
|
title="Now Playing",
|
||||||
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
||||||
)
|
)
|
||||||
@ -136,7 +143,7 @@ class Audio:
|
|||||||
if notify_channel:
|
if notify_channel:
|
||||||
notify_channel = self.bot.get_channel(notify_channel)
|
notify_channel = self.bot.get_channel(notify_channel)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=notify_channel.guild.me.top_role.colour, title="Queue ended."
|
colour=(await self._get_embed_colour(notify_channel)), title="Queue ended."
|
||||||
)
|
)
|
||||||
await notify_channel.send(embed=embed)
|
await notify_channel.send(embed=embed)
|
||||||
|
|
||||||
@ -162,7 +169,7 @@ class Audio:
|
|||||||
if message_channel:
|
if message_channel:
|
||||||
message_channel = self.bot.get_channel(message_channel)
|
message_channel = self.bot.get_channel(message_channel)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=message_channel.guild.me.top_role.colour,
|
colour=(await self._get_embed_colour(message_channel)),
|
||||||
title="Track Error",
|
title="Track Error",
|
||||||
description="{}\n**[{}]({})**".format(
|
description="{}\n**[{}]({})**".format(
|
||||||
extra, player.current.title, player.current.uri
|
extra, player.current.title, player.current.uri
|
||||||
@ -304,7 +311,7 @@ class Audio:
|
|||||||
"External server: [{use_external_lavalink}]```"
|
"External server: [{use_external_lavalink}]```"
|
||||||
).format(__version__, jarbuild, **global_data)
|
).format(__version__, jarbuild, **global_data)
|
||||||
|
|
||||||
embed = discord.Embed(colour=ctx.guild.me.top_role.colour, description=msg)
|
embed = discord.Embed(colour=(await ctx.embed_colour()), description=msg)
|
||||||
return await ctx.send(embed=embed)
|
return await ctx.send(embed=embed)
|
||||||
|
|
||||||
@audioset.command()
|
@audioset.command()
|
||||||
@ -372,7 +379,7 @@ class Audio:
|
|||||||
else:
|
else:
|
||||||
servers = "\n".join(server_list)
|
servers = "\n".join(server_list)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Connected in {} servers:".format(server_num),
|
title="Connected in {} servers:".format(server_num),
|
||||||
description=servers,
|
description=servers,
|
||||||
)
|
)
|
||||||
@ -450,7 +457,7 @@ class Audio:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="Now Playing", description=song
|
colour=(await ctx.embed_colour()), title="Now Playing", description=song
|
||||||
)
|
)
|
||||||
if await self.config.guild(ctx.guild).thumbnail() and player.current.thumbnail:
|
if await self.config.guild(ctx.guild).thumbnail() and player.current.thumbnail:
|
||||||
embed.set_thumbnail(url=player.current.thumbnail)
|
embed.set_thumbnail(url=player.current.thumbnail)
|
||||||
@ -519,7 +526,7 @@ class Audio:
|
|||||||
if player.current and not player.paused and command != "resume":
|
if player.current and not player.paused and command != "resume":
|
||||||
await player.pause()
|
await player.pause()
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Track Paused",
|
title="Track Paused",
|
||||||
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
||||||
)
|
)
|
||||||
@ -528,7 +535,7 @@ class Audio:
|
|||||||
if player.paused and command != "pause":
|
if player.paused and command != "pause":
|
||||||
await player.pause(False)
|
await player.pause(False)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Track Resumed",
|
title="Track Resumed",
|
||||||
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
||||||
)
|
)
|
||||||
@ -590,7 +597,7 @@ class Audio:
|
|||||||
queue_user = ["{}: {:g}%".format(x[0], x[1]) for x in top_queue_users]
|
queue_user = ["{}: {:g}%".format(x[0], x[1]) for x in top_queue_users]
|
||||||
queue_user_list = "\n".join(queue_user)
|
queue_user_list = "\n".join(queue_user)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Queued and playing songs:",
|
title="Queued and playing songs:",
|
||||||
description=queue_user_list,
|
description=queue_user_list,
|
||||||
)
|
)
|
||||||
@ -650,7 +657,7 @@ class Audio:
|
|||||||
for track in tracks:
|
for track in tracks:
|
||||||
player.add(ctx.author, track)
|
player.add(ctx.author, track)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Playlist Enqueued",
|
title="Playlist Enqueued",
|
||||||
description="Added {} tracks to the queue.".format(len(tracks)),
|
description="Added {} tracks to the queue.".format(len(tracks)),
|
||||||
)
|
)
|
||||||
@ -666,7 +673,7 @@ class Audio:
|
|||||||
single_track = tracks[0]
|
single_track = tracks[0]
|
||||||
player.add(ctx.author, single_track)
|
player.add(ctx.author, single_track)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Track Enqueued",
|
title="Track Enqueued",
|
||||||
description="**[{}]({})**".format(single_track.title, single_track.uri),
|
description="**[{}]({})**".format(single_track.title, single_track.uri),
|
||||||
)
|
)
|
||||||
@ -772,7 +779,7 @@ class Audio:
|
|||||||
else:
|
else:
|
||||||
playlist_url = "URL: <{}>".format(playlist_url)
|
playlist_url = "URL: <{}>".format(playlist_url)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Playlist info for {}:".format(playlist_name),
|
title="Playlist info for {}:".format(playlist_name),
|
||||||
description="Author: **{}**\n{}".format(author_obj, playlist_url),
|
description="Author: **{}**\n{}".format(author_obj, playlist_url),
|
||||||
)
|
)
|
||||||
@ -789,7 +796,7 @@ class Audio:
|
|||||||
abc_names = sorted(playlist_list, key=str.lower)
|
abc_names = sorted(playlist_list, key=str.lower)
|
||||||
all_playlists = ", ".join(abc_names)
|
all_playlists = ", ".join(abc_names)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Playlists for {}:".format(ctx.guild.name),
|
title="Playlists for {}:".format(ctx.guild.name),
|
||||||
description=all_playlists,
|
description=all_playlists,
|
||||||
)
|
)
|
||||||
@ -911,7 +918,7 @@ class Audio:
|
|||||||
player.add(author_obj, lavalink.rest_api.Track(data=track))
|
player.add(author_obj, lavalink.rest_api.Track(data=track))
|
||||||
track_count = track_count + 1
|
track_count = track_count + 1
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Playlist Enqueued",
|
title="Playlist Enqueued",
|
||||||
description="Added {} tracks to the queue.".format(track_count),
|
description="Added {} tracks to the queue.".format(track_count),
|
||||||
)
|
)
|
||||||
@ -974,7 +981,7 @@ class Audio:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
embed1 = discord.Embed(
|
embed1 = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="Please wait, adding tracks..."
|
colour=(await ctx.embed_colour()), title="Please wait, adding tracks..."
|
||||||
)
|
)
|
||||||
playlist_msg = await ctx.send(embed=embed1)
|
playlist_msg = await ctx.send(embed=embed1)
|
||||||
for song_url in v2_playlist["playlist"]:
|
for song_url in v2_playlist["playlist"]:
|
||||||
@ -987,7 +994,7 @@ class Audio:
|
|||||||
pass
|
pass
|
||||||
if track_count % 5 == 0:
|
if track_count % 5 == 0:
|
||||||
embed2 = discord.Embed(
|
embed2 = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Loading track {}/{}...".format(
|
title="Loading track {}/{}...".format(
|
||||||
track_count, len(v2_playlist["playlist"])
|
track_count, len(v2_playlist["playlist"])
|
||||||
),
|
),
|
||||||
@ -1007,7 +1014,7 @@ class Audio:
|
|||||||
else:
|
else:
|
||||||
msg = "Added {} tracks from the {} playlist.".format(track_count, v2_playlist_name)
|
msg = "Added {} tracks from the {} playlist.".format(track_count, v2_playlist_name)
|
||||||
embed3 = discord.Embed(
|
embed3 = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="Playlist Saved", description=msg
|
colour=(await ctx.embed_colour()), title="Playlist Saved", description=msg
|
||||||
)
|
)
|
||||||
await playlist_msg.edit(embed=embed3)
|
await playlist_msg.edit(embed=embed3)
|
||||||
else:
|
else:
|
||||||
@ -1103,7 +1110,7 @@ class Audio:
|
|||||||
player.queue.pop(queue_len)
|
player.queue.pop(queue_len)
|
||||||
await player.skip()
|
await player.skip()
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Replaying Track",
|
title="Replaying Track",
|
||||||
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
||||||
)
|
)
|
||||||
@ -1169,7 +1176,7 @@ class Audio:
|
|||||||
)
|
)
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Queue for " + ctx.guild.name,
|
title="Queue for " + ctx.guild.name,
|
||||||
description=queue_list,
|
description=queue_list,
|
||||||
)
|
)
|
||||||
@ -1275,8 +1282,7 @@ class Audio:
|
|||||||
if not tracks:
|
if not tracks:
|
||||||
return await self._embed_msg(ctx, "Nothing found.")
|
return await self._embed_msg(ctx, "Nothing found.")
|
||||||
songembed = discord.Embed(
|
songembed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()), title="Queued {} track(s).".format(len(tracks))
|
||||||
title="Queued {} track(s).".format(len(tracks)),
|
|
||||||
)
|
)
|
||||||
queue_duration = await self._queue_duration(ctx)
|
queue_duration = await self._queue_duration(ctx)
|
||||||
queue_total_duration = lavalink.utils.format_time(queue_duration)
|
queue_total_duration = lavalink.utils.format_time(queue_duration)
|
||||||
@ -1356,7 +1362,7 @@ class Audio:
|
|||||||
search_choice = tracks[-1]
|
search_choice = tracks[-1]
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Track Enqueued",
|
title="Track Enqueued",
|
||||||
description="**[{}]({})**".format(search_choice.title, search_choice.uri),
|
description="**[{}]({})**".format(search_choice.title, search_choice.uri),
|
||||||
)
|
)
|
||||||
@ -1393,7 +1399,7 @@ class Audio:
|
|||||||
search_track_num, track.title, track.uri
|
search_track_num, track.title, track.uri
|
||||||
)
|
)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="Tracks Found:", description=search_list
|
colour=(await ctx.embed_colour()), title="Tracks Found:", description=search_list
|
||||||
)
|
)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text="Page {}/{} | {} search results".format(page_num, search_num_pages, len(tracks))
|
text="Page {}/{} | {} search results".format(page_num, search_num_pages, len(tracks))
|
||||||
@ -1570,18 +1576,18 @@ class Audio:
|
|||||||
time_remain = lavalink.utils.format_time(dur - pos)
|
time_remain = lavalink.utils.format_time(dur - pos)
|
||||||
if player.current.is_stream:
|
if player.current.is_stream:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="There's nothing in the queue."
|
colour=(await ctx.embed_colour()), title="There's nothing in the queue."
|
||||||
)
|
)
|
||||||
embed.set_footer(text="Currently livestreaming {}".format(player.current.title))
|
embed.set_footer(text="Currently livestreaming {}".format(player.current.title))
|
||||||
else:
|
else:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="There's nothing in the queue."
|
colour=(await ctx.embed_colour()), title="There's nothing in the queue."
|
||||||
)
|
)
|
||||||
embed.set_footer(text="{} left on {}".format(time_remain, player.current.title))
|
embed.set_footer(text="{} left on {}".format(time_remain, player.current.title))
|
||||||
return await ctx.send(embed=embed)
|
return await ctx.send(embed=embed)
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Track Skipped",
|
title="Track Skipped",
|
||||||
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
description="**[{}]({})**".format(player.current.title, player.current.uri),
|
||||||
)
|
)
|
||||||
@ -1629,7 +1635,7 @@ class Audio:
|
|||||||
if not vol:
|
if not vol:
|
||||||
vol = await self.config.guild(ctx.guild).volume()
|
vol = await self.config.guild(ctx.guild).volume()
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Current Volume:",
|
title="Current Volume:",
|
||||||
description=str(vol) + "%",
|
description=str(vol) + "%",
|
||||||
)
|
)
|
||||||
@ -1659,7 +1665,7 @@ class Audio:
|
|||||||
if self._player_check(ctx):
|
if self._player_check(ctx):
|
||||||
await lavalink.get_player(ctx.guild.id).set_volume(vol)
|
await lavalink.get_player(ctx.guild.id).set_volume(vol)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="Volume:", description=str(vol) + "%"
|
colour=(await ctx.embed_colour()), title="Volume:", description=str(vol) + "%"
|
||||||
)
|
)
|
||||||
if not self._player_check(ctx):
|
if not self._player_check(ctx):
|
||||||
embed.set_footer(text="Nothing playing.")
|
embed.set_footer(text="Nothing playing.")
|
||||||
@ -1683,7 +1689,7 @@ class Audio:
|
|||||||
await self.config.rest_port.set(2333)
|
await self.config.rest_port.set(2333)
|
||||||
await self.config.ws_port.set(2332)
|
await self.config.ws_port.set(2332)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="External lavalink server: {}.".format(not external),
|
title="External lavalink server: {}.".format(not external),
|
||||||
)
|
)
|
||||||
embed.set_footer(text="Defaults reset.")
|
embed.set_footer(text="Defaults reset.")
|
||||||
@ -1697,7 +1703,7 @@ class Audio:
|
|||||||
await self.config.host.set(host)
|
await self.config.host.set(host)
|
||||||
if await self._check_external():
|
if await self._check_external():
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="Host set to {}.".format(host)
|
colour=(await ctx.embed_colour()), title="Host set to {}.".format(host)
|
||||||
)
|
)
|
||||||
embed.set_footer(text="External lavalink server set to True.")
|
embed.set_footer(text="External lavalink server set to True.")
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
@ -1710,7 +1716,7 @@ class Audio:
|
|||||||
await self.config.password.set(str(password))
|
await self.config.password.set(str(password))
|
||||||
if await self._check_external():
|
if await self._check_external():
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Server password set to {}.".format(password),
|
title="Server password set to {}.".format(password),
|
||||||
)
|
)
|
||||||
embed.set_footer(text="External lavalink server set to True.")
|
embed.set_footer(text="External lavalink server set to True.")
|
||||||
@ -1724,7 +1730,7 @@ class Audio:
|
|||||||
await self.config.rest_port.set(rest_port)
|
await self.config.rest_port.set(rest_port)
|
||||||
if await self._check_external():
|
if await self._check_external():
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour, title="REST port set to {}.".format(rest_port)
|
colour=(await ctx.embed_colour()), title="REST port set to {}.".format(rest_port)
|
||||||
)
|
)
|
||||||
embed.set_footer(text="External lavalink server set to True.")
|
embed.set_footer(text="External lavalink server set to True.")
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
@ -1737,7 +1743,7 @@ class Audio:
|
|||||||
await self.config.ws_port.set(ws_port)
|
await self.config.ws_port.set(ws_port)
|
||||||
if await self._check_external():
|
if await self._check_external():
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
colour=ctx.guild.me.top_role.colour,
|
colour=(await ctx.embed_colour()),
|
||||||
title="Websocket port set to {}.".format(ws_port),
|
title="Websocket port set to {}.".format(ws_port),
|
||||||
)
|
)
|
||||||
embed.set_footer(text="External lavalink server set to True.")
|
embed.set_footer(text="External lavalink server set to True.")
|
||||||
@ -1856,7 +1862,7 @@ class Audio:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def _embed_msg(ctx, title):
|
async def _embed_msg(ctx, title):
|
||||||
embed = discord.Embed(colour=ctx.guild.me.top_role.colour, title=title)
|
embed = discord.Embed(colour=(await ctx.embed_colour()), title=title)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
async def _get_playing(self, ctx):
|
async def _get_playing(self, ctx):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user