Skip to content

Commit 4278d2b

Browse files
committed
feat: add updatep command
1 parent 9c208ff commit 4278d2b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

plugins/godcmd/godcmd.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
"args": ["插件名"],
105105
"desc": "卸载指定插件",
106106
},
107+
"updatep": {
108+
"alias": ["updatep", "更新插件"],
109+
"args": ["插件名"],
110+
"desc": "更新指定插件",
111+
},
107112
"debug": {
108113
"alias": ["debug", "调试模式", "DEBUG"],
109114
"desc": "开启机器调试日志",
@@ -336,6 +341,11 @@ def on_handle_context(self, e_context: EventContext):
336341
ok, result = False, "请提供插件名"
337342
else:
338343
ok, result = PluginManager().uninstall_plugin(args[0])
344+
elif cmd == "updatep":
345+
if len(args) != 1:
346+
ok, result = False, "请提供插件名"
347+
else:
348+
ok, result = PluginManager().update_plugin(args[0])
339349
logger.debug("[Godcmd] admin command: %s by %s" % (cmd, user))
340350
else:
341351
ok, result = False, "需要管理员权限才能执行该指令"

plugins/plugin_manager.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,30 @@ def install_plugin(self, repo:str):
243243
logger.error("Failed to install plugin, {}".format(e))
244244
return False, "安装插件失败,"+str(e)
245245

246+
def update_plugin(self, name:str):
247+
try:
248+
import common.package_manager as pkgmgr
249+
pkgmgr.check_dulwich()
250+
except Exception as e:
251+
logger.error("Failed to install plugin, {}".format(e))
252+
return False, "无法导入dulwich,更新插件失败"
253+
from dulwich import porcelain
254+
name = name.upper()
255+
if name not in self.plugins:
256+
return False, "插件不存在"
257+
if name in ["HELLO","GODCMD","ROLE","TOOL","BDUNIT","BANWORDS","FINISH","DUNGEON"]:
258+
return False, "预置插件无法更新,请更新主程序仓库"
259+
dirname = self.plugins[name].path
260+
try:
261+
porcelain.pull(dirname, "origin")
262+
if os.path.exists(os.path.join(dirname,"requirements.txt")):
263+
logger.info("detect requirements.txt,installing...")
264+
pkgmgr.install_requirements(os.path.join(dirname,"requirements.txt"))
265+
return True, "更新插件成功,请重新运行程序"
266+
except Exception as e:
267+
logger.error("Failed to update plugin, {}".format(e))
268+
return False, "更新插件失败,"+str(e)
269+
246270
def uninstall_plugin(self, name:str):
247271
name = name.upper()
248272
if name not in self.plugins:

0 commit comments

Comments
 (0)