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 E569680DD9; Tue, 13 Sep 2022 10:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1663064790; bh=TQ/+VsiYieGTnL0y7QYT2oqXfM1Au6OBgMxQmppuhL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ptnxAc740O/gr0GGq93s0WeCo6CP/aerXcKnTVfvZPcRMwqAvZlxfkeYvDdFKJpm+ krQA6ZxlY2y25mlKNYA+l+oB0JC9davDFcYqv0bE5GrOo2ocCFnNkCcm77j9x2lkGs d5Yb+owvnF05vLzdPmdGiILbYQF7hZAiXwx1CKGjcfGg046LOM3LMFm91InocFzWIL xn4rYm25m9+e8yBx8fhPakwFA1A0BV42AuQjzgUhtFlNSg/htYN+cjJzDGu8fkzUOY fg6/8I/sCQ+zEsohSkrg3KqkoGcHyvfn9ZC5Y8pfCpT1IBUh+ghM9zgEMy0iqm1RFU bmLeDAWbVOwfA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v2 15/17] discord: Add save_broadcast() in database insertion Date: Tue, 13 Sep 2022 17:24:56 +0700 Message-Id: <20220913102458.615-16-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220913102458.615-1-kiizuha@gnuweeb.org> References: <20220913102458.615-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add save_broadcast() to save discord guild channel to the database for send new lore emails to the channels. Signed-off-by: Muhammad Rizki --- .../database/methods/insertion/__init__.py | 4 +- .../methods/insertion/insert_broadcast.py | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 daemon/dscord/database/methods/insertion/insert_broadcast.py diff --git a/daemon/dscord/database/methods/insertion/__init__.py b/daemon/dscord/database/methods/insertion/__init__.py index 632aa55..4192735 100644 --- a/daemon/dscord/database/methods/insertion/__init__.py +++ b/daemon/dscord/database/methods/insertion/__init__.py @@ -5,8 +5,10 @@ from .insert_atom import InsertAtom +from .insert_broadcast import InsertBroadcast class Insertion( - InsertAtom + InsertAtom, + InsertBroadcast ): pass diff --git a/daemon/dscord/database/methods/insertion/insert_broadcast.py b/daemon/dscord/database/methods/insertion/insert_broadcast.py new file mode 100644 index 0000000..e68f9b4 --- /dev/null +++ b/daemon/dscord/database/methods/insertion/insert_broadcast.py @@ -0,0 +1,42 @@ +from mysql.connector import errors +from datetime import datetime + + +class InsertBroadcast: + + def save_broadcast( + self, + guild_id: int, + channel_id: int, + channel_name: str, + channel_link: str = None, + ): + try: + return self.__insert_broadcast( + guild_id=guild_id, + channel_id=channel_id, + channel_name=channel_name, + channel_link=channel_link + ) + except errors.IntegrityError: + # + # Duplicate data, skip! + # + return None + + + def __insert_broadcast( + self, + guild_id: int, + channel_id: int, + channel_name: str, + channel_link: str = None, + ): + q = """ + INSERT INTO dc_broadcasts + (guild_id, channel_id, channel_name, channel_link, created_at) + VALUES (%s, %s, %s, %s, %s) + """ + values = (guild_id, channel_id, channel_name, channel_link, datetime.utcnow()) + self.cur.execute(q, values) + return self.cur.lastrowid -- Muhammad Rizki