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 C66ED80614; Thu, 21 Jul 2022 23:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658446228; bh=HNUmEX3kt9bCESZ2T6w2v0MdXHtqLqRcRjxoDK2PF/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l5ydvtYoiSwxBzTbD/msPfUlRjBvAHdCqJQnee8p0lFoLPb36Ce6cJ51lBuJW/j8N p3jbhWkYp/kZxpILgrmiBuPX7gEEddPH/Ni0S0Dd/3fgprpdijk2yluXGW0XmXt12T h4Wbco2KMZckkvRAGfsXxdpVvzcb+XsYoTnsMP2+1hfVsZJt6WTzn2zKeixqTHeVRV DDkKTZSOjgb8OYGH7q2lRRoycwN0FIEKpSrIW6U/NpEtDpQTfEEoWFlGzCRTlyvpNV M1IPByvVcwaHy4+8DPTL4fPT4nbCo2rmVixM/K8pSfM7XVqEL1Zqp/v4cUKgkJGMn3 nNHflEDbDDIpw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v3 16/17] Replace send email functions Date: Fri, 22 Jul 2022 06:29:37 +0700 Message-Id: <20220721232938.503-17-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: I want to replace called functions in packages/plugins/scrape.py because I created custom functions for send email to Telegram using inheritance method, so I replace it and remove related unused codes. Signed-off-by: Muhammad Rizki --- daemon/packages/plugins/scrape.py | 48 ++++++------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/daemon/packages/plugins/scrape.py b/daemon/packages/plugins/scrape.py index 1698c6d..280c3f9 100644 --- a/daemon/packages/plugins/scrape.py +++ b/daemon/packages/plugins/scrape.py @@ -4,15 +4,11 @@ # Copyright (C) 2022 Ammar Faizi # -from pyrogram.types import InlineKeyboardMarkup -from pyrogram.types import InlineKeyboardButton from pyrogram.types import Message from pyrogram import filters -from pyrogram import Client +from packages import DaemonClient from scraper import Scraper -from pyrogram import enums from scraper import utils -from scraper import Bot import shutil import re import asyncio @@ -25,11 +21,11 @@ import asyncio # .lore https://lore.kernel.org/path/message_id/raw # LORE_CMD_URL_PATTERN = r"^(?:\/|\.|\!)lore\s+(https?:\/\/lore\.kernel\.org\/\S+)" -@Client.on_message( +@DaemonClient.on_message( filters.regex(LORE_CMD_URL_PATTERN) & filters.chat(["kiizuah", "nekoha", -1001673279485]) ) -async def scrap_email(_, m: Message): +async def scrap_email(c: DaemonClient, m: Message): p = re.search(LORE_CMD_URL_PATTERN, m.text) if not p: return @@ -43,10 +39,14 @@ async def scrap_email(_, m: Message): text, files, is_patch = utils.create_template(mail) if is_patch: - m = await __send_patch_msg(m, mail, text, url) + m = await c.send_patch_email( + mail, m.chat.id, text, m.id, url + ) else: text = "#ml\n" + text - m = await __send_text_msg(m, text, url) + m = await c.send_text_email( + m.chat.id, text, m.id, url + ) for d, f in files: await m.reply_document(f"{d}/{f}", file_name=f) @@ -54,33 +54,3 @@ async def scrap_email(_, m: Message): if files: shutil.rmtree(str(files[0][0])) - - -async def __send_patch_msg(m, mail, text, url): - tmp, fnm, caption, url = Bot.prepare_send_patch(mail, text, url) - ret = await m.reply_document( - fnm, - caption=caption, - parse_mode=enums.ParseMode.HTML, - reply_markup=InlineKeyboardMarkup([ - [InlineKeyboardButton( - "See the full message", - url=url - )] - ]) - ) - Bot.clean_up_after_send_patch(tmp) - return ret - - -async def __send_text_msg(m, text, url): - return await m.reply( - text, - parse_mode=enums.ParseMode.HTML, - reply_markup=InlineKeyboardMarkup([ - [InlineKeyboardButton( - "See the full message", - url=url.replace("/raw","") - )] - ]) - ) -- Muhammad Rizki