Skip to content

Commit

Permalink
Some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooling0602 committed Nov 8, 2024
1 parent 9ce293b commit a4cc1d9
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 37 deletions.
1 change: 0 additions & 1 deletion lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ matrix_sync:
error: Please check your account, password and network conditions, you can issue in GitHub for any help.
manual_sync:
start_sync: Room message receiver (as sub thread 'MatrixReceiver') started!
start_tip: Room message receiver reloaded with possible history messages reprinting.
stop_sync: Room message receiver stopped! Before next time server startup, it needs to be started manually.
start_error: Room message receiver is already running, do not restart it in cases not special such as non-reloading or after stopped!
stop_error: Unknown errors happened when stop room message receiver!
Expand Down
1 change: 0 additions & 1 deletion lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ matrix_sync:
error: 请检查你的账号密码以及网络情况,你可以在GitHub提出issue以获取任何帮助。
manual_sync:
start_sync: 已开始接收房间消息!(启动子线程MatrixReceiver)
start_tip: 房间消息接收器开始重载,已发送的历史消息可能会重新输出!
stop_sync: 已停止接收房间消息,到下次服务器启动完成前都只能手动重启!
start_error: 已在接收房间消息,非重载等特殊情况或手动停止后,不要再次尝试启动!
stop_error: 关闭房间消息接收器时发生未知错误!
Expand Down
25 changes: 1 addition & 24 deletions matrix_sync/commands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import asyncio
import json
import matrix_sync.config

from mcdreforged.api.all import *
from matrix_sync.globals import *
from matrix_sync.token import get_tip_read
from matrix_sync.sync.receiver import getMsg

psi = ServerInterface.psi()
Expand All @@ -31,12 +28,6 @@ def plugin_command(server: PluginServerInterface):
lambda src: src.reply(stopSync(src))
)
)
.then(
Literal('closetip')
.runs(
lambda src: src.reply(closeTip())
)
)
)

# Help tips.
Expand All @@ -52,12 +43,7 @@ def help() -> RTextList:
def manualSync():
if not tLock.locked():
start_room_msg()
psi.say(psi.rtr("matrix_sync.manual_sync.start_tip"))
read = asyncio.run(get_tip_read())
if not read:
psi.rtr("matrix_sync.manual_sync.start_sync")
else:
return psi.rtr("matrix_sync.manual_sync.start_sync")
return psi.rtr("matrix_sync.manual_sync.start_sync")
else:
return psi.rtr("matrix_sync.manual_sync.start_error")

Expand All @@ -75,15 +61,6 @@ def stopSync(src):
return psi.rtr("matrix_sync.manual_sync.stop_error")
else:
return psi.rtr("matrix_sync.manual_sync.stop_denied")

def closeTip():
TOKEN_FILE = matrix_sync.config.TOKEN_FILE
with open(TOKEN_FILE, "r") as f:
existing_data = json.load(f)
existing_data["tip_read"] = True
with open(TOKEN_FILE, "w") as f:
json.dump(existing_data, f)
return psi.rtr("matrix_sync.on_tip_read")

# Sub thread to receive room messages from matrix without block main MCDR thread.
@new_thread('MatrixReceiver')
Expand Down
12 changes: 1 addition & 11 deletions matrix_sync/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@ async def getToken():
async with aiofiles.open(TOKEN_FILE, "r") as f:
contents = await f.read()
cache = json.loads(contents)
return cache["token"]

async def get_tip_read():
TOKEN_FILE = matrix_sync.config.TOKEN_FILE
async with aiofiles.open(TOKEN_FILE, "r") as f:
contents = await f.read()
cache = json.loads(contents)
try:
return cache["tip_read"]
except KeyError:
return False
return cache["token"]

0 comments on commit a4cc1d9

Please sign in to comment.