1
0
Fork 0
mirror of synced 2024-05-18 19:42:28 +12:00

Add a command to control colours used

This commit is contained in:
phxntxm 2018-01-01 18:06:24 -06:00
parent 0ff6704206
commit 164d62a179
2 changed files with 68 additions and 2 deletions

View file

@ -273,6 +273,27 @@ class Administration:
fmt = "The birthday announcements have just been turned {}".format("on" if allowed else "off")
await ctx.send(fmt)
@commands.command()
@commands.guild_only()
@utils.custom_perms(manage_guild=True)
@utils.check_restricted()
async def allowcolours(self, ctx, setting):
"""Turns on/off the ability to use colour roles in this server
EXAMPLE: !allowcolours on
RESULT: Colour roles can now be used in this server"""
if setting.lower() in ['on', 'yes', 'true']:
allowed = True
else:
allowed = False
entry = {
'server_id': str(ctx.message.guild.id),
'colour_roles_allowed': allowed
}
self.bot.db.save('server_settings', entry)
fmt = "The ability to use colour roles have just been turned {}".format("on" if allowed else "off")
await ctx.send(fmt)
@commands.command()
@commands.guild_only()
@utils.custom_perms(manage_guild=True)
@ -845,7 +866,7 @@ class Administration:
@commands.guild_only()
@utils.custom_perms(manage_guild=True)
@utils.check_restricted()
async def _welcome_message(self, ctx, *, msg = None):
async def _welcome_message(self, ctx, *, msg):
"""A command to customize the welcome/goodbye message
There are a couple things that can be set to customize the message
{member} - Will mention the user joining
@ -857,7 +878,7 @@ class Administration:
parent = ctx.message.content.split()[0]
parent = parent[len(ctx.prefix):]
if msg and re.search("{.*token.*}", msg):
if re.search("{.*token.*}", msg):
await ctx.send("Illegal content in {} message".format(parent))
else:
try:

View file

@ -13,6 +13,51 @@ class Roles:
def __init__(self, bot):
self.bot = bot
@commands.command(aliases=['color'])
@commands.guild_only()
@commands.check(utils.is_owner)
# @utils.custom_perms(send_messages=True)
@utils.check_restricted()
async def colour(self, ctx, role_colour: discord.Colour):
"""Used to give yourself a role matching the colour given.
If the role doesn't exist, it will be created. Names such as red, blue, yellow, etc. can be used.
Additionally, hex codes can be used as well
EXAMPLE: !colour red
RESULT: A role that matches red (#e74c3c) will be given to you"""
if self.bot.db.load('server_settings', key=ctx.guild.id, pluck="colour_roles_allowed"):
await ctx.send("Colour roles not allowed on this server! "
"The command `allowcolours` must be ran to enable them!")
return
if not ctx.me.guild_permissions.manage_roles:
await ctx.send("Error: I need manage_roles to be able to use this command")
return
# The convention we'll use for the name
name = "Bonfire {}".format(role_colour)
# Try to find a role that matches our convention, Name #000000 with the colour matching
role = discord.utils.get(ctx.guild.roles, name=name, colour=role_colour)
# The colour roles they currently have, we need to remove them if they want a new colour
old_roles = [r for r in ctx.author.roles if re.match(r'Bonfire #[0-9a-zA-Z]+', r.name)]
if old_roles:
await ctx.author.remove_roles([old_roles])
# If the role doesn't exist, we need to create it
if not role:
opts = {
"name": name,
"colour": role_colour
}
await ctx.guild.create_role(**opts)
# Now add the role
await ctx.author.add_roles(role)
await ctx.send("I have just given you your requested colour!")
@commands.group(aliases=['roles'], invoke_without_command=True)
@commands.guild_only()
@utils.custom_perms(send_messages=True)