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 3D9B780E9E; Tue, 20 Sep 2022 13:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663681716; bh=jo5kIXCHs+xHUJC89Wu4iFPuH2vH0LpZL4dyuyXAdTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qnz7slOzJXJPyNEdR4m0UWHqJIHFzzkxYfYn0+KPTSRW+H3u4qoVXF9dPqrpExaVV wG9m4cZDJL2HfQ49UyTu99vSqKcNllRbXjeQG7k52Ryx9F8XrxwWC1CMVm5IPZ8f9q XgAW+iag+QagcEYadRX5rLH42gUFLhQhvi4VCfvDYEgkFF+XP7nHv0q5GbmScz8rOV 4CYg5cmvm7h5s6yyMwOj3Uy6QIILqu/QOcZi0NO6wTuHjXP53xIJjNNUGbhWT31pDM jW5q6fYsac8GJJFagni2B9J15i80FvYGMSXC7MAqpJf1HoZJdEee+F7SjVsof8FXb9 qoHISu/dLQLtg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v4 03/17] telegram: Rename some functions in scraper/bot.py Date: Tue, 20 Sep 2022 20:47:58 +0700 Message-Id: <20220920134812.331-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220920134812.331-1-kiizuha@gnuweeb.org> References: <20220920134812.331-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Rename some functions to make it more readable. 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