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 604A57E328; Fri, 29 Jul 2022 00:42:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659055359; bh=z6UP9OomH3Zaj0jge8t2QiTzSiyVO4pKe/wK4w9GHqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FTS10zrS2WRsnHTxfKdyiSYIsqMJ587j13aC8y3jNf+0A6AxWp+PRe1jq/6kxQZyN ro7gPFilZpZd+i7GkMjiTL65r5sfIYNc7iUsUhE3C4tfuFw81f9f2UxxZzSH840n8+ N0+xhaHrTK3a/LA3SKIx0RWotwbs+DLK/BXmidqYr5iK1jVshPaT9F4Quqil5qiBTx 1ogBYr7FgIaTOTz+M0zjnpmQPzbroWlCZbMhYobO1QfDbeula4jrK8F7jMOTeMMLIR J+sAWXoGYsnMeFzKDfLfxmbrR/Hm3ZSq51DRNss+zJVhvxfbwUQu3vfRWnSPl4WVKh rJEi/M3ysA/XA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v2 18/18] Add del_chat callback query Date: Fri, 29 Jul 2022 07:40:46 +0700 Message-Id: <20220729004046.1890-38-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220729004046.1890-1-kiizuha@gnuweeb.org> References: <20220729004046.1890-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