fix: 修复Windows下删除插件报错拒绝访问的问题;

修复权限组异常的问题
This commit is contained in:
Soulter
2023-05-21 11:00:59 +08:00
parent a68338b651
commit c6cf1153c1
2 changed files with 21 additions and 2 deletions

View File

@@ -528,7 +528,12 @@ def oper_msg(message,
qq_msg = message.message[0].text
session_id = message.user_id
role = "member"
if ("user_id" in message.sender and str(message.sender.user_id) == admin_qq) or ("tiny_id" in message.sender and str(message.sender.tiny_id) == admin_qqchan):
if message.type == "GuildMessage":
sender_id = str(message.sender.tiny_id)
else:
sender_id = str(message.sender.user_id)
if sender_id == admin_qq or sender_id == admin_qqchan:
gu.log("检测到管理员身份", gu.LEVEL_INFO, tag="GOCQ")
role = "admin"

View File

@@ -11,6 +11,7 @@ import shutil
import importlib
from util import general_utils as gu
from model.platform.qq import QQ
import stat
PLATFORM_QQCHAN = 'qqchan'
PLATFORM_GOCQ = 'gocq'
@@ -151,7 +152,8 @@ class Command:
return False, f"你的身份组{role}没有权限删除插件", "plugin"
try:
# 删除文件夹
shutil.rmtree(os.path.join(ppath, l[2]))
# shutil.rmtree(os.path.join(ppath, l[2]))
self.remove_dir(os.path.join(ppath, l[2]))
if l[2] in cached_plugins:
del cached_plugins[l[2]]
return True, "插件卸载成功~", "plugin"
@@ -204,6 +206,18 @@ class Command:
if role != "admin":
return False, f"你的身份组{role}没有权限开发者模式", "plugin"
return True, "cached_plugins: \n" + str(cached_plugins), "plugin"
def remove_dir(self, file_path):
while 1:
if not os.path.exists(file_path):
break
try:
shutil.rmtree(file_path)
except PermissionError as e:
err_file_path = str(e).split("\'", 2)[1]
if os.path.exists(err_file_path):
os.chmod(err_file_path, stat.S_IWUSR)
'''