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:
parent
ebca2172f4
commit
ba696f4c56
2
setup.py
2
setup.py
|
@ -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"],
|
||||||
)
|
)
|
||||||
|
|
|
@ -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
|
|
@ -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
|
||||||
|
"""
|
||||||
|
...
|
Reference in New Issue