from aiogram import types
from aiogram.dispatcher.filters import BoundFilter
import config
import dispatcher


class IsOwnerFilter(BoundFilter):
    """
    Custom filter "is_owner".
    """
    key = "is_owner"

    def __init__(self, is_owner):
        self.is_owner = is_owner

    async def check(self, message: types.Message):
        return message.from_user.id in config.BOT_OWNERS


class IsAuthFilter(BoundFilter):
    """
    Custom filter "is_owner".
    """
    key = "is_auth"

    def __init__(self, is_auth):
        self.is_owner = is_auth

    async def check(self, message: types.Message):
        query = 'SELECT user_id FROM auth_users WHERE user_id = %s'
        args = (message.from_user.id,)
        res = dispatcher.db.execute_query(query, args)
        res = bool(len(res))

        return res
