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 6CAA68060F; Sat, 30 Jul 2022 04:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659156057; bh=nejJegjReD3Ek/vzieBCviJYs/NZNh7kVQ/KFgH9e4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tgIBzgdC6odREjKOqx3o3ToVb/iIpkywNR7ZbUuA9OfoQc07q9RdxAAcdMGZa7iXI QIitR1/KJxPy/hkVJv3EZAY2I086vwQO9x4kZCjApMfGtCS2a6kX8rn1+zbjgiykP/ 4f+MGjyzuEqYFzP8YJ8SRbqxrUTYFr5ffsgbPsj67z+p9In4TMnL6NgZhOuSRSfgAX dY20Bm3fXzkT0ppkWH6bprkJ9Kht1QRwLBXLmlOzkkEkAo6ugIErWzAIHBqGVAtx9I bBq1b7XSOmN2+fw1+6JWRXgr2W+8aaSZTVGeiWKk/5wYw0+okDM+yTlaHMrWWFNzYH 0JgPx8AQQX6Vw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v4 10/18] Add utility function buton_numbers() Date: Sat, 30 Jul 2022 11:40:08 +0700 Message-Id: <20220730044016.988-11-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: Add utility function buton_numbers() for easily create a number of inline buttons to manage delete atom urls. Signed-off-by: Muhammad Rizki --- daemon/packages/plugins/manage_atom.py | 5 ++++- daemon/scraper/utils.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/daemon/packages/plugins/manage_atom.py b/daemon/packages/plugins/manage_atom.py index 0d2166a..0b916de 100644 --- a/daemon/packages/plugins/manage_atom.py +++ b/daemon/packages/plugins/manage_atom.py @@ -44,4 +44,7 @@ async def del_atom_url(c: DaemonClient, m: Message): text += f"{i}. {u}\n" text += "\nChoose one of the URL above to delete by index below." - await m.reply(text) + await m.reply(text, reply_markup=utils.button_numbers( + data=atoms, + callback_prefix="del_atom" + )) diff --git a/daemon/scraper/utils.py b/daemon/scraper/utils.py index f7de5ba..d894c32 100644 --- a/daemon/scraper/utils.py +++ b/daemon/scraper/utils.py @@ -4,6 +4,7 @@ # Copyright (C) 2022 Ammar Faizi # +from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton from email.message import Message from typing import Dict from slugify import slugify @@ -246,3 +247,19 @@ def remove_command(text: str): txt = text.split(" ") txt = text.replace(txt[0] + " ","") return txt + + +def button_numbers(data: list, callback_prefix: str, limit: int = 8): + if limit > 8: + raise ValueError("Limit value cannot more than 8.") + + lst = [] + for i in range(1, len(data)+1): + button = InlineKeyboardButton( + str(i), + callback_data=f"{callback_prefix} {i}" + ) + lst.append(button) + + buttons = [lst[i:i + limit ] for i in range(0, len(lst), limit)] + return InlineKeyboardMarkup(buttons) -- Muhammad Rizki