Skip to content

Commit

Permalink
You should have trusted me.
Browse files Browse the repository at this point in the history
fixes #41
  • Loading branch information
fixator10 committed Aug 25, 2020
1 parent 04f990a commit 5c012f9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
1 change: 0 additions & 1 deletion leveler/commands/lvladmin/basecmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import discord
from redbot.core import commands

from leveler.abc import CompositeMetaClass
Expand Down
16 changes: 9 additions & 7 deletions leveler/commands/lvladmin/roles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import OrderedDict
from typing import Union

import discord
from redbot.core import commands
Expand Down Expand Up @@ -68,27 +69,28 @@ async def linkrole(
@commands.mod_or_permissions(manage_roles=True)
@role.command(name="unlink", usage="<role>")
@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")
Expand Down
18 changes: 7 additions & 11 deletions leveler/commands/lvlset/levelup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import random
from typing import Union

import discord
from redbot.core import commands

from leveler.abc import MixinMeta
Expand All @@ -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():
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 6 additions & 10 deletions leveler/commands/lvlset/profile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import random
from typing import Union

import discord
from redbot.core import commands

from leveler.abc import MixinMeta
Expand All @@ -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`.
Expand 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)
Expand Down Expand Up @@ -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]
Expand All @@ -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":
Expand Down
8 changes: 5 additions & 3 deletions leveler/commands/lvlset/rank.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import random
from typing import Union

import discord
from redbot.core import commands

from leveler.abc import MixinMeta
Expand All @@ -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`.
Expand Down Expand Up @@ -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`.**"
Expand Down

0 comments on commit 5c012f9

Please sign in to comment.