Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

add support to communicate via a proxy #167 #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion simplematrixbotlib/api.py
Original file line number Diff line number Diff line change
@@ -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:
15 changes: 15 additions & 0 deletions simplematrixbotlib/config.py
Original file line number Diff line number Diff line change
@@ -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:
"""