From 89ba586ca9a4abf01eaf4ecc6831cc496864586b Mon Sep 17 00:00:00 2001 From: "sourcery-ai[bot]" <58596630+sourcery-ai[bot]@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:59:44 +0800 Subject: [PATCH] =?UTF-8?q?keyword=20=E6=96=B0=E5=A2=9E=E8=A2=AB=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E6=B6=88=E6=81=AF=E5=88=A0=E9=99=A4=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Els <48439969+EAlyce@users.noreply.github.com> Co-authored-by: Sourcery AI <> Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com> --- keyword/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/keyword/main.py b/keyword/main.py index 249804c4..517827c5 100644 --- a/keyword/main.py +++ b/keyword/main.py @@ -30,6 +30,7 @@ class KeywordTask: ban: int restrict: int delay_delete: int + source_delay_delete: Optional[int] = 0 def __init__( self, @@ -47,6 +48,7 @@ def __init__( ban: int = 0, restrict: int = 0, delay_delete: int = 0, + source_delay_delete: int = 0, ): self.task_id = task_id self.cid = cid @@ -62,6 +64,7 @@ def __init__( self.ban = ban self.restrict = restrict self.delay_delete = delay_delete + self.source_delay_delete = source_delay_delete def export(self): return { @@ -79,6 +82,7 @@ def export(self): "ban": self.ban, "restrict": self.restrict, "delay_delete": self.delay_delete, + "source_delay_delete": self.source_delay_delete, } def export_str(self, show_all: bool = False): @@ -87,6 +91,7 @@ def export_str(self, show_all: bool = False): if show_all: text += f"{self.cid} - " text += f"{self.msg}" + text += f"{self.source_delay_delete}" return text def save_to_file(self): @@ -162,7 +167,10 @@ async def process_keyword(self, message: Message): text, parse_mode=ParseMode.HTML, reply_to_message_id=reply_id ) if self.delete: - await message.safe_delete() + if self.source_delay_delete > 0: + add_delete_message_job(message, self.source_delay_delete) + else: + await message.safe_delete() uid = message.from_user.id if message.from_user else message.sender_chat.id if self.ban > 0: with contextlib.suppress(Exception): @@ -228,8 +236,10 @@ def parse_task(self, text: str): if len(data) > 4: self.delay_delete = int(data[4]) + if len(data) > 5: # assuming the source_delay_delete is the 6th part of the task format + self.source_delay_delete = int(data[5]) - if self.ban < 0 or self.restrict < 0 or self.delay_delete < 0: + if self.ban < 0 or self.restrict < 0 or self.delay_delete < 0 or self.source_delay_delete < 0: raise ValueError("Invalid task format")