Discord-Bot-Python/helpers/checks.py
2023-01-23 14:29:07 +02:00

30 lines
793 B
Python

import json
import os
from typing import Callable, TypeVar
from discord.ext import commands
from exceptions import *
from helpers import db_manager
T = TypeVar("T")
def is_owner() -> Callable[[T], T]:
async def predicate(context: commands.Context) -> bool:
with open(f"{os.path.realpath(os.path.dirname(__file__))}/../config.json") as file:
data = json.load(file)
if context.author.id not in data["owners"]:
raise UserNotOwner
return True
return commands.check(predicate)
def not_blacklisted() -> Callable[[T], T]:
async def predicate(context: commands.Context) -> bool:
if await db_manager.is_blacklisted(context.author.id):
raise UserBlacklisted
return True
return commands.check(predicate)