mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
🐛 修复插件管理器报错
This commit is contained in:
parent
ffb902e3e9
commit
f6a2bdcff2
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
@ -46,15 +47,15 @@ class PluginManager:
|
|||||||
user_list = await get_bot().get_friend_list()
|
user_list = await get_bot().get_friend_list()
|
||||||
for plugin in plugin_list:
|
for plugin in plugin_list:
|
||||||
if plugin.name not in HIDDEN_PLUGINS:
|
if plugin.name not in HIDDEN_PLUGINS:
|
||||||
models = ([PluginPermission(name=plugin.name, session_id=group['group_id'], session_type='group') for
|
# 将所有PluginPermission相同的,只保留一个
|
||||||
group in group_list] if group_list else []) + \
|
if group_list:
|
||||||
([PluginPermission(name=plugin.name, session_id=user['user_id'], session_type='user') for
|
await asyncio.gather(
|
||||||
user in user_list] if user_list else [])
|
*[PluginPermission.update_or_create(name=plugin.name, session_id=group['group_id'],
|
||||||
if models:
|
session_type='group') for group in group_list])
|
||||||
await PluginPermission.bulk_create(
|
if user_list:
|
||||||
models,
|
await asyncio.gather(
|
||||||
ignore_conflicts=True
|
*[PluginPermission.update_or_create(name=plugin.name, session_id=user['user_id'],
|
||||||
)
|
session_type='user') for user in user_list])
|
||||||
if plugin.name not in HIDDEN_PLUGINS:
|
if plugin.name not in HIDDEN_PLUGINS:
|
||||||
if plugin.name not in cls.plugins:
|
if plugin.name not in cls.plugins:
|
||||||
if metadata := plugin.metadata:
|
if metadata := plugin.metadata:
|
||||||
@ -142,8 +143,8 @@ async def _(event: MessageEvent, matcher: Matcher):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# 权限检查
|
# 权限检查
|
||||||
perm = await PluginPermission.get_or_none(name=matcher.plugin_name, session_id=session_id,
|
perm = await PluginPermission.filter(name=matcher.plugin_name, session_id=session_id,
|
||||||
session_type=session_type)
|
session_type=session_type).first()
|
||||||
if not perm:
|
if not perm:
|
||||||
await PluginPermission.create(name=matcher.plugin_name, session_id=session_id, session_type=session_type)
|
await PluginPermission.create(name=matcher.plugin_name, session_id=session_id, session_type=session_type)
|
||||||
return
|
return
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
from nonebot import on_regex, on_command, on_notice
|
from nonebot import on_regex, on_command, on_notice
|
||||||
from nonebot import plugin as nb_plugin
|
from nonebot import plugin as nb_plugin
|
||||||
from nonebot.adapters.onebot.v11 import Message, GroupMessageEvent, PrivateMessageEvent, MessageEvent
|
from nonebot.adapters.onebot.v11 import Message, GroupMessageEvent, PrivateMessageEvent, MessageEvent
|
||||||
@ -26,8 +27,11 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def notice_rule(event: NoticeEvent):
|
def notice_rule(event: NoticeEvent) -> bool:
|
||||||
return isinstance(event, (FriendAddNoticeEvent, GroupIncreaseNoticeEvent))
|
if isinstance(event, FriendAddNoticeEvent):
|
||||||
|
return True
|
||||||
|
elif isinstance(event, GroupIncreaseNoticeEvent):
|
||||||
|
return event.user_id == event.self_id
|
||||||
|
|
||||||
|
|
||||||
def fullmatch(msg: Message = CommandArg()) -> bool:
|
def fullmatch(msg: Message = CommandArg()) -> bool:
|
||||||
@ -183,18 +187,9 @@ async def _(event: MessageEvent, msg: Message = CommandArg()):
|
|||||||
async def _(event: NoticeEvent):
|
async def _(event: NoticeEvent):
|
||||||
plugin_list = nb_plugin.get_loaded_plugins()
|
plugin_list = nb_plugin.get_loaded_plugins()
|
||||||
if isinstance(event, FriendAddNoticeEvent):
|
if isinstance(event, FriendAddNoticeEvent):
|
||||||
models = [
|
await asyncio.gather(*[PluginPermission.update_or_create(name=plugin, session_id=event.user_id, session_type='user') for plugin
|
||||||
PluginPermission(name=plugin, session_id=event.user_id, session_type='user') for plugin in plugin_list if plugin not in HIDDEN_PLUGINS
|
in plugin_list if plugin not in HIDDEN_PLUGINS])
|
||||||
]
|
elif isinstance(event, GroupIncreaseNoticeEvent):
|
||||||
elif isinstance(event, GroupIncreaseNoticeEvent) and event.user_id == event.self_id:
|
await asyncio.gather(
|
||||||
models = [
|
*[PluginPermission.update_or_create(name=plugin, session_id=event.group_id, session_type='group') for plugin
|
||||||
PluginPermission(name=plugin, session_id=event.group_id, session_type='group') for plugin in plugin_list if
|
in plugin_list if plugin not in HIDDEN_PLUGINS])
|
||||||
plugin not in HIDDEN_PLUGINS
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
if models:
|
|
||||||
await PluginPermission.bulk_create(
|
|
||||||
models,
|
|
||||||
ignore_conflicts=True
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user