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 944F180D11; Sun, 11 Sep 2022 10:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662892429; bh=UwzYniZKeXJGrgbNiTibW8dofkoawRAloXFpTuCnBKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLPQxKJzovKKiJjynllC5lpOHSaGktD/GTZbRG+tNm2zQK4FL82ucTEn4abr+k9t0 vuew/bSLFfYRNog+5U2bPBhGRkYgza+0QnEPjOvVB71QoNoxwOs0wXeVK7bIB11il5 wBAQmmOq6eW9NfInsHTDqQEvst3qrafd1O1nmeYfjgMpQP0AAE47YDWVqzeBXYhSXF AzukiAD3oxkF/FDeK7LKmHEVrL2z7QJidBR6iNdOVdLD2jmZAq4RSed/9SKoLsFQUG orbMfrVvIhcgL9qogr1WcX/nwEL5khweMOBWdXM1lCXM6X7pmUeZmtu5KxSNr6PpoZ 3Hs1xStDLRoNQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v1 03/17] [telegram] Renaming some functions in scraper/bot.py Date: Sun, 11 Sep 2022 17:33:09 +0700 Message-Id: <20220911103323.1949-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220911103323.1949-1-kiizuha@gnuweeb.org> References: <20220911103323.1949-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