diff --git a/README.md b/README.md index ebb0fb0..179b6bd 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,14 @@ 开发过程中用到的pypi项目:[matrix-nio](https://pypi.org/project/matrix-nio/)。 +版本进度:`v2.5.0` + ## 用法 从release下载最新版本,在MCDReforged的启动环境中安装好需要的Python依赖,然后扔到plugins文件夹里面即可。 在使用此插件之前,你必须知道什么是[Matrix](https://matrix.org/),然后准备一个账号作为matrix机器人用于消息同步,并认真阅读下面的内容以进行插件配置。 -配置完毕并启用插件后,若有测试消息成功发送到matrix群组,则表示消息同步开始工作。 +配置完毕并加载插件后,若有测试消息成功发送到matrix群组,则表示消息同步开始工作。 若消息同步的过程中有任意方向的消息转发出现问题,也请按配置文件部分的内容检查配置是否正确。 @@ -33,44 +35,39 @@ > > v2 LTS 开发中,如果你不需要多账号、多房间管理,可以持续使用v2版本。 > -> v2 LTS 推送正在进行,配置文件格式已大幅度修改,可能和之前完全不兼容,建议备份后删除旧配置。 +> v2 LTS 推送正在进行,配置文件格式已大幅度修改,可能和之前完全不兼容,建议备份后删除旧配置并按照新的配置格式重新设置插件。 #### settings.json | 配置项 | 配置内容 | | - | - | -| plugin-enabled | 插件是否启用,请确保配置文件和所需设置修改无误后再开启 | -| allow_all_rooms_msg | 是否允许来自所有房间的消息,若开启,则来自机器人账号所加入的房间的消息都会被转发到游戏中,并注明房间的显示名称,否则只转发已设置的房间的消息 | -| sync_old_msg | 是否同步旧的消息,默认关闭,开启以在插件启动同步时加载历史消息 | +| `sync.all_rooms` | 是否接收来自机器人加入的所有房间的消息,默认全部接收 | +| `sync.old_messages` | 是否在启动接收器时加载历史消息,默认不加载 | +| `message_format.single_room` | 只接收当前配置的房间的消息时,消息的显示格式 | +| `message_format.all_room` | 接收机器人加入的所有房间的消息时,消息的显示格式 | +| `log_style.mcdr` | 是否使用MCDR的日志样式,默认为否(使用插件自己的日志样式) | +| `log_style.debug` | 是否显示调试日志,默认为否 | ## 接口(API) -2.3.0以前的旧接口仍然有效,请到[docs](https://github.com/Mooling0602/MatrixSync-MCDR/blob/dev/docs.md)查看。 - -> 2.3.x修改的接口将不再受到任何支持,原因为相关函数名和分发的插件事件中提供的参数发生冲突。 - -2.4.0版本重构后的新接口的简单用法: -```python -import matrix_sync.client -from matrix_sync.reporter import send_matrix +请前往[docs](https://github.com/Mooling0602/MatrixSync-MCDR/blob/dev/docs.md)查看。 -def main(): - message = "你要发送的消息" - send_matrix(message) - -# 消息将在独立线程MatrixReporter中被发送到Matrix,不再可能会阻塞MCDR主线程 -# 如果消息没有发送到Matrix,启用MCDR配置中的`debug.plugin`,会显示详情 -``` +v2.5.0进行了一次彻底的代码重构,并且此版本开始进行长期支持,此前的所有API全部失效。 ## 热重载(reload)及消息互通控制 -始终建议在运行环境稳定时,尽量不使用热重载。 +始终建议在运行环境稳定时,尽量不使用热重载,减少出错概率 + +插件加载时会自动启动消息接收器(转发Matrix消息到MCDR控制台,被动),游戏内的玩家聊天也会自动转发到Matrix(主动),目前前者可以手动进行开关。 -现在Matrix消息的收发已经实现同步,使用`!!msync`查看帮助。 +插件卸载时或停止消息接收器时,会自动关闭消息接收器,并关闭运行中的异步客户端。 -服务器启动完成后,插件会自动启动Minecraft游戏服务器和Matrix之间的消息互通,暂时不能对消息的收发方向进行配置。(将于2.5.x继续改善) +若出现插件卸载后仍有残留线程运行的情况,请反馈到Issues页面。遇到这种情况,你只能完全退出甚至强制退出MCDR。 +> 目前这个问题基本不会发生,但不排除有没考虑到的情况。一般情况下,你可以随意热重载以刷新插件配置。 ## 注意 ### 关于首次使用 -首次加载插件的时候,插件将自动初始化配置并卸载自己。你需要正确修改默认的配置文件,并在settings.json中启用plugin_enabled配置项以启用插件,然后重载插件以正常使用。 +首次加载插件的时候,插件将自动初始化配置并卸载自己。你需要正确修改默认的配置文件,然后重载插件以正常使用。 + +如果`/path/to/mcdr/config/matrix_sync/config.json`中的机器人账号信息有误,会出现报错,在反馈报错到Issues前,请确认你的信息准确无误,否则无助于解决问题。 - 不打算支持加密信息(EE2E),有需要可以二次开发修改插件,欢迎PR。 diff --git a/README_en_us.md b/README_en_us.md index 1c52cf0..87a142d 100644 --- a/README_en_us.md +++ b/README_en_us.md @@ -3,53 +3,10 @@ > To avoid incorrect links after merging into the main branch, all URLs should use the main branch's address. If you are accessing other branches, please make sure to manually adjust the link's target location. # MatrixSync-MCDR -A MCDR (full name [MCDReforged](https://mcdreforged.com/)) plugin, use to sync messages between Matrix groups and online gaming in Minecraft servers. +A MCDR (full name [MCDReforged](https://mcdreforged.com/)) plugin, can sync messages between Matrix groups and online gaming in Minecraft servers. About [Matrix](https://matrix.org/): an open decentralized network communication protocol for chat software. -The following project is used in the development process: [matrix-nio](https://pypi.org/project/matrix-nio/)。 +The following project is used in the development process: [matrix-nio](https://pypi.org/project/matrix-nio/). -Thanks for ChatGPT and Google Translate's help to translate the content from Chinese, if anything wrong, please issue to feedback or PR to `/lang`. - -## Usage -Download the latest version from the release, install the necessary Python dependencies in the MCDReforged startup environment, and then throw it into the plugins folder. - -Before using this plugin, you must know what [Matrix](https://matrix.org/) is, then prepare an account as a matrix bot for message synchronization, and carefully read the following content to configure the plugin. - -After configuration and enabling the plugin, if the test message is successfully sent to the matrix group, it means that message synchronization has started to work. - -If there is any issue with message forwarding in any direction during the message synchronization process, please check the configuration according to the following content to ensure it is correct. - -### Configuration File -#### config.json - -| Configuration Item | Content | -| - | - | -| **homeserver** | The homeserver address used to log in to the bot account | -| **user_id** | The bot account ID, formatted as @username:example.com | -| **password** | The password of the bot account, generally only used for the initial login | -| **room_id** | The ID of the room to sync game messages | -| **device_id** | The device name used for login, generally no need to modify, can be customized | - -Multi-config is not supported, will add API support for developers from v3. -#### settings.json - -| Configuration Item | Content | -| - | - | -| plugin-enabled | Whether the plugin is enabled, please ensure the configuration file and necessary settings are modified correctly before enabling | -| allow_all_rooms_msg | Whether to allow messages from all rooms, if enabled, messages from rooms joined by the bot account will be forwarded to the game, with the room display name specified, otherwise only messages from the configured room will be forwarded | -| sync_old_msg | Whether to sync old messages, enabled on default, disable to see old messages when plugin is just loaded | - -## Interface (API) -See the docs in [中文文档](https://github.com/Mooling0602/MatrixSync-MCDR/blob/docs.md) at present. - -## Hot Reload (reload) & message sync control -It is advisable not to use hot reload in a stable environment. - -Execute `!!msync` to see the usage. - -## Note -### First-time Use -When loading the plugin for the first time, the plugin will automatically initialize the configuration and then unload itself. You need to correctly modify the default configuration file and enable the plugin_enabled option in settings.json to activate the plugin. Then, restart the server or reload the plugin for proper use. If you choose the latter, after reloading the plugin, if the server has finished starting, you can use !!msync start to start the room message receiver, enabling Matrix message forwarding to the game. Furthermore, as long as the plugin is successfully loaded without issues, in-game messages will always be automatically forwarded to the Matrix room. This will be synchronized with the room message receiver in versions above 2.4.0. - -- The plugin does not support encrypted messages (EE2E). If needed, you can modify the plugin for secondary development, and PRs are welcome. +v2.5.0+ need new translations, but not prepared yet, you can use translation tools to read "中文" README at present. I would be grateful if you could help translation by commit PRs. diff --git a/config.ini b/config.ini index bb9e68a..23f6d97 100644 --- a/config.ini +++ b/config.ini @@ -1,7 +1,7 @@ # Do not edit this file! # 不要修改这个文件! [framework] -ver=1 +ver=2 [main] ver=2.5.0 [release] diff --git a/matrix_sync/config/default.py b/matrix_sync/config/default.py index 067292b..f122f50 100644 --- a/matrix_sync/config/default.py +++ b/matrix_sync/config/default.py @@ -19,6 +19,6 @@ }, "log_style": { "mcdr": False, - "debug": True + "debug": False } } \ No newline at end of file diff --git a/matrix_sync/entry.py b/matrix_sync/entry.py index 3c48de4..87a7644 100644 --- a/matrix_sync/entry.py +++ b/matrix_sync/entry.py @@ -9,7 +9,7 @@ from mcdreforged.api.all import * -# Framwork ver: 2.5.0-1 +# Framwork ver: 2.5.0-2 def on_load(server: PluginServerInterface, prev_module): asyncio.run(load_config(server)) command_register(server) @@ -18,10 +18,10 @@ def on_load(server: PluginServerInterface, prev_module): def on_server_startup(server: PluginServerInterface): start_sync(False) -async def on_user_info(server: PluginServerInterface, info: Info): +def on_user_info(server: PluginServerInterface, info: Info): if info.player is not None and not info.content.startswith("!!"): - playerMsg = f"[MC] <{info.player}> {info.content}" - await send_to_matrix(playerMsg) + player_message = f"[MC] <{info.player}> {info.content}" + matrix_reporter(player_message) # Exit sync process when server stop. async def on_server_stop(server: PluginServerInterface, server_return_code: int):