aboutsummaryrefslogtreecommitdiffstats
path: root/slack/proxy.py
blob: ba8e81da5c61ffa0b1b19455b9ab9a9c36209ae3 (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import annotations

import weechat


class Proxy:
    @property
    def name(self):
        return weechat.config_string(weechat.config_get("weechat.network.proxy_curl"))

    @property
    def enabled(self):
        return bool(self.type)

    @property
    def _proxy_option_prefix(self):
        return f"weechat.proxy.{self.name}"

    @property
    def type(self):
        return weechat.config_string(
            weechat.config_get(f"{self._proxy_option_prefix}.type")
        )

    @property
    def address(self):
        return weechat.config_string(
            weechat.config_get(f"{self._proxy_option_prefix}.address")
        )

    @property
    def port(self):
        return weechat.config_integer(
            weechat.config_get(f"{self._proxy_option_prefix}.port")
        )

    @property
    def ipv6(self):
        return weechat.config_boolean(
            weechat.config_get(f"{self._proxy_option_prefix}.ipv6")
        )

    @property
    def username(self):
        return weechat.config_string(
            weechat.config_get(f"{self._proxy_option_prefix}.username")
        )

    @property
    def password(self):
        return weechat.config_string(
            weechat.config_get(f"{self._proxy_option_prefix}.password")
        )

    @property
    def curl_option(self):
        if not self.enabled:
            return ""

        user = (
            f"{self.username}:{self.password}@"
            if self.username and self.password
            else ""
        )
        return f"-x{self.type}://{user}{self.address}:{self.port}"