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 41B947E328; Fri, 29 Jul 2022 00:45:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659055557; bh=nejJegjReD3Ek/vzieBCviJYs/NZNh7kVQ/KFgH9e4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U172IhRBgk8qtLPTL7ktZTnU7DZht2nOsX4axJWTImt0QmckwaQDOD/gpeLyyJb9Z jrv6feM9ONfQacZrdMHKsdL7JY5vjPdPyxrl2wdS7j6erEn0DMMhCau+L3inJAoOxe E1koWi4XyosgurB/PCHiz6TeZkpahUqeZowtEdgMLWp8QRYCc4TkzfFa1pjsrHIrqm 9RwJFwhDP7dqsFNCffo0W+Kp9oo/LgUa1gXStIMdWckvbf46Pz8KoGxpT+BTxDhPe3 hRMGhy/QNGbxuLomIdg1/L7MO3WvDAShxupuBRhY70P6xQtxLkGYXINKeFGrK2sM0o xaBXX3lwWYSmQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v2 10/18] Add utility function buton_numbers() Date: Fri, 29 Jul 2022 07:44:59 +0700 Message-Id: <20220729004507.1668-11-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220729004507.1668-1-kiizuha@gnuweeb.org> References: <20220729004507.1668-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