From 69eb87fe8fb5850e6b804804441454eb768d41ac Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Sat, 11 Feb 2023 19:47:24 +0800 Subject: [PATCH] fix: use __aexit__ instead of close --- aiotieba_reviewer/__version__.py | 2 +- aiotieba_reviewer/database.py | 5 ----- examples/cmd_handler.py | 8 ++++---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/aiotieba_reviewer/__version__.py b/aiotieba_reviewer/__version__.py index 485f44a..748655c 100644 --- a/aiotieba_reviewer/__version__.py +++ b/aiotieba_reviewer/__version__.py @@ -1 +1 @@ -__version__ = "0.1.1" +__version__ = "0.1.2a0" diff --git a/aiotieba_reviewer/database.py b/aiotieba_reviewer/database.py index 32dc2a3..2c6b0e1 100644 --- a/aiotieba_reviewer/database.py +++ b/aiotieba_reviewer/database.py @@ -70,11 +70,6 @@ async def __aenter__(self) -> "MySQLDB": await self._create_pool() return self - async def close(self) -> None: - if self._pool is not None: - self._pool.close() - await self._pool.wait_closed() - async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: await self.close() diff --git a/examples/cmd_handler.py b/examples/cmd_handler.py index 73488fc..4ed9ef2 100644 --- a/examples/cmd_handler.py +++ b/examples/cmd_handler.py @@ -245,7 +245,7 @@ def _parse_config(_config: Dict[str, str]) -> Tuple[tb.Client, tbr.MySQLDB, tb.C async def close(self) -> None: await asyncio.gather( - *[c.close() for c in itertools.chain.from_iterable(self.admins.values())], self.listener.close() + *[c.__aexit__() for c in itertools.chain.from_iterable(self.admins.values())], self.listener.__aexit__() ) async def __aenter__(self) -> "Listener": @@ -371,7 +371,7 @@ async def cmd_hide(self, ctx: Context) -> None: 屏蔽指令所在主题帖 """ - if await ctx.admin.hide_thread(ctx.fname,ctx.tid): + if await ctx.admin.hide_thread(ctx.fname, ctx.tid): await ctx.admin.del_post(ctx.fname, ctx.pid) @check_and_log(need_permission=2, need_arg_num=0) @@ -419,7 +419,7 @@ async def _cmd_block(self, ctx: Context, day: int) -> None: user = await self._arg2user_info(ctx.args[0]) note = ctx.args[1] if len(ctx.args) > 1 else ctx.note - if await ctx.admin.block(user.portrait, day=day, reason=note): + if await ctx.admin.block(ctx.fname, user.portrait, day=day, reason=note): await ctx.admin.del_post(ctx.fname, ctx.pid) @check_and_log(need_permission=2, need_arg_num=1) @@ -777,7 +777,7 @@ async def cmd_water(self, ctx: Context) -> None: 将指令所在主题帖标记为无关水,并临时屏蔽 """ - if await ctx.admin_db.add_tid(ctx.tid, tag=1) and await ctx.admin.hide_thread(ctx.fname,ctx.tid): + if await ctx.admin_db.add_tid(ctx.tid, tag=1) and await ctx.admin.hide_thread(ctx.fname, ctx.tid): await ctx.admin.del_post(ctx.fname, ctx.pid) @check_and_log(need_permission=2, need_arg_num=0)