Skip to content

Commit

Permalink
支持通过/pixivbot unschedule all命令取消所有订阅、/pixivbot unwatch all命令取消所有推送
Browse files Browse the repository at this point in the history
  • Loading branch information
ssttkkl committed Apr 26, 2023
1 parent 59a4e89 commit 477db42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/nonebot_plugin_pixivbot/handler/command/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ async def parse_args(self, args: Sequence[str]) -> dict:

# noinspection PyMethodOverriding
async def actual_handle(self, *, code: str):
if await scheduler.remove_task(self.post_dest, code):
if code != "all":
ok = await scheduler.remove_task(self.post_dest, code)
else:
await scheduler.remove_all_by_subscriber(self.post_dest)
ok = True

if ok:
await self.post_plain_text(message="取消订阅成功")
else:
raise BadRequestError("取消订阅失败,不存在该订阅")
Expand Down
8 changes: 7 additions & 1 deletion src/nonebot_plugin_pixivbot/handler/command/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ async def parse_args(self, args: Sequence[str]) -> dict:

# noinspection PyMethodOverriding
async def actual_handle(self, *, code: str):
if await watchman.remove_task(self.post_dest, code):
if code != "all":
ok = await watchman.remove_task(self.post_dest, code)
else:
await watchman.remove_all_by_subscriber(self.post_dest)
ok = True

if ok:
await self.post_plain_text(message="取消订阅成功")
else:
raise BadRequestError("取消订阅失败,不存在该订阅")
Expand Down
4 changes: 2 additions & 2 deletions src/nonebot_plugin_pixivbot/service/interval_task_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def _on_trigger(self, item: T):

if not available:
logger.info(f"[{self.tag}] {post_dest} is no longer available, removing all his tasks...")
await self.unschedule_all_by_subscriber(post_dest)
await self.remove_all_by_subscriber(post_dest)

@abstractmethod
def _make_job_trigger(self, item: T) -> BaseTrigger:
Expand Down Expand Up @@ -122,7 +122,7 @@ async def remove_task(self, post_dest: PostDestination[T_UID, T_GID], code: str)
else:
return False

async def unschedule_all_by_subscriber(self, post_dest: PostDestination[T_UID, T_GID]):
async def remove_all_by_subscriber(self, post_dest: PostDestination[T_UID, T_GID]):
old = await self.repo.delete_many_by_subscriber(get_bot_user_identifier(post_dest.bot),
post_dest.identifier)
for item in old:
Expand Down

0 comments on commit 477db42

Please sign in to comment.