fix v1.2调整交互命令返回信息

This commit is contained in:
thsrite
2024-06-09 18:27:23 +08:00
parent 20debbadcf
commit 9627fed64e
3 changed files with 16 additions and 14 deletions

View File

@@ -41,4 +41,4 @@ MoviePilot三方插件市场https://github.com/thsrite/MoviePilot-Plugins/
- [HomePage v1.2](docs%2FHomePage.md)
- 目录监控(统一入库消息增强版) v1.0
- Sql执行器 v1.1
- 命令执行器 v1.1
- 命令执行器 v1.2

View File

@@ -489,7 +489,7 @@
"author": "thsrite",
"level": 1,
"history": {
"v1.1": "支持交互命令/cmd [command]执行需主程序1.9.4+",
"v1.1": "支持交互命令/sql [command]执行需主程序1.9.4+",
"v1.0": "自定义MoviePilot数据库Sql执行"
}
},
@@ -497,12 +497,13 @@
"name": "命令执行器",
"description": "自定义容器命令执行。",
"labels": "工具",
"version": "1.1",
"version": "1.2",
"icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/command.png",
"author": "thsrite",
"level": 1,
"history": {
"v1.1": "支持交互命令/sql [sql]执行需主程序1.9.4+",
"v1.2": "调整交互命令返回信息",
"v1.1": "支持交互命令/cmd [sql]执行需主程序1.9.4+",
"v1.0": "自定义容器命令执行"
}
}

View File

@@ -15,7 +15,7 @@ class CommandExecute(_PluginBase):
# 插件图标
plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/command.png"
# 插件版本
plugin_version = "1.1"
plugin_version = "1.2"
# 插件作者
plugin_author = "thsrite"
# 作者主页
@@ -41,8 +41,8 @@ class CommandExecute(_PluginBase):
try:
for command in self._command.split("\n"):
logger.info(f"开始执行命令 {command}")
last_output, last_error = self.execute_command(command)
logger.info(last_output if last_output else last_error)
ouptut = self.execute_command(command)
# logger.info('\n'.join(ouptut))
except Exception as e:
logger.error(f"命令执行失败 {str(e)}")
return
@@ -60,24 +60,23 @@ class CommandExecute(_PluginBase):
:param command: 命令
"""
result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
last_output = None
last_error = None
ouptut = []
while True:
error = result.stderr.readline().decode("utf-8")
if error == '' and result.poll() is not None:
break
if error:
logger.info(error.strip())
last_error = error.strip()
ouptut.append(error.strip())
while True:
output = result.stdout.readline().decode("utf-8")
if output == '' and result.poll() is not None:
break
if output:
logger.info(output.strip())
last_output = output.strip()
ouptut.append(output.strip())
return last_output, last_error
return ouptut
@eventmanager.register(EventType.PluginAction)
def execute(self, event: Event = None):
@@ -85,15 +84,17 @@ class CommandExecute(_PluginBase):
event_data = event.event_data
if not event_data or event_data.get("action") != "command_execute":
return
logger.info(f"收到命令执行事件 ...{event_data}")
args = event_data.get("args")
if not args:
return
logger.info(f"收到命令,开始执行命令 ...{args}")
last_output, last_error = self.execute_command(args)
ouptut = self.execute_command(args)
# logger.info('\n'.join(ouptut))
self.post_message(channel=event.event_data.get("channel"),
title="命令执行结果",
text=last_output if last_output else last_error,
text='\n'.join(ouptut),
userid=event.event_data.get("user"))
def get_state(self) -> bool: