4
1
Fork 1
This repository has been archived on 2024-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
qBitDownload-Bot/tubot/db/types.py

68 lines
1.2 KiB
Python
Raw Normal View History

# -*- 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)