From b38dde1b70bd80fff85c6d54b6ebc15ca81f4a58 Mon Sep 17 00:00:00 2001 From: passthem Date: Sat, 7 Mar 2026 17:50:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=8B=A5=E5=B9=B2=E6=8B=BC?= =?UTF-8?q?=E5=86=99=E9=94=99=E8=AF=AF=EF=BC=8C=E5=A2=9E=E5=BC=BA=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konabot/common/permsys/__init__.py | 5 ++++- konabot/common/permsys/repo.py | 16 ++++++++++------ konabot/plugins/perm_manage/__init__.py | 12 ++++++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/konabot/common/permsys/__init__.py b/konabot/common/permsys/__init__.py index 7f5b8b7..3ae3904 100644 --- a/konabot/common/permsys/__init__.py +++ b/konabot/common/permsys/__init__.py @@ -91,7 +91,10 @@ def create_startup(): # pragma: no cover @driver.on_shutdown async def _(): - await db.close_all_connections() + try: + await db.close_all_connections() + except Exception: + pass DepPermManager = Annotated[PermManager, Depends(perm_manager)] diff --git a/konabot/common/permsys/repo.py b/konabot/common/permsys/repo.py index f8a294a..4c944b7 100644 --- a/konabot/common/permsys/repo.py +++ b/konabot/common/permsys/repo.py @@ -121,7 +121,7 @@ class PermRepo: async def get_entity_id_batch( self, entities: list[PermEntity] ) -> dict[PermEntity, int]: - """批量获取 Entity 的 eneity_id + """批量获取 Entity 的 entity_id Args: entities: PermEntity 列表 @@ -130,11 +130,15 @@ class PermRepo: 字典,键为 PermEntity,值为对应的 ID """ - for entity in entities: - await self.conn.execute( - s("create_entity.sql"), - (entity.platform, entity.entity_type, entity.external_id), - ) + # for entity in entities: + # await self.conn.execute( + # s("create_entity.sql"), + # (entity.platform, entity.entity_type, entity.external_id), + # ) + await self.conn.executemany( + s("create_entity.sql"), + [(e.platform, e.entity_type, e.external_id) for e in entities], + ) await self.conn.commit() val_placeholders = ", ".join(["(?, ?, ?)"] * len(entities)) params = [] diff --git a/konabot/plugins/perm_manage/__init__.py b/konabot/plugins/perm_manage/__init__.py index fe3ea6f..93bcd25 100644 --- a/konabot/plugins/perm_manage/__init__.py +++ b/konabot/plugins/perm_manage/__init__.py @@ -58,7 +58,7 @@ def make_formatter(parent: PermEntity): @cmd.assign("list") -async def list_permisison( +async def list_permission( pm: DepPermManager, ec: _DepEntityChain, event: Event, @@ -71,7 +71,7 @@ async def list_permisison( @cmd.assign("get") -async def get_permisison( +async def get_permission( pm: DepPermManager, ec: _DepEntityChain, perm: str, @@ -96,7 +96,7 @@ async def get_permisison( @cmd.assign("set") -async def set_permisison( +async def set_permission( pm: DepPermManager, ec: _DepEntityChain, perm: str, @@ -105,8 +105,8 @@ async def set_permisison( ): if any(i == val.lower() for i in ("y", "yes", "allow", "true", "t")): await pm.update_permission(ec[0], perm, True) - if any(i == val.lower() for i in ("n", "no", "deny", "false", "f")): + elif any(i == val.lower() for i in ("n", "no", "deny", "false", "f")): await pm.update_permission(ec[0], perm, False) - if any(i == val.lower() for i in ("null", "none")): + elif any(i == val.lower() for i in ("null", "none")): await pm.update_permission(ec[0], perm, None) - await get_permisison(pm, ec, perm, event) + await get_permission(pm, ec, perm, event)