Skip to content

Commit

Permalink
Update to v2.5.0 stable, ready to merge and release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooling0602 committed Dec 23, 2024
1 parent 560c2ca commit fa6d77c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 11 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# MatrixSync-MCDR
一个MCDR(全称[MCDReforged](https://mcdreforged.com/))插件,用于同步Matrix群组和《我的世界》服务器的线上游戏之间的消息。

> 注意:不再支持`mcdreforged<2.14`
关于[Matrix](https://matrix.org/): 一个开放的去中心化通讯协议,用于聊天软件。

开发过程中用到的pypi项目:[matrix-nio](https://pypi.org/project/matrix-nio/)
Expand Down Expand Up @@ -41,17 +43,18 @@

| 配置项 | 配置内容 |
| - | - |
| `sync.all_rooms` | 是否接收来自机器人加入的所有房间的消息,默认全部接收 |
| `sync.old_messages` | 是否在启动接收器时加载历史消息,默认不加载 |
| `listen.all_rooms` | 是否接收来自机器人加入的所有房间的消息,默认全部接收 |
| `listen.old_messages` | 是否在启动接收器时加载历史消息,默认不加载 |
| `message_format.single_room` | 只接收当前配置的房间的消息时,消息的显示格式 |
| `message_format.all_room` | 接收机器人加入的所有房间的消息时,消息的显示格式 |
| `log_style.mcdr` | 是否使用MCDR的日志样式,默认为否(使用插件自己的日志样式) |
| `log_style.debug` | 是否显示调试日志,默认为否 |
| `ver` | 配置文件版本,请不要进行修改 |

## 接口(API)
请前往[docs](https://github.com/Mooling0602/MatrixSync-MCDR/blob/dev/docs.md)查看。

v2.5.0进行了一次彻底的代码重构,并且此版本开始进行长期支持,此前的所有API全部失效。
v2.5.0进行了一次彻底的代码重构,并且此版本开始进行长期支持,此前的所有API全部失效,并且此前的配置文件不再受支持

## 热重载(reload)及消息互通控制
始终建议在运行环境稳定时,尽量不使用热重载,减少出错概率
Expand Down
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ ver=4
[main]
ver=2.5.0
[release]
test=1
test=0
[ci]
plugin=1
12 changes: 12 additions & 0 deletions lang/en_us.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
matrix_sync:
check_config: Please recheck your config, if you confirm it's correct, issue this in GitHub.
help:
message: "See the help page for §7!!msync§r commands."
title: "----- MatrixSync Command Help -----"
root: "§7!!msync§r Show this help page."
start: "§7!!msync start§r Start message sync(will automatically start when loaded plugin and server startup)."
stop: "§7!!msync stop§r Stop message sync."
send: "§7!!msync send <message>§r Send a specified message to matrix, can be quoted by \"\"."
status: "§7!!msync status§r Check the status of message sync."
reload:
plugin: "§7!!msync reload§r Reload this plugin and refresh its config."
subpack: "§7!!msync reload <pack_name>§r Reload a subpack and refresh its config."
login:
failed: Failed to login your bot
success: Login by password successfully!
save_token: Saving token for the bot account...
on_receiver_cancelled: Receiver task was cancelled.
on_send_command: Message is sending to matrix...
on_sync_running: Already running message sync!
on_sync_start: Starting message sync...
on_unload: Unloading MatrixSync...
Expand Down
12 changes: 12 additions & 0 deletions lang/zh_cn.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
matrix_sync:
check_config: 请重新检查你的配置,如果你确信其准确无误,请前往GitHub Issues页面反馈相关问题!
help:
message: "查看指令 §7!!msync§r 的帮助页面"
title: "----- MatrixSync 指令帮助 -----"
root: "§7!!msync§r 显示此帮助页面"
start: "§7!!msync start§r 开始消息同步(在插件加载完成后和服务器启动完成后会自动开始)"
stop: "§7!!msync stop§r 停止消息同步"
send: "§7!!msync send <message>§r 向Matrix发送一条指定消息,可以用\"\"括起来"
status: "§7!!msync status§r 查看消息同步的状态"
reload:
plugin: "§7!!msync reload§r 重载此插件并刷新其配置"
subpack: "§7!!msync reload <pack_name>§r 重载一个子包并刷新其配置"
login:
failed: 无法登录你的机器人
success: 成功使用密码完成登录!
save_token: 正在为机器人账号保存Token...
on_receiver_cancelled: 接收器任务已经取消。
on_send_command: 消息正在发送到Matrix...
on_sync_running: 消息同步已在运行!
on_sync_start: 开始消息同步...
on_unload: 正在卸载 MatrixSync...
Expand Down
39 changes: 33 additions & 6 deletions matrix_sync/commands.py → matrix_sync/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import matrix_sync.plg_globals as plg_globals

from mcdreforged.api.all import *
from .client.reporter import send_to_matrix
from .client.receiver import get_messages, stop_sync
from .client import *
from .utils import tr
from .utils.logger import *
from ..client.reporter import send_to_matrix
from ..client.receiver import get_messages, stop_sync
from ..client import *
from ..utils import tr
from ..utils.logger import *
from .help import *


builder = SimpleCommandBuilder()
Expand Down Expand Up @@ -39,6 +40,9 @@ async def add_report_task(message: str):
await report_task

def command_register(server: PluginServerInterface):
server.register_help_message("!!msync", help_message)
builder.arg("message", QuotableText)
builder.arg("pack_name", Text)
builder.register(server)

@builder.command("!!msync start")
Expand All @@ -55,4 +59,27 @@ def show_status():
if plg_globals.sync:
log_info(tr("sync_status.running"))
else:
log_info(tr("sync_status.not_running"))
log_info(tr("sync_status.not_running"))

@builder.command("!!msync send <message>")
def on_command_send(src: CommandSource, ctx: CommandContext):
matrix_reporter(ctx["message"])
src.reply(tr("on_send_command"))

@builder.command("!!msync reload")
def on_command_reload():
psi.reload_plugin(plgSelf.id)

@builder.command("!!msync reload <pack_name>")
def on_command_reload_subpack(src: CommandSource, ctx: CommandContext):
plugin_list = psi.get_plugin_list()
subpack_id = "msync_" + ctx["pack_name"]
if subpack_id in plugin_list:
psi.reload_plugin(subpack_id)
else:
src.reply("Reload subpack error: Invaild name!")

@builder.command("!!msync")
@builder.command("!!msync help")
def show_help(src: CommandSource):
src.reply(help_page)
15 changes: 15 additions & 0 deletions matrix_sync/commands/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from mcdreforged.api.rtext import RTextList
from ..utils import tr

help_page = RTextList(
tr("help.title", False) + "\n",
tr("help.root", False) + "\n",
tr("help.start", False) + "\n",
tr("help.stop", False) + "\n",
tr("help.send", False) + "\n",
tr("help.status", False) + "\n",
tr("help.reload.plugin", False) + "\n",
tr("help.reload.subpack", False) + "\n"
)

help_message = tr("help.message", False)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
matrix-nio
aiofiles
asyncio
mcdreforged
mcdreforged>=2.14

0 comments on commit fa6d77c

Please sign in to comment.