diff --git a/CHANGELOG.md b/CHANGELOG.md index aa00e3f..e03eb82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 0.3.14 (2024-05-21) + +- Fixed issue in handling of login credentials, added error handling for login failures + ### 0.3.13 (2024-05-20) - **Breaking Change**: The `ForceTools` configuration option behavior has changed. Instead of using a separate model for tools, the bot will now try to use the default chat model for tool requests, even if that model is not known to support tools. diff --git a/pyproject.toml b/pyproject.toml index 3511bed..46ac095 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ allow-direct-references = true [project] name = "matrix-gptbot" -version = "0.3.13" +version = "0.3.14" authors = [ { name = "Kumi Mitterer", email = "gptbot@kumi.email" }, diff --git a/src/gptbot/classes/bot.py b/src/gptbot/classes/bot.py index 183ee7f..41ea82d 100644 --- a/src/gptbot/classes/bot.py +++ b/src/gptbot/classes/bot.py @@ -31,6 +31,7 @@ from nio import ( RoomGetStateError, DiskDownloadResponse, MemoryDownloadResponse, + LoginError, ) from nio.store import SqliteStore @@ -243,17 +244,24 @@ class GPTBot: assert "Matrix" in config, "Matrix config not found" homeserver = config["Matrix"]["Homeserver"] - bot.matrix_client = AsyncClient(homeserver) - if ("Password" in config["Matrix"]) and config.get("Matrix", "Password"): - await bot.matrix_client.login(password=config["Matrix"]["Password"]) + if config.get("Matrix", "Password"): + if not config.get("Matrix", "UserID"): + raise Exception("Cannot log in: UserID not set in config") + + bot.matrix_client = AsyncClient(homeserver, user=config["Matrix"]["UserID"]) + login = await bot.matrix_client.login(password=config["Matrix"]["Password"]) + + if isinstance(login, LoginError): + raise Exception(f"Could not log in: {login.message}") config["Matrix"]["AccessToken"] = bot.matrix_client.access_token - config["Matrix"]["UserID"] = bot.matrix_client.user_id config["Matrix"]["DeviceID"] = bot.matrix_client.device_id config["Matrix"]["Password"] = "" else: + bot.matrix_client = AsyncClient(homeserver) + bot.matrix_client.access_token = config["Matrix"]["AccessToken"] bot.matrix_client.user_id = config["Matrix"].get("UserID") bot.matrix_client.device_id = config["Matrix"].get("DeviceID")