make it work with pantalaimon and encryption
This commit is contained in:
parent
d7d68f4d42
commit
c56bf9160e
|
@ -13,6 +13,8 @@ pip install -r requirements.txt
|
|||
|
||||
Copy `config.sample.yaml` to `config.yaml` and fill it out with your bot's auth and your OpenAI API key.
|
||||
|
||||
[Pantalaimon](https://github.com/matrix-org/pantalaimon) is **required** for the bot to be able to talk in encrypted rooms.
|
||||
|
||||
Then invite your bot and start a chat by prefixing your message with `!c`. The bot will create a thread (you don't need
|
||||
to use `!c` in the thread).
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ class MatrixNioGPTHelper:
|
|||
"""
|
||||
client = None
|
||||
|
||||
client_config = AsyncClientConfig(max_limit_exceeded=0, max_timeouts=0, store_sync_tokens=True, encryption_enabled=True)
|
||||
# Encryption is disabled because it's handled by Pantalaimon.
|
||||
client_config = AsyncClientConfig(max_limit_exceeded=0, max_timeouts=0, store_sync_tokens=True, encryption_enabled=False)
|
||||
|
||||
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
|
||||
|
@ -31,23 +32,23 @@ class MatrixNioGPTHelper:
|
|||
Path(self.store_path).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
self.device_name = device_name
|
||||
self.client = AsyncClient(homeserver=self.homeserver, user=self.user_id, config=self.client_config, store_path=self.store_path, device_id=device_id)
|
||||
self.client = AsyncClient(homeserver=self.homeserver, user=self.user_id, config=self.client_config, device_id=device_id)
|
||||
|
||||
async def login(self) -> tuple[bool, LoginError] | tuple[bool, LoginResponse | None]:
|
||||
try:
|
||||
# If there are no previously-saved credentials, we'll use the password
|
||||
# If there are no previously-saved credentials, we'll use the password.
|
||||
if not os.path.exists(self.auth_file):
|
||||
logger.info('Using username/password.')
|
||||
resp = await self.client.login(self.passwd, device_name=self.device_name)
|
||||
|
||||
# check that we logged in succesfully
|
||||
# check that we logged in successfully.
|
||||
if isinstance(resp, LoginResponse):
|
||||
self.write_details_to_disk(resp)
|
||||
return True, resp
|
||||
else:
|
||||
return False, resp
|
||||
else:
|
||||
# Otherwise the config file exists, so we'll use the stored credentials
|
||||
# Otherwise the config file exists, so we'll use the stored credentials.
|
||||
logger.info('Using cached credentials.')
|
||||
with open(self.auth_file, "r") as f:
|
||||
config = json.load(f)
|
||||
|
|
Loading…
Reference in New Issue