Update utils
This commit is contained in:
parent
c6304b10bf
commit
6fad4f3787
2 changed files with 8 additions and 25 deletions
|
@ -5,9 +5,7 @@ from pkgutil import iter_modules
|
||||||
from typing import Any, Callable, Iterable, Optional, TypeVar
|
from typing import Any, Callable, Iterable, Optional, TypeVar
|
||||||
|
|
||||||
import git
|
import git
|
||||||
from dis_snek.models.discord.embed import Color, Embed
|
from dis_snek.models.discord.embed import Embed
|
||||||
from dis_snek.models.discord.message import Message
|
|
||||||
from discord.ext import commands
|
|
||||||
|
|
||||||
import jarvis.cogs
|
import jarvis.cogs
|
||||||
import jarvis.db
|
import jarvis.db
|
||||||
|
@ -28,15 +26,16 @@ def build_embed(
|
||||||
) -> Embed:
|
) -> Embed:
|
||||||
"""Embed builder utility function."""
|
"""Embed builder utility function."""
|
||||||
if not timestamp:
|
if not timestamp:
|
||||||
timestamp = datetime.utcnow()
|
timestamp = datetime.now()
|
||||||
embed = Embed(
|
embed = Embed(
|
||||||
title=title,
|
title=title,
|
||||||
description=description,
|
description=description,
|
||||||
color=parse_color_hex(color),
|
color=color,
|
||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
fields=fields,
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
for field in fields:
|
||||||
|
embed.add_field(**field.to_dict())
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,15 +60,6 @@ def unconvert_bytesize(size: int, ending: str) -> int:
|
||||||
return round(size * (1024 ** sizes.index(ending)))
|
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:
|
def get_extensions(path: str = jarvis.cogs.__path__) -> list:
|
||||||
"""Get J.A.R.V.I.S. cogs."""
|
"""Get J.A.R.V.I.S. cogs."""
|
||||||
config = get_config()
|
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]
|
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:
|
def update() -> int:
|
||||||
"""J.A.R.V.I.S. update utility."""
|
"""J.A.R.V.I.S. update utility."""
|
||||||
repo = git.Repo(".")
|
repo = git.Repo(".")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""Permissions wrappers."""
|
"""Permissions wrappers."""
|
||||||
from dis_snek import Context, Permissions
|
from dis_snek import InteractionContext, Permissions
|
||||||
|
|
||||||
from jarvis.config import get_config
|
from jarvis.config import get_config
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ from jarvis.config import get_config
|
||||||
def user_is_bot_admin() -> bool:
|
def user_is_bot_admin() -> bool:
|
||||||
"""Check if a user is a J.A.R.V.I.S. admin."""
|
"""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."""
|
"""Command check predicate."""
|
||||||
if getattr(get_config(), "admins", None):
|
if getattr(get_config(), "admins", None):
|
||||||
return ctx.author.id in get_config().admins
|
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:
|
def admin_or_permissions(*perms: list) -> bool:
|
||||||
"""Check if a user is an admin or has other perms."""
|
"""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
|
"""Extended check predicate.""" # noqa: D401
|
||||||
is_admin = ctx.author.has_permission(Permissions.ADMINISTRATOR)
|
is_admin = ctx.author.has_permission(Permissions.ADMINISTRATOR)
|
||||||
has_other = any(ctx.author.has_permission(perm) for perm in perms)
|
has_other = any(ctx.author.has_permission(perm) for perm in perms)
|
||||||
|
|
Loading…
Add table
Reference in a new issue