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 2D323804FD; Sat, 1 Oct 2022 13:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664629467; bh=AVqqvpp5fZCXyVRdalJr7aTYrwVmIWpXUXJTYOQCAs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nA7jgnFYPzJsPGMSGFJ3PsD+AfLeFt4dcuPQ5lKFEGmRINX24WaZzItyVQQUZ0BRY /XVDzqruUTQugrEAO43vUtNkGoYYxfuWRe3N46jnwH1SEiytQGxPi+3aqTK/5OjUwS Yke6xSxWiiUBlEcQ56g3zeb06yZN0NlpmefIHeK5G8eDUkEegNjWQbM8fDqwouMSA8 xWCQ/IoqncLS5xH+5fMNsWR0BSZ/um5NkuvU0r70mhJLkZseVWf2jtjOae0BnKdI1f fJjRpwVpeLKZj9WJ3GOy3EZX7KygflMRXone2BeHSGvS7cO27gTJZ/WaU/8NwtixVO 3zaeZUCxGuJaw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 05/26] discord: Add get_reply_id() in getter directory Date: Sat, 1 Oct 2022 20:03:33 +0700 Message-Id: <20221001130355.784-6-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: Add get_reply_id() to get the Discord message ID of the lore email message sent to the Discord channel. With this, the bot can reply to the sent message of the lore email. Signed-off-by: Muhammad Rizki --- .../database/methods/getter/__init__.py | 4 ++- .../database/methods/getter/get_reply.py | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 daemon/dscord/database/methods/getter/get_reply.py diff --git a/daemon/dscord/database/methods/getter/__init__.py b/daemon/dscord/database/methods/getter/__init__.py index 0f4b976..63cab01 100644 --- a/daemon/dscord/database/methods/getter/__init__.py +++ b/daemon/dscord/database/methods/getter/__init__.py @@ -7,10 +7,12 @@ from .get_atom_urls import GetAtomURL from .get_broadcast_chats import GetBroadcastChats from .get_email_id import GetEmailID +from .get_reply import GetDiscordReply class Getter( GetAtomURL, GetBroadcastChats, - GetEmailID + GetEmailID, + GetDiscordReply ): pass diff --git a/daemon/dscord/database/methods/getter/get_reply.py b/daemon/dscord/database/methods/getter/get_reply.py new file mode 100644 index 0000000..870dc84 --- /dev/null +++ b/daemon/dscord/database/methods/getter/get_reply.py @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# Copyright (C) 2022 Ammar Faizi +# + + +class GetDiscordReply: + + def get_reply_id(self, email_id, channel_id): + ''' + Get Telegram message ID sent match with + email message ID and Telegram chat ID. + - Return Telegram message ID if exists: `int` + - Return None if not exists` + ''' + q = """ + SELECT dc_mail_msg.dc_msg_id + FROM dc_emails INNER JOIN dc_mail_msg + ON dc_emails.id = dc_mail_msg.email_id + WHERE dc_emails.message_id = %(email_msg_id)s + AND dc_mail_msg.channel_id = %(channel_id)s + """ + + self.cur.execute(q, { + "email_msg_id": email_id, + "channel_id": channel_id + }) + res = self.cur.fetchone() + if not bool(res): + return None + + return res[0] -- Muhammad Rizki