🐛 修复无法同时禁用所有插件的问题

This commit is contained in:
CMHopeSunshine 2022-09-04 11:52:50 +08:00
parent fd0d4f3985
commit 39f65a3258
2 changed files with 19 additions and 15 deletions

View File

@ -28,7 +28,9 @@ __plugin_meta__ = PluginMetadata(
async def _(event: MessageEvent):
await update_cmd.send(f'{NICKNAME}开始执行git pull更新', at_sender=True)
p = subprocess.run(['git', 'pull'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
await update_cmd.finish('更新结果:' + (p.stdout if p.returncode == 0 else p.stderr).decode('utf-8').replace('+', '').replace('-', '').strip(' '))
results = (p.stdout if p.returncode == 0 else p.stderr).decode('utf-8').split('\n')
result_msg = ''.join(result.split('|')[0].strip(' ') + '\n' for result in results)
await update_cmd.finish(f'更新结果:{result_msg}')
@reboot_cmd.handle()

View File

@ -36,8 +36,9 @@ async def _(event: GroupMessageEvent, state: T_State, match: dict = RegexDict(),
state['plugin'] = []
state['plugin_no_exist'] = []
for plugin in match['plugin'].strip().split(' '):
if plugin not in plugin_manager.data.keys() and plugin not in ['all', '全部']:
if module_name := list(filter(lambda x: plugin_manager.data[x].name == plugin, plugin_manager.data.keys())):
if plugin in plugin_manager.data.keys() or plugin in ['all', '全部']:
state['plugin'].append(plugin)
elif module_name := list(filter(lambda x: plugin_manager.data[x].name == plugin, plugin_manager.data.keys())):
state['plugin'].append(module_name[0])
else:
state['plugin_no_exist'].append(plugin)
@ -57,8 +58,9 @@ async def _(event: PrivateMessageEvent, state: T_State, match: dict = RegexDict(
state['plugin'] = []
state['plugin_no_exist'] = []
for plugin in match['plugin'].strip().split(' '):
if plugin not in plugin_manager.data.keys() and plugin not in ['all', '全部']:
if module_name := list(filter(lambda x: plugin_manager.data[x].name == plugin, plugin_manager.data.keys())):
if plugin in plugin_manager.data.keys() or plugin in ['all', '全部']:
state['plugin'].append(plugin)
elif module_name := list(filter(lambda x: plugin_manager.data[x].name == plugin, plugin_manager.data.keys())):
state['plugin'].append(module_name[0])
else:
state['plugin_no_exist'].append(plugin)
@ -74,7 +76,7 @@ async def _(state: T_State):
del cache_help[state['session_id']]
if not state['plugin'] and state['plugin_no_exist']:
await manage_cmd.finish(f'没有叫{" ".join(state["plugin_no_exist"])}的插件')
extra_msg = f'但没有叫{" ".join(state["plugin_no_exist"])}的插件' if state['plugin_no_exist'] else ''
extra_msg = f'但没有叫{" ".join(state["plugin_no_exist"])}的插件' if state['plugin_no_exist'] else ''
if state['group'] and not state['user']:
for group_id in state['group']:
if 'all' in state['plugin']:
@ -82,7 +84,7 @@ async def _(state: T_State):
else:
await asyncio.gather(*[PluginPermission.filter(name=plugin, session_id=group_id, session_type='group').update(status=state['bool']) for plugin in state['plugin']])
logger.info('插件管理器', f'{"<g>启用</g>" if state["bool"] else "<r>禁用</r>"}群<m>{" ".join(map(str, state["group"]))}</m>的插件<m>{" ".join(state["plugin"])}</m>使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}{" ".join(map(str, state["group"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}{" ".join(map(str, state["group"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
elif state['user'] and not state['group']:
for user_id in state['user']:
if 'all' in state['plugin']:
@ -91,7 +93,7 @@ async def _(state: T_State):
await asyncio.gather(*[PluginPermission.filter(name=plugin, session_id=user_id, session_type='user').update(status=state['bool']) for plugin in state['plugin']])
logger.info('插件管理器',
f'{"<g>启用</g>" if state["bool"] else "<r>禁用</r>"}用户<m>{" ".join(map(str, state["user"]))}</m>的插件<m>{" ".join(state["plugin"])}</m>使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}用户{" ".join(map(str, state["user"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}用户{" ".join(map(str, state["user"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
else:
for group_id in state['group']:
if 'all' in state['plugin']:
@ -104,7 +106,7 @@ async def _(state: T_State):
await plugin.save()
logger.info('插件管理器',
f'{"<g>启用</g>" if state["bool"] else "<r>禁用</r>"}群<m>{" ".join(map(str, state["group"]))}</m>中用户<m>{" ".join(map(str, state["user"]))}</m>的插件<m>{" ".join(state["plugin"])}</m>使用权限')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}{" ".join(map(str, state["group"]))}中用户{" ".join(map(str, state["user"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
await manage_cmd.finish(f'{"启用" if state["bool"] else "禁用"}{" ".join(map(str, state["group"]))}中用户{" ".join(map(str, state["user"]))}的插件{" ".join(state["plugin"])}使用权限{extra_msg}')
@help_cmd.handle()