fix add update交互命令
This commit is contained in:
parent
26f63c4ea7
commit
8a46ebc4a0
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ class SystemChain(ChainBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_restart_file = "__system_restart__"
|
_restart_file = "__system_restart__"
|
||||||
|
_update_file = "__system_update__"
|
||||||
|
|
||||||
def remote_clear_cache(self, channel: MessageChannel, userid: Union[int, str]):
|
def remote_clear_cache(self, channel: MessageChannel, userid: Union[int, str]):
|
||||||
"""
|
"""
|
||||||
@ -39,6 +41,25 @@ class SystemChain(ChainBase):
|
|||||||
}, self._restart_file)
|
}, self._restart_file)
|
||||||
SystemUtils.restart()
|
SystemUtils.restart()
|
||||||
|
|
||||||
|
def update(self, channel: MessageChannel, userid: Union[int, str]):
|
||||||
|
"""
|
||||||
|
重启系统
|
||||||
|
"""
|
||||||
|
if channel and userid:
|
||||||
|
self.post_message(Notification(channel=channel,
|
||||||
|
title="系统正在更新,请耐心等候!", userid=userid))
|
||||||
|
# 保存重启信息
|
||||||
|
self.save_cache({
|
||||||
|
"channel": channel.value,
|
||||||
|
"userid": userid
|
||||||
|
}, self._update_file)
|
||||||
|
|
||||||
|
# 重启系统
|
||||||
|
os.system("bash /usr/local/bin/mp_update")
|
||||||
|
self.post_message(Notification(channel=channel,
|
||||||
|
title="暂无新版本!", userid=userid))
|
||||||
|
self.remove_cache(self._update_file)
|
||||||
|
|
||||||
def version(self, channel: MessageChannel, userid: Union[int, str]):
|
def version(self, channel: MessageChannel, userid: Union[int, str]):
|
||||||
"""
|
"""
|
||||||
查看当前版本、远程版本
|
查看当前版本、远程版本
|
||||||
@ -58,13 +79,35 @@ class SystemChain(ChainBase):
|
|||||||
如通过交互命令重启,
|
如通过交互命令重启,
|
||||||
重启完发送msg
|
重启完发送msg
|
||||||
"""
|
"""
|
||||||
|
cache_file, action, channel, userid = None, None, None, None
|
||||||
|
# 重启消息
|
||||||
restart_channel = self.load_cache(self._restart_file)
|
restart_channel = self.load_cache(self._restart_file)
|
||||||
logger.info(f"获取到重启msg=> {restart_channel}")
|
|
||||||
if restart_channel:
|
if restart_channel:
|
||||||
|
cache_file = self._restart_file
|
||||||
|
action = "重启"
|
||||||
# 发送重启完成msg
|
# 发送重启完成msg
|
||||||
if not isinstance(restart_channel, dict):
|
if not isinstance(restart_channel, dict):
|
||||||
restart_channel = json.loads(restart_channel)
|
restart_channel = json.loads(restart_channel)
|
||||||
|
channel = next(
|
||||||
|
(channel for channel in MessageChannel.__members__.values() if
|
||||||
|
channel.value == restart_channel.get('channel')), None)
|
||||||
|
userid = restart_channel.get('userid')
|
||||||
|
|
||||||
|
# 更新消息
|
||||||
|
update_channel = self.load_cache(self._update_file)
|
||||||
|
if update_channel:
|
||||||
|
cache_file = self._update_file
|
||||||
|
action = "更新"
|
||||||
|
# 发送重启完成msg
|
||||||
|
if not isinstance(update_channel, dict):
|
||||||
|
update_channel = json.loads(update_channel)
|
||||||
|
channel = next(
|
||||||
|
(channel for channel in MessageChannel.__members__.values() if
|
||||||
|
channel.value == update_channel.get('channel')), None)
|
||||||
|
userid = update_channel.get('userid')
|
||||||
|
|
||||||
|
# 发送消息
|
||||||
|
if channel and userid:
|
||||||
# 版本号
|
# 版本号
|
||||||
release_version = self.__get_release_version()
|
release_version = self.__get_release_version()
|
||||||
local_version = self.__get_local_version()
|
local_version = self.__get_local_version()
|
||||||
@ -72,15 +115,10 @@ class SystemChain(ChainBase):
|
|||||||
title = f"当前版本:{local_version}"
|
title = f"当前版本:{local_version}"
|
||||||
else:
|
else:
|
||||||
title = f"当前版本:{local_version},远程版本:{release_version}"
|
title = f"当前版本:{local_version},远程版本:{release_version}"
|
||||||
|
|
||||||
channel = next(
|
|
||||||
(channel for channel in MessageChannel.__members__.values() if
|
|
||||||
channel.value == restart_channel.get('channel')), None)
|
|
||||||
|
|
||||||
self.post_message(Notification(channel=channel,
|
self.post_message(Notification(channel=channel,
|
||||||
title=f"系统已重启完成!{title}",
|
title=f"系统已{action}完成!{title}",
|
||||||
userid=restart_channel.get('userid')))
|
userid=userid))
|
||||||
self.remove_cache(self._restart_file)
|
self.remove_cache(cache_file)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_release_version():
|
def __get_release_version():
|
||||||
|
@ -148,6 +148,12 @@ class Command(metaclass=Singleton):
|
|||||||
"description": "当前版本",
|
"description": "当前版本",
|
||||||
"category": "管理",
|
"category": "管理",
|
||||||
"data": {}
|
"data": {}
|
||||||
|
},
|
||||||
|
"/update": {
|
||||||
|
"func": SystemChain(self._db).update,
|
||||||
|
"description": "更新系统",
|
||||||
|
"category": "管理",
|
||||||
|
"data": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# 汇总插件命令
|
# 汇总插件命令
|
||||||
|
Loading…
x
Reference in New Issue
Block a user