mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[V3 Core] add support for setting a color for embeds (#1707)
* [V3 Core] add support for setting a color for embeds * Add a guild toggle for whether to use the bot color * Add a function for getting embed color in Context * Coroutines need to be awaited lol
This commit is contained in:
parent
07eb6bf88e
commit
971ccf9df4
34
Pipfile.lock
generated
34
Pipfile.lock
generated
@ -83,6 +83,13 @@
|
|||||||
],
|
],
|
||||||
"version": "==1.0.2"
|
"version": "==1.0.2"
|
||||||
},
|
},
|
||||||
|
"fuzzywuzzy": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:d40c22d2744dff84885b30bbfc07fab7875f641d070374331777a4d1808b8d4e",
|
||||||
|
"sha256:ecf490216fb4d76b558a03042ff8f45a8782f17326caca1384d834cbaa2c7e6f"
|
||||||
|
],
|
||||||
|
"version": "==0.16.0"
|
||||||
|
},
|
||||||
"idna": {
|
"idna": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f",
|
"sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f",
|
||||||
@ -121,6 +128,12 @@
|
|||||||
],
|
],
|
||||||
"version": "==4.3.1"
|
"version": "==4.3.1"
|
||||||
},
|
},
|
||||||
|
"python-levenshtein": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:033a11de5e3d19ea25c9302d11224e1a1898fe5abd23c61c7c360c25195e3eb1"
|
||||||
|
],
|
||||||
|
"version": "==0.12.0"
|
||||||
|
},
|
||||||
"pyyaml": {
|
"pyyaml": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:0c507b7f74b3d2dd4d1322ec8a94794927305ab4cebbe89cc47fe5e81541e6e8",
|
"sha256:0c507b7f74b3d2dd4d1322ec8a94794927305ab4cebbe89cc47fe5e81541e6e8",
|
||||||
@ -219,6 +232,13 @@
|
|||||||
],
|
],
|
||||||
"version": "==1.4.3"
|
"version": "==1.4.3"
|
||||||
},
|
},
|
||||||
|
"atomicwrites": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:240831ea22da9ab882b551b31d4225591e5e447a68c5e188db5b89ca1d487585",
|
||||||
|
"sha256:a24da68318b08ac9c9c45029f4a10371ab5b20e4226738e150e6e7c571630ae6"
|
||||||
|
],
|
||||||
|
"version": "==1.1.5"
|
||||||
|
},
|
||||||
"attrs": {
|
"attrs": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:4b90b09eeeb9b88c35bc642cbac057e45a5fd85367b985bd2809c62b7b939265",
|
"sha256:4b90b09eeeb9b88c35bc642cbac057e45a5fd85367b985bd2809c62b7b939265",
|
||||||
@ -300,11 +320,11 @@
|
|||||||
},
|
},
|
||||||
"more-itertools": {
|
"more-itertools": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:0dd8f72eeab0d2c3bd489025bb2f6a1b8342f9b198f6fc37b52d15cfa4531fea",
|
"sha256:2b6b9893337bfd9166bee6a62c2b0c9fe7735dcf85948b387ec8cba30e85d8e8",
|
||||||
"sha256:11a625025954c20145b37ff6309cd54e39ca94f72f6bb9576d1195db6fa2442e",
|
"sha256:6703844a52d3588f951883005efcf555e49566a48afd4db4e965d69b883980d3",
|
||||||
"sha256:c9ce7eccdcb901a2c75d326ea134e0886abfbea5f93e91cc95de9507c0816c44"
|
"sha256:a18d870ef2ffca2b8463c0070ad17b5978056f403fb64e3f15fe62a52db21cc0"
|
||||||
],
|
],
|
||||||
"version": "==4.1.0"
|
"version": "==4.2.0"
|
||||||
},
|
},
|
||||||
"packaging": {
|
"packaging": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
@ -349,11 +369,11 @@
|
|||||||
},
|
},
|
||||||
"pytest": {
|
"pytest": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:54713b26c97538db6ff0703a12b19aeaeb60b5e599de542e7fca0ec83b9038e8",
|
"sha256:39555d023af3200d004d09e51b4dd9fdd828baa863cded3fd6ba2f29f757ae2d",
|
||||||
"sha256:829230122facf05a5f81a6d4dfe6454a04978ea3746853b2b84567ecf8e5c526"
|
"sha256:c76e93f3145a44812955e8d46cdd302d8a45fbfc7bf22be24fe231f9d8d8853a"
|
||||||
],
|
],
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==3.5.1"
|
"version": "==3.6.0"
|
||||||
},
|
},
|
||||||
"pytest-asyncio": {
|
"pytest-asyncio": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
|||||||
@ -49,13 +49,20 @@ class RedBase(BotBase):
|
|||||||
enable_sentry=None,
|
enable_sentry=None,
|
||||||
locale="en",
|
locale="en",
|
||||||
embeds=True,
|
embeds=True,
|
||||||
|
color=15158332,
|
||||||
help__page_char_limit=1000,
|
help__page_char_limit=1000,
|
||||||
help__max_pages_in_guild=2,
|
help__max_pages_in_guild=2,
|
||||||
help__tagline="",
|
help__tagline="",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.db.register_guild(
|
self.db.register_guild(
|
||||||
prefix=[], whitelist=[], blacklist=[], admin_role=None, mod_role=None, embeds=None
|
prefix=[],
|
||||||
|
whitelist=[],
|
||||||
|
blacklist=[],
|
||||||
|
admin_role=None,
|
||||||
|
mod_role=None,
|
||||||
|
embeds=None,
|
||||||
|
use_bot_color=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.db.register_user(embeds=None)
|
self.db.register_user(embeds=None)
|
||||||
@ -92,6 +99,7 @@ class RedBase(BotBase):
|
|||||||
|
|
||||||
self.counter = Counter()
|
self.counter = Counter()
|
||||||
self.uptime = None
|
self.uptime = None
|
||||||
|
self.color = None
|
||||||
|
|
||||||
self.main_dir = bot_dir
|
self.main_dir = bot_dir
|
||||||
|
|
||||||
|
|||||||
@ -121,6 +121,20 @@ class Context(commands.Context):
|
|||||||
await query.delete()
|
await query.delete()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
async def embed_colour(self):
|
||||||
|
"""
|
||||||
|
Helper function to get the colour for an embed.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
discord.Colour:
|
||||||
|
The colour to be used
|
||||||
|
"""
|
||||||
|
if self.guild and await self.bot.db.guild(self.guild).use_bot_color():
|
||||||
|
return self.guild.me.color
|
||||||
|
else:
|
||||||
|
return self.bot.color
|
||||||
|
|
||||||
async def embed_requested(self):
|
async def embed_requested(self):
|
||||||
"""
|
"""
|
||||||
Simple helper to call bot.embed_requested
|
Simple helper to call bot.embed_requested
|
||||||
|
|||||||
@ -556,6 +556,42 @@ class Core:
|
|||||||
await ctx.bot.db.guild(ctx.guild).mod_role.set(role.id)
|
await ctx.bot.db.guild(ctx.guild).mod_role.set(role.id)
|
||||||
await ctx.send(_("The mod role for this guild has been set."))
|
await ctx.send(_("The mod role for this guild has been set."))
|
||||||
|
|
||||||
|
@_set.command(aliases=["usebotcolor"])
|
||||||
|
@checks.guildowner()
|
||||||
|
@commands.guild_only()
|
||||||
|
async def usebotcolour(self, ctx):
|
||||||
|
"""
|
||||||
|
Toggle whether to use the bot owner-configured colour for embeds.
|
||||||
|
|
||||||
|
Default is to not use the bot's configured colour, in which case the
|
||||||
|
colour used will be the colour of the bot's top role.
|
||||||
|
"""
|
||||||
|
current_setting = await ctx.bot.db.guild(ctx.guild).use_bot_color()
|
||||||
|
await ctx.bot.db.guild(ctx.guild).use_bot_color.set(not current_setting)
|
||||||
|
await ctx.send(
|
||||||
|
_("The bot {} use its configured color for embeds.").format(
|
||||||
|
_("will not") if current_setting else _("will")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@_set.command(aliases=["color"])
|
||||||
|
@checks.is_owner()
|
||||||
|
async def colour(self, ctx, *, colour: discord.Colour = None):
|
||||||
|
"""
|
||||||
|
Sets a default colour to be used for the bot's embeds.
|
||||||
|
|
||||||
|
Acceptable values cor the colour parameter can be found at:
|
||||||
|
|
||||||
|
http://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#discord.ext.commands.ColourConverter
|
||||||
|
"""
|
||||||
|
if colour is None:
|
||||||
|
ctx.bot.color = discord.Color.red()
|
||||||
|
await ctx.bot.db.color.set(discord.Color.red().value)
|
||||||
|
return await ctx.send(_("The color has been reset."))
|
||||||
|
ctx.bot.color = colour
|
||||||
|
await ctx.bot.db.color.set(colour.value)
|
||||||
|
await ctx.send(_("The color has been set."))
|
||||||
|
|
||||||
@_set.command()
|
@_set.command()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
async def avatar(self, ctx, url: str):
|
async def avatar(self, ctx, url: str):
|
||||||
|
|||||||
@ -172,6 +172,7 @@ def init_events(bot, cli_flags):
|
|||||||
if invite_url:
|
if invite_url:
|
||||||
print("\nInvite URL: {}\n".format(invite_url))
|
print("\nInvite URL: {}\n".format(invite_url))
|
||||||
|
|
||||||
|
bot.color = discord.Colour(await bot.db.color())
|
||||||
if bot.rpc_enabled:
|
if bot.rpc_enabled:
|
||||||
await bot.rpc.initialize()
|
await bot.rpc.initialize()
|
||||||
|
|
||||||
|
|||||||
@ -72,10 +72,12 @@ class Help(formatter.HelpFormatter):
|
|||||||
def avatar(self):
|
def avatar(self):
|
||||||
return self.context.bot.user.avatar_url_as(format="png")
|
return self.context.bot.user.avatar_url_as(format="png")
|
||||||
|
|
||||||
@property
|
async def color(self):
|
||||||
def color(self):
|
|
||||||
if self.pm_check(self.context):
|
if self.pm_check(self.context):
|
||||||
return 0
|
return self.context.bot.color
|
||||||
|
else:
|
||||||
|
if await self.context.bot.db.guild(self.context.guild).use_bot_color():
|
||||||
|
return self.context.bot.color
|
||||||
else:
|
else:
|
||||||
return self.me.color
|
return self.me.color
|
||||||
|
|
||||||
@ -250,7 +252,7 @@ class Help(formatter.HelpFormatter):
|
|||||||
field_groups = self.group_fields(emb["fields"], page_char_limit)
|
field_groups = self.group_fields(emb["fields"], page_char_limit)
|
||||||
|
|
||||||
for i, group in enumerate(field_groups, 1):
|
for i, group in enumerate(field_groups, 1):
|
||||||
embed = discord.Embed(color=self.color, **emb["embed"])
|
embed = discord.Embed(color=await self.color(), **emb["embed"])
|
||||||
|
|
||||||
if len(field_groups) > 1:
|
if len(field_groups) > 1:
|
||||||
description = "{} *- Page {} of {}*".format(
|
description = "{} *- Page {} of {}*".format(
|
||||||
@ -269,26 +271,26 @@ class Help(formatter.HelpFormatter):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def simple_embed(self, ctx, title=None, description=None, color=None):
|
async def simple_embed(self, ctx, title=None, description=None, color=None):
|
||||||
# Shortcut
|
# Shortcut
|
||||||
self.context = ctx
|
self.context = ctx
|
||||||
if color is None:
|
if color is None:
|
||||||
color = self.color
|
color = await self.color()
|
||||||
embed = discord.Embed(title=title, description=description, color=color)
|
embed = discord.Embed(title=title, description=description, color=color)
|
||||||
embed.set_footer(text=ctx.bot.formatter.get_ending_note())
|
embed.set_footer(text=ctx.bot.formatter.get_ending_note())
|
||||||
embed.set_author(**self.author)
|
embed.set_author(**self.author)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
def cmd_not_found(self, ctx, cmd, color=None):
|
async def cmd_not_found(self, ctx, cmd, color=None):
|
||||||
# Shortcut for a shortcut. Sue me
|
# Shortcut for a shortcut. Sue me
|
||||||
out = fuzzy_command_search(ctx, " ".join(ctx.args[1:]))
|
out = fuzzy_command_search(ctx, " ".join(ctx.args[1:]))
|
||||||
embed = self.simple_embed(
|
embed = await self.simple_embed(
|
||||||
ctx, title="Command {} not found.".format(cmd), description=out, color=color
|
ctx, title="Command {} not found.".format(cmd), description=out, color=color
|
||||||
)
|
)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
def cmd_has_no_subcommands(self, ctx, cmd, color=None):
|
async def cmd_has_no_subcommands(self, ctx, cmd, color=None):
|
||||||
embed = self.simple_embed(
|
embed = await self.simple_embed(
|
||||||
ctx, title=ctx.bot.command_has_no_subcommands.format(cmd), color=color
|
ctx, title=ctx.bot.command_has_no_subcommands.format(cmd), color=color
|
||||||
)
|
)
|
||||||
return embed
|
return embed
|
||||||
@ -324,7 +326,7 @@ async def help(ctx, *cmds: str):
|
|||||||
command = ctx.bot.all_commands.get(name)
|
command = ctx.bot.all_commands.get(name)
|
||||||
if command is None:
|
if command is None:
|
||||||
if use_embeds:
|
if use_embeds:
|
||||||
await destination.send(embed=ctx.bot.formatter.cmd_not_found(ctx, name))
|
await destination.send(embed=await ctx.bot.formatter.cmd_not_found(ctx, name))
|
||||||
else:
|
else:
|
||||||
await destination.send(
|
await destination.send(
|
||||||
ctx.bot.command_not_found.format(name, fuzzy_command_search(ctx, name))
|
ctx.bot.command_not_found.format(name, fuzzy_command_search(ctx, name))
|
||||||
@ -339,7 +341,7 @@ async def help(ctx, *cmds: str):
|
|||||||
command = ctx.bot.all_commands.get(name)
|
command = ctx.bot.all_commands.get(name)
|
||||||
if command is None:
|
if command is None:
|
||||||
if use_embeds:
|
if use_embeds:
|
||||||
await destination.send(embed=ctx.bot.formatter.cmd_not_found(ctx, name))
|
await destination.send(embed=await ctx.bot.formatter.cmd_not_found(ctx, name))
|
||||||
else:
|
else:
|
||||||
await destination.send(
|
await destination.send(
|
||||||
ctx.bot.command_not_found.format(name, fuzzy_command_search(ctx, name))
|
ctx.bot.command_not_found.format(name, fuzzy_command_search(ctx, name))
|
||||||
@ -352,7 +354,9 @@ async def help(ctx, *cmds: str):
|
|||||||
command = command.all_commands.get(key)
|
command = command.all_commands.get(key)
|
||||||
if command is None:
|
if command is None:
|
||||||
if use_embeds:
|
if use_embeds:
|
||||||
await destination.send(embed=ctx.bot.formatter.cmd_not_found(ctx, key))
|
await destination.send(
|
||||||
|
embed=await ctx.bot.formatter.cmd_not_found(ctx, key)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await destination.send(
|
await destination.send(
|
||||||
ctx.bot.command_not_found.format(key, fuzzy_command_search(ctx, name))
|
ctx.bot.command_not_found.format(key, fuzzy_command_search(ctx, name))
|
||||||
@ -361,10 +365,10 @@ async def help(ctx, *cmds: str):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
if use_embeds:
|
if use_embeds:
|
||||||
await destination.send(
|
await destination.send(
|
||||||
embed=ctx.bot.formatter.simple_embed(
|
embed=await ctx.bot.formatter.simple_embed(
|
||||||
ctx,
|
ctx,
|
||||||
title='Command "{0.name}" has no subcommands.'.format(command),
|
title='Command "{0.name}" has no subcommands.'.format(command),
|
||||||
color=ctx.bot.formatter.color,
|
color=await ctx.bot.formatter.color(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user