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.217]) by gnuweeb.org (Postfix) with ESMTPSA id 183288104C; Mon, 3 Oct 2022 23:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664841215; bh=QkUaJMwhBQc3Y4R1aAiNkxGfqxMUxur22Xsw85md6Jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W3rEq2LKiObSVA7/WcrY3Yarrc1DbtOSykFOAXimxdG2raDd4DQ1ikyemV+trc9/H VDmb6M7GoFy5r3M7jZ4Xo1U8RlFDdaHc8J3zp4EmDGeMhNasXzqDhjgOLYobObbjLw HMRgMSZy/mPOYItCKtZRoLK1HR8ndp9Go4IzQHU5ABqcBKmiwfqhFvdSQMty0IR5uZ lTStovDksUUAK1aUKBR3zedV2cNPcv++APf0gaZV5dFW+cjDrwYjNvE6Zu9ERZu+va Xv7tQ93nTYWpnT7e7W93Ohuo0qz2fkl9mKDJ7fJbSGJiyJyXD25U6VbwsDnfQ5xjh+ 5Kf1Hm+EMq6Vw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 19/28] discord: Implement the mail Listener() class Date: Tue, 4 Oct 2022 06:52:20 +0700 Message-Id: <20221003235230.1824-20-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221003235230.1824-1-kiizuha@gnuweeb.org> References: <20221003235230.1824-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Use the mail Listener() class in the dc.py and add the scheduler for the Listener() class works. Signed-off-by: Muhammad Rizki --- daemon/dc.py | 20 +++++++++++++++++++ daemon/dscord/gnuweeb/client.py | 1 + .../dscord/gnuweeb/plugins/events/on_ready.py | 2 ++ 3 files changed, 23 insertions(+) diff --git a/daemon/dc.py b/daemon/dc.py index 9b86df2..5028e94 100644 --- a/daemon/dc.py +++ b/daemon/dc.py @@ -6,13 +6,24 @@ import os from dotenv import load_dotenv from mysql import connector +from apscheduler.schedulers.asyncio import AsyncIOScheduler from dscord.gnuweeb import GWClient +from dscord.mailer import Listener +from dscord.mailer import Mutexes +from atom import Scraper def main(): load_dotenv("discord.env") + sched = AsyncIOScheduler( + job_defaults={ + "max_instances": 3, + "misfire_grace_time": None + } + ) + client = GWClient( db_conn=connector.connect( host=os.getenv("DB_HOST"), @@ -21,6 +32,15 @@ def main(): database=os.getenv("DB_NAME") ) ) + + mailer = Listener( + client=client, + sched=sched, + scraper=Scraper(), + mutexes=Mutexes() + ) + client.mailer = mailer + client.run(os.getenv("DISCORD_TOKEN"), log_handler=None) diff --git a/daemon/dscord/gnuweeb/client.py b/daemon/dscord/gnuweeb/client.py index 2506ec3..03a1b8c 100644 --- a/daemon/dscord/gnuweeb/client.py +++ b/daemon/dscord/gnuweeb/client.py @@ -20,6 +20,7 @@ class GWClient(commands.Bot): self.db = DB(db_conn) intents = Intents.default() intents.message_content = True + self.mailer = None super().__init__( command_prefix=["$", "."], description="Just a bot for receiving lore emails.", diff --git a/daemon/dscord/gnuweeb/plugins/events/on_ready.py b/daemon/dscord/gnuweeb/plugins/events/on_ready.py index cb7de29..c93e8a0 100644 --- a/daemon/dscord/gnuweeb/plugins/events/on_ready.py +++ b/daemon/dscord/gnuweeb/plugins/events/on_ready.py @@ -13,6 +13,8 @@ class OnReady(commands.Cog): @commands.Cog.listener() async def on_ready(self): + self.bot.mailer.run() + t = "[ GNU/Weeb Bot is connected ]\n\n" t += f"ID : {self.bot.user.id}\n" t += f"Name : {self.bot.user.display_name}\n" -- Muhammad Rizki