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.149]) by gnuweeb.org (Postfix) with ESMTPSA id 245D580F78; Sun, 25 Sep 2022 21:15:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664140517; bh=Veb8E7AVb0dEFWe2reqHonPBNmsGlqqkIB1iyFOpja4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QMz1SS0n5g/3kaS1HuP3XtEht4eNtxX5vrevlTyxXedKzoOM87VJL9u6wZO26D5XB d57Nr0+uRxf79/rwJohWWXWhEtIYKTFsyRLzEzngzIPft9Kt9zRNEqHH+UIT7aXtmE 3BJOrng3P4964/dx+gzUEHoWLgGgUaMzKpE0Uh8BSLpfBTQoF1XJX33lOrCX+Ixr+u laYQN72i2oPnY10jZ5Z/lw/GwS4S+rDaLxhylR8MAZ9fxZ+bZuoiDrrLipmQyKZsWN 7hgyHvRR2ZZUle5s3B2ERYE9HIdFo2imwXj32PHJ8x/wnIXMODPZ/I3cpSUAZrpmKX k0Ur3yqgbngQg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v5 15/18] discord: Add save_broadcast() in database insertion Date: Mon, 26 Sep 2022 04:14:24 +0700 Message-Id: <20220925211427.412-16-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220925211427.412-1-kiizuha@gnuweeb.org> References: <20220925211427.412-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Add save_broadcast() to save the discord guild channel to the database for sending 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