# -*- coding: utf-8 -*- #################################### # DataBase module abstract classes # #################################### # Imports from abc import ABC, abstractmethod from tubot.static.abc import IValidatable from tubot.db.types import CacheDBTypes, UserStates class CacheDB(IValidatable, ABC): """ Abstract class for CacheDB """ _ctype: CacheDBTypes def __init__(self) -> None: if self._ctype is None: raise NotImplementedError("CacheDB type not implemented") # Users @abstractmethod async def add_user(self, tg_id: int, name: str) -> None: """ Add user to cache db :param tg_id: User telegram id :param name: User telegram name """ raise NotImplementedError @abstractmethod async def user_state(self, tg_id: int) -> UserStates: """ Get user state :param tg_id: User telegram id :return: Status of user """ raise NotImplementedError @abstractmethod async def change_user_state(self, tg_id: int, status: UserStates) -> None: """ Change user state :param tg_id: User telegram id :param status: New user status """ raise NotImplementedError @abstractmethod async def auth_user(self, tg_id: int) -> None: """ Auth user :param tg_id: User telegram id """ raise NotImplementedError @abstractmethod async def is_user_auth(self, tg_id: int) -> bool: """ Check if user is already auth :param tg_id: User telegram id """ raise NotImplementedError # Dirs @abstractmethod async def cache_dirs(self, dirs: dict, expire: int) -> None: """ Cache dirs from DirectoryGetter :param dirs: Dirs dict :param expire: Expire time (in seconds) """ raise NotImplementedError @property @abstractmethod async def get_dirs(self) -> dict: """ Returns precached dirs :return: Dirs dict """ raise NotImplementedError