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.126.135]) by gnuweeb.org (Postfix) with ESMTPSA id 247557E416; Tue, 3 Jan 2023 06:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1672727827; bh=j8wSVkYC+F3edPtbe1rUXRolx16G1kXFimWQuvP7ulk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VAWKJdWY9yGc0G1aPy4FnxlBVm66E7tekr9Ji21SP2vpZFh9Nt7NKJXW0ZYoZrdL6 m1VByAKigYtSfQNtVe24ZhJmCGSWvLtPzAo9Bki30SfJcSIdcFaGMkLrtw8F5QDWyU dQuUS7zQl689BfacbuK/SsAJYgSZOSf8Sor2hgb9MEVlceu6D2lodssdPIjUQM50c4 kZZQkI0vaJGH7GYFTqeJZe2x+5FjP1WSivK/UgR8li4zEzR/lyMeOdHBHwcBvPVsw+ EOQuXiplaKvvVuy8p1utI6zukTpFq3sZp6GvW+ByftptgaDrpXnitm/Le4Q+btaOcH /GWBH3g9VrzJQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 03/13] refactor(telegram)!: Ensure the Telegram bot has been started Date: Tue, 3 Jan 2023 13:36:31 +0700 Message-Id: <20230103063641.1680-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230103063641.1680-1-kiizuha@gnuweeb.org> References: <20230103063641.1680-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We need to start the Telegram bot first before the listener is started. So, if error may happen, when the listener sending a report message to the channel, the Telegram bot is already been started. Signed-off-by: Muhammad Rizki --- daemon/telegram/mailer/listener.py | 1 + daemon/tg.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py index 8425dd4..eed3953 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -37,6 +37,7 @@ class Bot(): # Execute __run() once to avoid high latency at # initilization. # + self.sched.start() self.runner = self.sched.add_job( func=self.__run, misfire_grace_time=None, diff --git a/daemon/tg.py b/daemon/tg.py index 73ff2b9..9d50e44 100644 --- a/daemon/tg.py +++ b/daemon/tg.py @@ -7,6 +7,7 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler from dotenv import load_dotenv from mysql import connector +from pyrogram import idle from atom import Scraper from telegram.packages import DaemonClient from telegram.mailer import BotMutexes @@ -58,9 +59,11 @@ def main(): scraper=Scraper(), mutexes=BotMutexes() ) - sched.start() + + client.start() bot.run() - client.run() + idle() + client.stop() if __name__ == '__main__': -- Muhammad Rizki