aboutsummaryrefslogtreecommitdiff
path: root/velascobot2/utils.py
blob: 61b754e55ffa6873ba32a8ac3396930c8f88c0a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import logging
from enum import StrEnum

logger = logging.getLogger(__name__)


class GraphicType(StrEnum):
    STICKER = "STICKER"
    ANIMATION = "ANIMATION"
    VIDEO = "VIDEO"


class Response(StrEnum):
    TEXT = "TEXT"
    GRAPHIC = "GRAPHIC"


class ChatData:
    def __init__(
        self,
        id: str,
        chat_type: str,
        name: str,
        message_period: int = 10,
        answer_chance: float = 0.5,
        restricted: bool = False,
        silenced: bool = False,
    ) -> None:
        self.id = id
        self.type = chat_type
        self.name = name
        self.message_period = message_period
        self.answer_chance = answer_chance
        self.restricted = restricted
        self.silenced = silenced

    @staticmethod
    def from_sql_row(row: tuple[str, str, str, int, float, int, int]):
        logger.debug(f"From SQL row: {repr(row)}")
        return ChatData(
            row[0],
            row[1],
            row[2],
            int(row[3]),
            float(row[4]),
            int(row[5]) == 1,
            int(row[6]) == 1,
        )