From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.57]) by gnuweeb.org (Postfix) with ESMTPSA id 850527E317; Tue, 19 Jul 2022 00:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658189916; bh=m6hsIOmNqZiKItiioFrGvTJCTIzLPBF0s5j7uI1JMYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wb+P4fM0ZnbgvmwBmSUSUXE1U0TLxGpLQy1MLPQG9pvdyQ2lTkxpmIfvDFfKHj874 XYHCSWyVlsdmpQSuaPNNCM7O0fjwlEykIrIQG++63spt8BKeS5nnBFotOC9FsZYvfq qr16zQARnFE5lfG/9MeXi1FWxSdfUP7nv2IUd4tq6Wpoy9rQaLMvRjXPeDrIK6hrv5 F/L2+SugOlu/IbhmPVJgbuNWZTt01MGat1uRFDgdwqLuHRR3mex51Q9wr/2q8UDNNT RvTDjgs9Z5rdH9KWPsaeuwrB+zcinl0mQ4gpbKEvxgkNTvMnTR8tVhEJKKQILsJtLv OeXtyBJbcwnNg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v2 17/18] daemon: Remove __send_patch_msg() Date: Tue, 19 Jul 2022 07:17:43 +0700 Message-Id: <20220719001744.1950-18-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220719001744.1950-1-kiizuha@gnuweeb.org> References: <20220719001744.1950-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Muhammad Rizki I want to remove the __send_patch_msg() and displace the prepare patch, send patch, and clean up patch into the send_patch_email() in packages/client.py. Signed-off-by: Muhammad Rizki --- daemon/packages/client.py | 12 +++++++++--- daemon/scraper/bot.py | 16 +++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/daemon/packages/client.py b/daemon/packages/client.py index d4689d3..e125ed7 100644 --- a/daemon/packages/client.py +++ b/daemon/packages/client.py @@ -2,6 +2,8 @@ from pyrogram import Client from pyrogram.enums import ParseMode from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton from typing import Union, BinaryIO +from email.message import Message +from scraper import utils from .decorator import handle_flood @@ -39,15 +41,16 @@ class DaemonClient(Client): @handle_flood async def send_patch_email( self, + mail: Message, chat_id: Union[int, str], - doc: Union[str, BinaryIO], - caption: str, + text: str, reply_to: int, url: str = None, parse_mode: ParseMode = ParseMode.HTML ) -> Message: print("[send_patch_email]") - return await self.send_document( + tmp, doc, caption, url = utils.prepare_send_patch(mail, text, url) + m = await self.send_document( chat_id=chat_id, document=doc, caption=caption, @@ -60,3 +63,6 @@ class DaemonClient(Client): )] ]) ) + + utils.clean_up_after_send_patch(tmp) + return m diff --git a/daemon/scraper/bot.py b/daemon/scraper/bot.py index bc4025d..c193c9e 100644 --- a/daemon/scraper/bot.py +++ b/daemon/scraper/bot.py @@ -114,8 +114,9 @@ class Bot(): url = str(re.sub(r"/raw$", "", url)) if is_patch: - m = await self.__send_patch_msg(mail, tg_chat_id, - reply_to, text, url) + m = await self.client.send_patch_email( + mail, tg_chat_id, text, reply_to, url + ) else: text = "#ml\n" + text m = await self.client.send_text_email( @@ -152,14 +153,3 @@ class Bot(): return None return self.db.get_tg_reply_to(reply_to, tg_chat_id) - - - async def __send_patch_msg(self, mail, tg_chat_id, reply_to, text, url): - print("[__send_patch_msg]") - - tmp, doc, caption, url = utils.prepare_send_patch(mail, text, url) - ret = await self.client.send_patch_email( - tg_chat_id, doc, caption, reply_to, url - ) - utils.clean_up_after_send_patch(tmp) - return ret -- Muhammad Rizki