diff --git a/matrix_py_bridge/client.py b/matrix_py_bridge/client.py index 9b68b04..c53c9e9 100644 --- a/matrix_py_bridge/client.py +++ b/matrix_py_bridge/client.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Callable, Union, Optional from logging import Logger from nio import ( AsyncClient, @@ -16,9 +16,9 @@ class MatrixClient: user_id: str, token: str, device_id: Optional[str] = "mcdr", - logger: Optional[Logger, callable] = print, + logger: Union[Logger, Callable, None] = print, ): - self.connected: bool = False + self.connected: bool = True self.client = AsyncClient(homeserver=homeserver) self.client.user_id = user_id self.client.access_token = token @@ -47,25 +47,22 @@ class MatrixClient: if hasattr(self.logger, "debug"): self.logger.debug(f"MatrixClient response: {response}") - def on_sync_error(response: SyncError): + async def on_sync_error(response: SyncError): self.network_status = False - message = ( - "Sync error with matrix homeserver: " - f"{response.status_code}" - ) - RED = "\033[31m" - RESET = "\033[0m" + _message = f"Sync error with matrix homeserver: {response.status_code}" + _ansi_color_red = "\033[31m" + _ansi_reset_color = "\033[0m" if not self.logger: - print(RED + message + RESET) + print(_ansi_color_red + _message + _ansi_reset_color) if hasattr(self.logger, "error"): - self.logger.error(message) + self.logger.error(_message) else: - self.logger(RED + message + RESET) + self.logger(_ansi_color_red + _message + _ansi_reset_color) client.add_response_callback(on_sync_response, SyncResponse) client.add_response_callback(on_sync_error, SyncError) async def message_callback( room: MatrixRoom, event: RoomMessageText - ) -> None: - raise NotImplementedError() + ) -> None: # 处理接受到的消息回调 + raise NotImplementedError() # 咕咕咕…… diff --git a/matrix_py_bridge/config/file_handler.py b/matrix_py_bridge/config/file_handler.py index 27407c3..e995683 100644 --- a/matrix_py_bridge/config/file_handler.py +++ b/matrix_py_bridge/config/file_handler.py @@ -23,7 +23,7 @@ if __name__ == "__main__": import os if not os.path.exists("config.json"): - exit + exit() config = load_file_json("config.json") print("Config data type: " + str(type(config))) print("Config data content: " + str(config)) diff --git a/pyproject.toml b/pyproject.toml index 07fc05d..a0eb360 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ description = "A python plugin to sync messages between Minecraft server and mat readme = "README.md" requires-python = ">=3.11" dependencies = [ + "chardet>=5.2.0", "matrix-nio>=0.25.2", "mcdreforged>=2.15.2", ] diff --git a/requirements.txt b/requirements.txt index b211fb9..7543294 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ +chardet matrix-nio mcdreforged