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 C107D7FA25; Wed, 27 Jul 2022 02:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1658890035; bh=nejJegjReD3Ek/vzieBCviJYs/NZNh7kVQ/KFgH9e4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dB21mX4rfgGI+IpKdNVzDr8MY/yJXz0zjyycs6l9gERMSNRTPKKswVSlqOe5QiACb xgYHIY5yi7FLy14ZaGaK3Gido135A34IhsRCMm4V753RXlad/ITUSULQ4K1po71Syy XAOwqL7qCElFb8J0YuleXHPZdkFY8hhxVqgVlW7h1kEc07s53X8gF+du1KVXICBdcw Wr9n9vJdlyJCilUp+3/SYh+S3drA1sXBK/Db3MXOhBB5910H+L5sKJV7L352tikz/H l2qPy/+srSNxiJ7HKKmdBVNyrH44wLdtCuvP5WdXRCNv/WkpDvfi303Rrt50ZY3Bq8 EgB/vKtnxqgCw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List Subject: [PATCH v1 10/18] Add utility function buton_numbers() Date: Wed, 27 Jul 2022 09:46:26 +0700 Message-Id: <20220727024634.1995-11-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220727024634.1995-1-kiizuha@gnuweeb.org> References: <20220727024634.1995-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