68 lines
1.2 KiB
Python
68 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
#############################
|
|
# Types for DataBase module #
|
|
#############################
|
|
|
|
# Imports
|
|
from enum import Enum
|
|
|
|
|
|
class CacheDBTypes(Enum):
|
|
"""
|
|
Types of CacheDB
|
|
"""
|
|
|
|
PythonPKL = "python"
|
|
Redis = "redis"
|
|
|
|
|
|
class UserStates(Enum):
|
|
"""
|
|
Types of User status
|
|
"""
|
|
|
|
IDLE = "IDLE"
|
|
DIRS = "DIRS"
|
|
WAIT_FOR_TORRENT = "WAIT_FOR_TORRENT"
|
|
|
|
|
|
class User(object):
|
|
"""
|
|
User class
|
|
"""
|
|
|
|
tg_id: int
|
|
name: str
|
|
state: UserStates = UserStates.IDLE
|
|
auth: bool = False
|
|
|
|
def __init__(
|
|
self,
|
|
tg_id: int,
|
|
name: str,
|
|
state: UserStates = UserStates.IDLE,
|
|
auth: bool = False,
|
|
) -> None:
|
|
self.tg_id = tg_id
|
|
self.name = name
|
|
self.state = state
|
|
self.auth = auth
|
|
|
|
@property
|
|
def to_dict(self):
|
|
return {
|
|
"tg_id": self.tg_id,
|
|
"name": self.name,
|
|
"state": self.state.value,
|
|
"auth": self.auth,
|
|
}
|
|
|
|
@classmethod
|
|
def from_dict(cls, usr: dict) -> "User":
|
|
tg = usr["tg_id"]
|
|
name = usr["name"]
|
|
state = UserStates(usr["state"])
|
|
auth = usr["auth"]
|
|
return cls(tg, name, state, auth)
|