diff --git a/leveler/commands/lvladmin/basecmd.py b/leveler/commands/lvladmin/basecmd.py index d594f6f0..461de0cc 100644 --- a/leveler/commands/lvladmin/basecmd.py +++ b/leveler/commands/lvladmin/basecmd.py @@ -1,4 +1,3 @@ -import discord from redbot.core import commands from leveler.abc import CompositeMetaClass diff --git a/leveler/commands/lvladmin/roles.py b/leveler/commands/lvladmin/roles.py index 224722f0..0e671990 100644 --- a/leveler/commands/lvladmin/roles.py +++ b/leveler/commands/lvladmin/roles.py @@ -1,4 +1,5 @@ from collections import OrderedDict +from typing import Union import discord from redbot.core import commands @@ -68,27 +69,28 @@ async def linkrole( @commands.mod_or_permissions(manage_roles=True) @role.command(name="unlink", usage="") @commands.guild_only() - async def unlinkrole(self, ctx, *, role_to_unlink: discord.Role): + async def unlinkrole(self, ctx, *, role_to_unlink: Union[discord.Role, str]): """Delete a role/level association.""" server = ctx.guild + role_to_unlink = ( + role_to_unlink.name if isinstance(role_to_unlink, discord.Role) else role_to_unlink + ) server_roles = await self.db.roles.find_one({"server_id": str(server.id)}) roles = server_roles["roles"] - if role_to_unlink.name in roles: + if role_to_unlink in roles: await ctx.send( "**Role/Level association `{}`/`{}` removed.**".format( - role_to_unlink.name, roles[role_to_unlink.name]["level"] + role_to_unlink, roles[role_to_unlink]["level"] ) ) - del roles[role_to_unlink.name] + del roles[role_to_unlink] await self.db.roles.update_one( {"server_id": str(server.id)}, {"$set": {"roles": roles}} ) else: - await ctx.send( - "**The `{}` role is not linked to any levels!**".format(role_to_unlink.name) - ) + await ctx.send("**The `{}` role is not linked to any levels!**".format(role_to_unlink)) @commands.mod_or_permissions(manage_roles=True) @role.command(name="listlinks") diff --git a/leveler/commands/lvlset/levelup.py b/leveler/commands/lvlset/levelup.py index d703b5e4..8209620b 100644 --- a/leveler/commands/lvlset/levelup.py +++ b/leveler/commands/lvlset/levelup.py @@ -1,5 +1,7 @@ import random +from typing import Union +import discord from redbot.core import commands from leveler.abc import MixinMeta @@ -19,19 +21,17 @@ async def levelupset(self, ctx): @levelupset.command(name="color", alias=["colour"]) @commands.guild_only() - async def levelupcolors(self, ctx, section: str, color: str = None): + async def levelupcolors(self, ctx, section: str, color: Union[discord.Color, str]): """Set levelup color. Section can only be `info`. - Color can be : `default`, `white`, `HEX code` (#000000) or `auto`. + Color can be : `default`, `HEX code` (#000000) or `auto`. e.g: `[p]lvlset color info default`""" user = ctx.author - server = ctx.guild userinfo = await self.db.users.find_one({"user_id": str(user.id)}) section = section.lower() default_info_color = (30, 30, 30, 200) - white_info_color = (150, 150, 150, 180) default_a = 200 if await self.config.guild(ctx.guild).disabled(): @@ -61,17 +61,13 @@ async def levelupcolors(self, ctx, section: str, color: str = None): for hex_color in hex_colors: color_temp = await self._hex_to_rgb(hex_color, default_a) set_color.append(color_temp) - elif color == "white": - set_color = [white_info_color] elif color == "default": if section == "info": set_color = [default_info_color] - elif await self._is_hex(color): - set_color = [await self._hex_to_rgb(color, default_a)] + elif isinstance(color, discord.Color): + set_color = [color.r, color.g, color.b, default_a] else: - await ctx.send( - "**Not a valid color. Must be `default` `HEX color`, `white` or `auto`.**" - ) + await ctx.send("**Not a valid color. Must be `default` `HEX color` or `auto`.**") return await self.db.users.update_one( diff --git a/leveler/commands/lvlset/profile.py b/leveler/commands/lvlset/profile.py index a5d84e51..e28b48c8 100644 --- a/leveler/commands/lvlset/profile.py +++ b/leveler/commands/lvlset/profile.py @@ -1,5 +1,7 @@ import random +from typing import Union +import discord from redbot.core import commands from leveler.abc import MixinMeta @@ -18,7 +20,7 @@ async def profileset(self, ctx): @profileset.command(name="color", alias=["colour"]) @commands.guild_only() - async def profilecolors(self, ctx, section: str, color: str): + async def profilecolors(self, ctx, section: str, color: Union[discord.Color, str]): """Set profile color. For section, you can choose: `exp`, `rep`, `badge`, `info` or `all`. @@ -29,7 +31,6 @@ async def profilecolors(self, ctx, section: str, color: str): section = section.lower() default_info_color = (30, 30, 30, 200) - white_info_color = (150, 150, 150, 180) default_rep = (92, 130, 203, 230) default_badge = (128, 151, 165, 230) default_exp = (255, 255, 255, 230) @@ -86,9 +87,6 @@ async def profilecolors(self, ctx, section: str, color: str): for hex_color in hex_colors: color_temp = await self._hex_to_rgb(hex_color, default_a) set_color.append(color_temp) - - elif color == "white": - set_color = [white_info_color] elif color == "default": if section == "exp": set_color = [default_exp] @@ -105,12 +103,10 @@ async def profilecolors(self, ctx, section: str, color: str): default_badge, default_info_color, ] - elif await self._is_hex(color): - set_color = [await self._hex_to_rgb(color, default_a)] + elif isinstance(color, discord.Color): + set_color = [color.r, color.g, color.b, default_a] else: - await ctx.send( - "**Not a valid color. Must be `default`, `HEX color`, `white` or `auto`.**" - ) + await ctx.send("**Not a valid color. Must be `default`, `HEX color` or `auto`.**") return if section == "all": diff --git a/leveler/commands/lvlset/rank.py b/leveler/commands/lvlset/rank.py index 62217781..db651744 100644 --- a/leveler/commands/lvlset/rank.py +++ b/leveler/commands/lvlset/rank.py @@ -1,5 +1,7 @@ import random +from typing import Union +import discord from redbot.core import commands from leveler.abc import MixinMeta @@ -18,7 +20,7 @@ async def rankset(self, ctx): @rankset.command(name="color", alias=["colour"]) @commands.guild_only() - async def rankcolors(self, ctx, section: str, color: str = None): + async def rankcolors(self, ctx, section: str, color: Union[discord.Color, str]): """Set rank color. For section, you can choose: `exp`, `info` or `all`. @@ -85,8 +87,8 @@ async def rankcolors(self, ctx, section: str, color: str = None): default_badge, default_info_color, ] - elif await self._is_hex(color): - set_color = [await self._hex_to_rgb(color, default_a)] + elif isinstance(color, discord.Color): + set_color = [color.r, color.g, color.b, default_a] else: await ctx.send( "**Not a valid color. Must be `default`, `HEX color`, `white or `auto`.**"