diff --git a/simplematrixbotlib/api.py b/simplematrixbotlib/api.py index 1d87b3d..aaf1e1f 100644 --- a/simplematrixbotlib/api.py +++ b/simplematrixbotlib/api.py @@ -22,7 +22,7 @@ async def check_valid_homeserver(homeserver: str) -> bool: async with aiohttp.ClientSession() as session: try: async with session.get( - f'{homeserver}/_matrix/client/versions') as response: + f'{homeserver}/_matrix/client/versions',proxy=os.environ.get('https_proxy')) as response: if response.status == 200: return True except aiohttp.client_exceptions.ClientConnectorError: @@ -91,11 +91,13 @@ async def login(self): store_sync_tokens=True, encryption_enabled=self.config.encryption_enabled) store_path = self.config.store_path + proxy = self.config.proxy or os.environ.get('https_proxy',os.environ.get('HTTPS_PROXY')) os.makedirs(store_path, mode=0o750, exist_ok=True) self.async_client = AsyncClient(homeserver=self.creds.homeserver, user=self.creds.username, device_id=self.creds.device_id, store_path=store_path, + proxy=proxy, config=client_config) if self.creds.access_token: diff --git a/simplematrixbotlib/config.py b/simplematrixbotlib/config.py index f2def07..743ed49 100644 --- a/simplematrixbotlib/config.py +++ b/simplematrixbotlib/config.py @@ -44,6 +44,7 @@ class Config: _join_on_invite: bool = True _encryption_enabled: bool = ENCRYPTION_ENABLED _emoji_verify: bool = False # So users who enable it are aware of required interactivity + _proxy: str = None # So users who enable it are aware of required interactivity _ignore_unverified_devices: bool = True # True by default in Element # TODO: auto-ignore/auto-blacklist devices/users # _allowed_unverified_devices etc @@ -120,6 +121,20 @@ def emoji_verify(self) -> bool: def emoji_verify(self, value: bool) -> None: self._emoji_verify = value and self.encryption_enabled + @property + def proxy(self) -> str: + """ + Returns + ------- + string + Whether a proxy, and which should be used to communicate. + """ + return self._proxy + + @proxy.setter + def proxy(self, value: str) -> None: + self._proxy = value + @property def store_path(self) -> str: """