Skip to content

Commit

Permalink
keyword 新增被回复消息删除时间
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people authored Dec 7, 2023
1 parent 76dfacc commit 89ba586
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions keyword/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class KeywordTask:
ban: int
restrict: int
delay_delete: int
source_delay_delete: Optional[int] = 0

def __init__(
self,
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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):
Expand All @@ -87,6 +91,7 @@ def export_str(self, show_all: bool = False):
if show_all:
text += f"<code>{self.cid}</code> - "
text += f"{self.msg}"
text += f"{self.source_delay_delete}"
return text

def save_to_file(self):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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")


Expand Down

0 comments on commit 89ba586

Please sign in to comment.