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.177]) by gnuweeb.org (Postfix) with ESMTPSA id 49B0D8060C; Sat, 1 Oct 2022 13:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664629498; bh=QkUaJMwhBQc3Y4R1aAiNkxGfqxMUxur22Xsw85md6Jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ePifuk8PCZauiXSrupibZ9ipggrVRe5Wi2biaRnFJmMfgNKs9oG7DI75TaDfJgo61 GkTkTfgXD3N0gKa96eqj/a44EA7SNsWUc0m2F/Gp5u8Fu3B0uz2oshD9eZ+382yfpU kln61Ke0yEi3CnU5eWVtI2o83gFEE6a5rAbU3Kzy367QmmDgseSTSuUBRkh/fRnXT3 Lt7Gh54Uin2+kuqi7e3M5qe6Md7XABVMLndO7X0Pv+u6NbCXLX19ELkDJ0y8HLm0lt chhfxHV253PJT3lc6hjE18dC4uQhWJvmePk5ISjN1d3GrZQQkIjYEJMgRPkT1z9rll V0IfhkuplKoIA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 17/26] discord: Implement the mail Listener() class Date: Sat, 1 Oct 2022 20:03:45 +0700 Message-Id: <20221001130355.784-18-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221001130355.784-1-kiizuha@gnuweeb.org> References: <20221001130355.784-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