Skip to content

Commit

Permalink
fix: use __aexit__ instead of close
Browse files Browse the repository at this point in the history
  • Loading branch information
lumina37 committed Feb 11, 2023
1 parent 8b82a32 commit 69eb87f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aiotieba_reviewer/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.1"
__version__ = "0.1.2a0"
5 changes: 0 additions & 5 deletions aiotieba_reviewer/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions examples/cmd_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 69eb87f

Please sign in to comment.