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.157]) by gnuweeb.org (Postfix) with ESMTPSA id 9D0467E257; Sat, 30 Jul 2022 04:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659156075; bh=z6UP9OomH3Zaj0jge8t2QiTzSiyVO4pKe/wK4w9GHqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rO+OG4aJ4vBRcDHnkulQDG4bmhoOQbEV1IluaNqstFMM4pPOliBF0VzITqqL/ovRh 8cuEUeREvqymkOt6yUJ0Hi2ZbZis1X8RwQcpVoGZGBWJkZXbCRuDT0Ls08/DT+jShn dn+QFNhF2lCMi5IyMOwjTC/e4U4y7VONl88uls8yMNwNQ8QnV0VyWS6v/e2zL6+U6g 4XnKzkQQTB2w6bd+uTGDomd9m5D5xboPEq0/7zh8sv3kTsW46TzCxYD5i4P2X/HkDu 1Y2XxE+M/hLQfaK9nk5xu0IGY3cxkcQdheTHE8ZrRlZ3U18NqndsgoH3QQSqPCmBJX Hm+mZ/D1bPdSg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v4 18/18] Add del_chat callback query Date: Sat, 30 Jul 2022 11:40:16 +0700 Message-Id: <20220730044016.988-19-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220730044016.988-1-kiizuha@gnuweeb.org> References: <20220730044016.988-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: I want to easily remove chat by index remotely using bot message button, easily just press the button number in /del_chat bot command. Signed-off-by: Muhammad Rizki --- daemon/packages/plugins/callbacks/del_chat.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 daemon/packages/plugins/callbacks/del_chat.py diff --git a/daemon/packages/plugins/callbacks/del_chat.py b/daemon/packages/plugins/callbacks/del_chat.py new file mode 100644 index 0000000..d8ba569 --- /dev/null +++ b/daemon/packages/plugins/callbacks/del_chat.py @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +from packages import DaemonClient +from scraper import utils +from pyrogram.types import CallbackQuery + + +@DaemonClient.on_callback_query(group=2) +async def on_del_chat(c: DaemonClient, cb: CallbackQuery): + if not "del_chat" in cb.data: + return + + chats = c.db.get_broadcast_chats() + if not bool(chats): + return await cb.answer("Currently empty.") + + index = int(utils.remove_command(cb.data)) + chat = chats[index - 1] + chat_id = chat[1] + chat_name = chat[3] + + success = c.db.delete_broadcast(chat_id) + if not success: + msg = f"Failed to delete {chat_name} from receiving email message\n" + msg += "Maybe it's already been deleted or not exists." + else: + msg = f"Success delete {chat_name} from receiving email message" + + await cb.answer(msg, show_alert=True) + + await cb.message.delete() + if cb.message.reply_to_message: + await cb.message.reply_to_message.delete() -- Muhammad Rizki