public inbox for [email protected]
 help / color / mirror / Atom feed
From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH v1 17/26] discord: Implement the mail Listener() class
Date: Sat,  1 Oct 2022 20:03:45 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Use the mail Listener() class in the dc.py and add the scheduler for
the Listener() class works.

Signed-off-by: Muhammad Rizki <[email protected]>
---
 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


  parent reply	other threads:[~2022-10-01 13:04 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-01 13:03 [PATCH v1 00/26] The complete version of the Discord bot Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 01/26] discord: Add get_atom_urls() to get the list of atom URLs Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 02/26] Fix the storage management after the refactor was happened Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 03/26] discord: Add get_broadcast_chats() to get the list of broadcast chats Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 04/26] discord: Add get_email_id() in getter directory Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 05/26] discord: Add get_reply_id() " Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 06/26] discord: Inherit Getter() class to the DBMethods() class Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 07/26] discord: Add delete_atom() in deletion directory Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 08/26] discord: Add delete_broadcast() " Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 09/26] discord: Inherit the Deletion() class to the DBMethods() class Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 10/26] discord: Inherit the DBMethods() class to the DB() class Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 11/26] discord: Use the created " Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 12/26] telegram: Rename some utility functions Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 13/26] discord: Add a FullMessageBtn() class in models Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 14/26] discord: Add filters.wait_on_limit() decorator Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 15/26] discord: Add send lore email message functions Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 16/26] discord: Add mail listener Muhammad Rizki
2022-10-01 13:03 ` Muhammad Rizki [this message]
2022-10-01 13:03 ` [PATCH v1 18/26] discord: Add @filters.lore_admin() decorator Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 19/26] discord: Add a list of atom URL slash command Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 20/26] discord: Add an add atom " Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 21/26] discord: Add a delete " Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 22/26] discord: Add channel_link() in the atom/utils.py Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 23/26] discord: Add a list broadcast slash command Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 24/26] discord: Add an add " Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 25/26] discord: Add a delete " Muhammad Rizki
2022-10-01 13:03 ` [PATCH v1 26/26] discord: Change the on_ready message Muhammad Rizki
2022-10-03 12:48 ` [PATCH v1 00/26] The complete version of the Discord bot Ammar Faizi
2022-10-03 13:04   ` Muhammad Rizki
2022-10-03 13:13     ` Ammar Faizi
2022-10-03 13:12   ` Muhammad Rizki
2022-10-03 13:13     ` Ammar Faizi
2022-10-03 23:12   ` Alviro Iskandar Setiawan
2022-10-03 23:14     ` Ammar Faizi
2022-10-03 23:18     ` Muhammad Rizki
2022-10-03 23:22       ` Alviro Iskandar Setiawan
2022-10-03 23:31         ` Ammar Faizi
2022-10-03 23:33         ` Muhammad Rizki
2022-10-03 23:36           ` Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox