fix encryption issues, print traceback
This commit is contained in:
parent
c91b0ac944
commit
7affc308a7
23
main.py
23
main.py
|
@ -7,6 +7,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
import openai
|
import openai
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -65,13 +66,16 @@ def retry(msg=None):
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
# Logging in with a new device each time seems to fix encryption errors
|
||||||
|
device_id = str(uuid4())
|
||||||
|
|
||||||
matrix_helper = MatrixNioGPTHelper(
|
matrix_helper = MatrixNioGPTHelper(
|
||||||
auth_file=Path(config_data['bot_auth']['store_path'], 'bot_auth.json'),
|
auth_file=Path(config_data['bot_auth']['store_path'], 'bot_auth.json'),
|
||||||
user_id=config_data['bot_auth']['username'],
|
user_id=config_data['bot_auth']['username'],
|
||||||
passwd=config_data['bot_auth']['password'],
|
passwd=config_data['bot_auth']['password'],
|
||||||
homeserver=config_data['bot_auth']['homeserver'],
|
homeserver=config_data['bot_auth']['homeserver'],
|
||||||
store_path=config_data['bot_auth']['store_path'],
|
store_path=config_data['bot_auth']['store_path'],
|
||||||
device_id=config_data['bot_auth'].get('device_id')
|
device_id=device_id # config_data['bot_auth'].get('device_id')
|
||||||
)
|
)
|
||||||
client = matrix_helper.client
|
client = matrix_helper.client
|
||||||
|
|
||||||
|
@ -117,12 +121,27 @@ async def main():
|
||||||
r = await client.join(room)
|
r = await client.join(room)
|
||||||
if not isinstance(r, JoinResponse):
|
if not isinstance(r, JoinResponse):
|
||||||
logger.critical(f'Failed to join room {room}: {vars(r)}')
|
logger.critical(f'Failed to join room {room}: {vars(r)}')
|
||||||
|
time.sleep(1.5)
|
||||||
|
|
||||||
|
# Log out old devices to keep the session clean
|
||||||
|
devices = (await client.devices()).devices
|
||||||
|
device_list = [x.id for x in devices]
|
||||||
|
device_list.remove(device_id)
|
||||||
|
x = await client.delete_devices(device_list, {
|
||||||
|
"type": "m.login.password",
|
||||||
|
"user": config_data['bot_auth']['username'],
|
||||||
|
"password": config_data['bot_auth']['password']
|
||||||
|
})
|
||||||
|
|
||||||
await client.sync_forever(timeout=10000, full_state=True)
|
await client.sync_forever(timeout=10000, full_state=True)
|
||||||
except (ClientConnectionError, ServerDisconnectedError):
|
except (ClientConnectionError, ServerDisconnectedError):
|
||||||
logger.warning("Unable to connect to homeserver, retrying in 15s...")
|
logger.warning("Unable to connect to homeserver, retrying in 15s...")
|
||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
finally:
|
except Exception:
|
||||||
|
logger.critical(traceback.format_exc())
|
||||||
|
logger.critical('Sleeping 5s...')
|
||||||
|
time.sleep(5)
|
||||||
|
except KeyboardInterrupt:
|
||||||
await client.close()
|
await client.close()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class MatrixNioGPTHelper:
|
||||||
"""
|
"""
|
||||||
client = None
|
client = None
|
||||||
|
|
||||||
client_config = AsyncClientConfig(max_limit_exceeded=0, max_timeouts=0, store_sync_tokens=True, encryption_enabled=True, )
|
client_config = AsyncClientConfig(max_limit_exceeded=0, max_timeouts=0, store_sync_tokens=True, encryption_enabled=True)
|
||||||
|
|
||||||
def __init__(self, auth_file: Union[Path, str], user_id: str, passwd: str, homeserver: str, store_path: str, device_name: str = 'MatrixGPT', device_id: str = None):
|
def __init__(self, auth_file: Union[Path, str], user_id: str, passwd: str, homeserver: str, store_path: str, device_name: str = 'MatrixGPT', device_id: str = None):
|
||||||
self.auth_file = auth_file
|
self.auth_file = auth_file
|
||||||
|
|
Loading…
Reference in New Issue