| Total Complexity | 3 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Copyright Pincer 2021-Present |
||
|
|
|||
| 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 | @staticmethod |
||
| 20 | def uri() -> str: |
||
| 21 | """ |
||
| 22 | :return uri: |
||
| 23 | The GatewayConfig's uri. |
||
| 24 | """ |
||
| 25 | uri = ( |
||
| 26 | f"{GatewayConfig.socket_base_url}" |
||
| 27 | f"?v={GatewayConfig.version}" |
||
| 28 | f"&encoding={GatewayConfig.encoding}" |
||
| 29 | ) |
||
| 30 | |||
| 31 | if GatewayConfig.compressed(): |
||
| 32 | uri += f"&compress={GatewayConfig.compression}" |
||
| 33 | |||
| 34 | return uri |
||
| 35 | |||
| 36 | @staticmethod |
||
| 37 | def compressed() -> bool: |
||
| 38 | """ |
||
| 39 | :return compressed: |
||
| 40 | Whether the Gateway should compress payloads or not. |
||
| 41 | """ |
||
| 42 | return GatewayConfig.compression == "zlib-stream" |
||
| 43 |