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 5992E80D8A; Sun, 11 Sep 2022 10:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662892457; bh=TQ/+VsiYieGTnL0y7QYT2oqXfM1Au6OBgMxQmppuhL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJdhdqUrJ6ZnCOgHJyAKyHSPuFvrO8ewUFMNajNmg398i6L3xNFjj3kKPKjUmfM8O tmIf5njkuy5mZ3swnx53z7FGNNUdR5QdjEpeccD9wpICQq8YNIKSxo3yzBWTGfEfJF yEQ84gxHaAkQLF60QAJVEI92kdy05rNrKqSXKS3oBrKno8fhPCae+i25xLe5EWanfv N+UVzt2OmfyoHYbEDBiL6dbz8TjP+MbCcvouPQQUQido/ZAL3CEuhTYfhDRc25PgRR Q+r4BP/GwgWRgcEiWi9nOs+NWEh/sIzjlYJWId7iPh0USGewwWrrvFg6H9mszr/tdO NclpAbbV/6U9w== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v1 15/17] [discord] Add save_broadcast() in database insertion Date: Sun, 11 Sep 2022 17:33:21 +0700 Message-Id: <20220911103323.1949-16-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220911103323.1949-1-kiizuha@gnuweeb.org> References: <20220911103323.1949-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