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.94]) by gnuweeb.org (Postfix) with ESMTPSA id 262877E7BE; Thu, 21 Jul 2022 23:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658446224; bh=3Ceo95sH8I11GsCW9BFwd5vxg+DxqHns8omu+7fdO3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YOlhZLyVJ/RqKcURMMgDHSv0IpmPCwHqsfxcK0xlD6HkmcfMAsX4NDtaGGvp3YCKt ew8gaAciZacOzoeA9g6KH7Xc87l8ENjcbFzNZz14UHiX/oT7xC3vtyYWxMSHTV3q6w Smzwg/a8GwiC0skCp6+qh2K6SzbhgceUguanVxpLa8Hf8n/6jrvh8rtyDrCe9JSdoQ z+4qydhAfQBbQZJ+qolRhyEGDLSYIRMFIu5nUnKI+y1y88FDx1mAgWHvATDyZHffka RUx+mG5lw2noPnk2OSeCV5ZbyM4vfuJRcZyjzP8ZvJ2o2WMvMH/xNdw8TKTCp5xrub EjeWdPIXZh0tg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v3 14/17] daemon: Remove __send_patch_msg() Date: Fri, 22 Jul 2022 06:29:35 +0700 Message-Id: <20220721232938.503-15-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220721232938.503-1-kiizuha@gnuweeb.org> References: <20220721232938.503-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 45acac3..5be7427 100644 --- a/daemon/packages/client.py +++ b/daemon/packages/client.py @@ -7,6 +7,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 @@ -44,15 +46,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, @@ -65,3 +68,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 38c6e94..c89ed58 100644 --- a/daemon/scraper/bot.py +++ b/daemon/scraper/bot.py @@ -118,8 +118,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( @@ -156,14 +157,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