2024-08-05 12:40:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# Types for DataBase module #
|
|
|
|
#############################
|
|
|
|
|
|
|
|
# Imports
|
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
|
|
|
class CacheDBTypes(Enum):
|
|
|
|
"""
|
|
|
|
Types of CacheDB
|
|
|
|
"""
|
2024-08-05 13:43:00 +00:00
|
|
|
|
|
|
|
PythonPKL = "python"
|
2024-08-05 18:21:13 +00:00
|
|
|
Redis = "redis"
|
2024-08-05 12:40:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserStates(Enum):
|
|
|
|
"""
|
|
|
|
Types of User status
|
|
|
|
"""
|
2024-08-05 13:43:00 +00:00
|
|
|
|
2024-08-06 10:58:19 +00:00
|
|
|
IDLE = "IDLE"
|
|
|
|
DIRS = "DIRS"
|
|
|
|
WAIT_FOR_TORRENT = "WAIT_FOR_TORRENT"
|
2024-08-05 13:43:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
class User(object):
|
|
|
|
"""
|
|
|
|
User class
|
|
|
|
"""
|
|
|
|
|
|
|
|
tg_id: int
|
|
|
|
name: str
|
2024-08-06 10:58:19 +00:00
|
|
|
state: UserStates = UserStates.IDLE
|
2024-08-05 13:43:00 +00:00
|
|
|
auth: bool = False
|
|
|
|
|
|
|
|
def __init__(
|
2024-08-06 10:58:19 +00:00
|
|
|
self,
|
|
|
|
tg_id: int,
|
|
|
|
name: str,
|
|
|
|
state: UserStates = UserStates.IDLE,
|
|
|
|
auth: bool = False,
|
2024-08-05 13:43:00 +00:00
|
|
|
) -> None:
|
|
|
|
self.tg_id = tg_id
|
|
|
|
self.name = name
|
|
|
|
self.state = state
|
|
|
|
self.auth = auth
|
|
|
|
|
|
|
|
@property
|
2024-08-06 10:58:19 +00:00
|
|
|
def to_dict(self):
|
2024-08-05 13:43:00 +00:00
|
|
|
return {
|
|
|
|
"tg_id": self.tg_id,
|
|
|
|
"name": self.name,
|
2024-08-06 10:58:19 +00:00
|
|
|
"state": self.state.value,
|
2024-08-05 13:43:00 +00:00
|
|
|
"auth": self.auth,
|
|
|
|
}
|
2024-08-06 10:58:19 +00:00
|
|
|
|
|
|
|
@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)
|