Add CacheDB abstract class

- init tubot.db
- init tubot.db.types
- init tubot.db.abc
- add CacheDBTypes enum
- add UserStates enum
- add CacheDB abstract class
This commit is contained in:
trueold89 2024-08-05 15:40:52 +03:00
parent ebca2172f4
commit ba696f4c56
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
3 changed files with 117 additions and 1 deletions

View File

@ -8,5 +8,5 @@ setup(
author_email="root@orudo.ru", author_email="root@orudo.ru",
description="A simple Telegram bot that will allow you to upload torrent files / magnet links to a remote Torrent server (qBitTorrent, Transmission, etc.)", description="A simple Telegram bot that will allow you to upload torrent files / magnet links to a remote Torrent server (qBitTorrent, Transmission, etc.)",
install_requires=["aiohttp>=3.10.0", "aiofiles>=24.1.0", "aiofiles>=24.1.0"], install_requires=["aiohttp>=3.10.0", "aiofiles>=24.1.0", "aiofiles>=24.1.0"],
packages=["tubot", "tubot.static", "tubot.torrent", "tubot.dirgetter"], packages=["tubot", "tubot.static", "tubot.torrent", "tubot.dirgetter", "db"],
) )

94
tubot/db/abc.py Normal file
View File

@ -0,0 +1,94 @@
# -*- 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

22
tubot/db/types.py Normal file
View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
#############################
# Types for DataBase module #
#############################
# Imports
from enum import Enum
class CacheDBTypes(Enum):
"""
Types of CacheDB
"""
...
class UserStates(Enum):
"""
Types of User status
"""
...