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.94]) by gnuweeb.org (Postfix) with ESMTPSA id 30E4D806D7; Fri, 29 Jul 2022 01:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659058929; bh=pbxpv0N6lNYvxmSdow6HyfaIs7+Xv4aNgO3/5shlC7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cIuIPd8Xf0ZheUgCS+vls4u5RG+xV5qaASGPDpVJ8xm0mHOnXTpGxhMEGoefptdOB ak99buFHv4wVFTPXoLN3TUxLKh1PsgRodGKNlz5oa0j7cuaNl1dwn1Tj49lVO3vXyi /+nV/DEG8k1tYOLoGsPXh7H40rVSka+Z8w8VN2Ld3MBGlWFmBJQ346vcxyB5IDc0aT Yv5rb6IYslmUZyXPRC+pgbK/gVIgCHkcH/+e3HEsQEV5/yI+nq8upYjeyoTWFRbZlZ BLV6QNVtXg6jURJDJIvbg1nJQsmN40ewWN+sVrPVLEjhGXrK0hDiLdmzsRGj7Ao/LB 805DMcjedKAtw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v3 15/18] Create /add_bc bot command Date: Fri, 29 Jul 2022 08:40:49 +0700 Message-Id: <20220729014052.1547-16-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220729014052.1547-1-kiizuha@gnuweeb.org> References: <20220729014052.1547-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Create /add_bc bot command for adding the current chat into the database Signed-off-by: Muhammad Rizki --- .../plugins/commands/manage_broadcast.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 daemon/packages/plugins/commands/manage_broadcast.py diff --git a/daemon/packages/plugins/commands/manage_broadcast.py b/daemon/packages/plugins/commands/manage_broadcast.py new file mode 100644 index 0000000..8397508 --- /dev/null +++ b/daemon/packages/plugins/commands/manage_broadcast.py @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +from pyrogram.types import Message +from pyrogram import filters, enums +from packages import DaemonClient + + +@DaemonClient.on_message( + filters.command("add_bc") & + (filters.private | filters.group) +) +async def add_broadcast(c: DaemonClient, m: Message): + if m.chat.type == enums.ChatType.PRIVATE: + chat_name = m.chat.first_name + else: + chat_name = m.chat.title + + inserted = c.db.insert_broadcast( + chat_id=m.chat.id, + name=chat_name, + type=str(m.chat.type), + created_at=m.date, + username=m.chat.username, + link=m.chat.invite_link + ) + + if inserted is None: + msg = f"This chat already added for receiving email messages" + else: + msg = f"Success add this chat for receiving email messages" + + await m.reply(msg) -- Muhammad Rizki