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.100]) by gnuweeb.org (Postfix) with ESMTPSA id 5833980DC0; Tue, 13 Sep 2022 10:26:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663064763; bh=UwzYniZKeXJGrgbNiTibW8dofkoawRAloXFpTuCnBKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G7dzwLKiHQ+JPJwJNPWRY4rDQXNqXmXZsWMvEvwwnwagSaos3ZZan1JF9hpITF/PX X+U7ltxinwN+UZW4KIpOsumrNZEW4xMmQM/tcDtjZPEQ5g9znXlCLUeb7pXbrSJk0o So+Qa3eh5wZ/zsoT61P57p6+lW2oa8exv9qgwzfz3RKxCkvqJkOLYjZED/LniPmG7E 3mAy8Xi345bkG2ic4j5ZX7XjlmSrLSzD4Q4K1du5TP3GZ+UB31dymXlhf4rMYDKTWS TnrQMBDWO7kaKdFGDI7X7ucQ7HA7EzEtUsgyQf2cxd9ByTCTZYB2Nddfo2Bl6laCdg YINVTKo92VGfQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v2 03/17] telegram: Renaming some functions in scraper/bot.py Date: Tue, 13 Sep 2022 17:24:44 +0700 Message-Id: <20220913102458.615-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220913102458.615-1-kiizuha@gnuweeb.org> References: <20220913102458.615-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Just renaming some functions... Signed-off-by: Muhammad Rizki --- daemon/telegram/scraper/bot.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/daemon/telegram/scraper/bot.py b/daemon/telegram/scraper/bot.py index 9ef5508..a7087ad 100644 --- a/daemon/telegram/scraper/bot.py +++ b/daemon/telegram/scraper/bot.py @@ -4,6 +4,7 @@ # Copyright (C) 2022 Ammar Faizi # +from pyrogram.types import Message from apscheduler.schedulers.asyncio import AsyncIOScheduler from packages import DaemonClient from scraper import Scraper @@ -72,7 +73,7 @@ class Bot(): chats = self.db.get_broadcast_chats() for chat in chats: async with self.mutexes.send_to_tg: - should_wait = await self.__send_to_tg(url, mail, + should_wait = await self.__send_mail(url, mail, chat[1]) if should_wait: @@ -80,7 +81,7 @@ class Bot(): # @__must_hold(self.mutexes.send_to_tg) - async def __send_to_tg(self, url, mail, tg_chat_id): + async def __send_mail(self, url, mail, tg_chat_id): email_msg_id = utils.get_email_msg_id(mail) if not email_msg_id: # @@ -89,7 +90,7 @@ class Bot(): # return False - email_id = self.__need_to_send_to_telegram(email_msg_id, + email_id = self.__mail_id_from_db(email_msg_id, tg_chat_id) if not email_id: # @@ -99,16 +100,16 @@ class Bot(): return False text, files, is_patch = utils.create_template(mail) - reply_to = self.get_tg_reply_to(mail, tg_chat_id) + reply_to = self.get_reply(mail, tg_chat_id) url = str(re.sub(r"/raw$", "", url)) if is_patch: - m = await self.client.send_patch_email( + m: "Message" = 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( + m: "Message" = await self.client.send_text_email( tg_chat_id, text,reply_to, url ) @@ -123,7 +124,7 @@ class Bot(): return True - def __need_to_send_to_telegram(self, email_msg_id, tg_chat_id): + def __mail_id_from_db(self, email_msg_id, tg_chat_id): email_id = self.db.save_email(email_msg_id) if email_id: return email_id @@ -132,7 +133,7 @@ class Bot(): return email_id - def get_tg_reply_to(self, mail, tg_chat_id): + def get_reply(self, mail, tg_chat_id): reply_to = mail.get("in-reply-to") if not reply_to: return None -- Muhammad Rizki