Completed
Push — main ( 82d873...c79b30 )
by
unknown
16s queued 12s
created

pincer._config.GatewayConfig.compressed()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from dataclasses import dataclass
5
from typing import Optional
6
7
8
@dataclass
9
class GatewayConfig:
10
    """
11
    This file is to make maintaining the library its gateway
12
        configuration easier.
13
    """
14
    socket_base_url: str = "wss://gateway.discord.gg/"
15
    version: int = 9
16
    encoding: str = "json"
17
    compression: Optional[str] = "zlib-stream"
18
19
    @classmethod
20
    def uri(cls) -> str:
21
        """
22
        :return uri:
23
            The GatewayConfig's uri.
24
        """
25
        return (
26
            f"{cls.socket_base_url}"
27
            f"?v={cls.version}"
28
            f"&encoding={cls.encoding}"
29
        ) + f"&compress={cls.compression}" * cls.compressed()
30
31
    @classmethod
32
    def compressed(cls) -> bool:
33
        """
34
        :return compressed:
35
            Whether the Gateway should compress payloads or not.
36
        """
37
        return cls.compression in ["zlib-stream", "zlib-payload"]
38