From 6fad4f37873f369b03899d0d5117dad0b9ae2d5e Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Fri, 4 Feb 2022 09:54:51 -0700 Subject: [PATCH] Update utils --- jarvis/utils/__init__.py | 27 +++++---------------------- jarvis/utils/permissions.py | 6 +++--- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/jarvis/utils/__init__.py b/jarvis/utils/__init__.py index 8306e5a..5c9a3c9 100644 --- a/jarvis/utils/__init__.py +++ b/jarvis/utils/__init__.py @@ -5,9 +5,7 @@ from pkgutil import iter_modules from typing import Any, Callable, Iterable, Optional, TypeVar import git -from dis_snek.models.discord.embed import Color, Embed -from dis_snek.models.discord.message import Message -from discord.ext import commands +from dis_snek.models.discord.embed import Embed import jarvis.cogs import jarvis.db @@ -28,15 +26,16 @@ def build_embed( ) -> Embed: """Embed builder utility function.""" if not timestamp: - timestamp = datetime.utcnow() + timestamp = datetime.now() embed = Embed( title=title, description=description, - color=parse_color_hex(color), + color=color, timestamp=timestamp, - fields=fields, **kwargs, ) + for field in fields: + embed.add_field(**field.to_dict()) return embed @@ -61,15 +60,6 @@ def unconvert_bytesize(size: int, ending: str) -> int: return round(size * (1024 ** sizes.index(ending))) -def get_prefix(bot: commands.Bot, message: Message) -> list: - """Get bot prefixes.""" - prefixes = ["!", "-", "%"] - # if not message.guild: - # return "?" - - return commands.when_mentioned_or(*prefixes)(bot, message) - - def get_extensions(path: str = jarvis.cogs.__path__) -> list: """Get J.A.R.V.I.S. cogs.""" config = get_config() @@ -77,13 +67,6 @@ def get_extensions(path: str = jarvis.cogs.__path__) -> list: return ["jarvis.cogs.{}".format(x) for x in vals] -def parse_color_hex(hex: str) -> Color: - """Convert a hex color to a d.py Color.""" - hex = hex.lstrip("#") - rgb = tuple(int(hex[i : i + 2], 16) for i in (0, 2, 4)) - return Color.from_rgb(*rgb) - - def update() -> int: """J.A.R.V.I.S. update utility.""" repo = git.Repo(".") diff --git a/jarvis/utils/permissions.py b/jarvis/utils/permissions.py index 5a401eb..a20b686 100644 --- a/jarvis/utils/permissions.py +++ b/jarvis/utils/permissions.py @@ -1,5 +1,5 @@ """Permissions wrappers.""" -from dis_snek import Context, Permissions +from dis_snek import InteractionContext, Permissions from jarvis.config import get_config @@ -7,7 +7,7 @@ from jarvis.config import get_config def user_is_bot_admin() -> bool: """Check if a user is a J.A.R.V.I.S. admin.""" - def predicate(ctx: Context) -> bool: + async def predicate(ctx: InteractionContext) -> bool: """Command check predicate.""" if getattr(get_config(), "admins", None): return ctx.author.id in get_config().admins @@ -20,7 +20,7 @@ def user_is_bot_admin() -> bool: def admin_or_permissions(*perms: list) -> bool: """Check if a user is an admin or has other perms.""" - async def predicate(ctx: Context) -> bool: + async def predicate(ctx: InteractionContext) -> bool: """Extended check predicate.""" # noqa: D401 is_admin = ctx.author.has_permission(Permissions.ADMINISTRATOR) has_other = any(ctx.author.has_permission(perm) for perm in perms)