keyword 新增被回复消息删除时间

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>
This commit is contained in:
sourcery-ai[bot] 2023-12-07 15:59:44 +08:00 committed by GitHub
parent 76dfacc1c1
commit 89ba586ca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,7 @@ class KeywordTask:
ban: int ban: int
restrict: int restrict: int
delay_delete: int delay_delete: int
source_delay_delete: Optional[int] = 0
def __init__( def __init__(
self, self,
@ -47,6 +48,7 @@ class KeywordTask:
ban: int = 0, ban: int = 0,
restrict: int = 0, restrict: int = 0,
delay_delete: int = 0, delay_delete: int = 0,
source_delay_delete: int = 0,
): ):
self.task_id = task_id self.task_id = task_id
self.cid = cid self.cid = cid
@ -62,6 +64,7 @@ class KeywordTask:
self.ban = ban self.ban = ban
self.restrict = restrict self.restrict = restrict
self.delay_delete = delay_delete self.delay_delete = delay_delete
self.source_delay_delete = source_delay_delete
def export(self): def export(self):
return { return {
@ -79,6 +82,7 @@ class KeywordTask:
"ban": self.ban, "ban": self.ban,
"restrict": self.restrict, "restrict": self.restrict,
"delay_delete": self.delay_delete, "delay_delete": self.delay_delete,
"source_delay_delete": self.source_delay_delete,
} }
def export_str(self, show_all: bool = False): def export_str(self, show_all: bool = False):
@ -87,6 +91,7 @@ class KeywordTask:
if show_all: if show_all:
text += f"<code>{self.cid}</code> - " text += f"<code>{self.cid}</code> - "
text += f"{self.msg}" text += f"{self.msg}"
text += f"{self.source_delay_delete}"
return text return text
def save_to_file(self): def save_to_file(self):
@ -162,7 +167,10 @@ class KeywordTask:
text, parse_mode=ParseMode.HTML, reply_to_message_id=reply_id text, parse_mode=ParseMode.HTML, reply_to_message_id=reply_id
) )
if self.delete: 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 uid = message.from_user.id if message.from_user else message.sender_chat.id
if self.ban > 0: if self.ban > 0:
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
@ -228,8 +236,10 @@ class KeywordTask:
if len(data) > 4: if len(data) > 4:
self.delay_delete = int(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") raise ValueError("Invalid task format")