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 231B77E257; Sat, 30 Jul 2022 04:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659156070; bh=hIbHDvJ6r05d7BHYbS8VWsQPVTlfnOyd9jdj36WnYA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hyUac4iWsqUkXjWQ8QnIwPREvb4UyJDMsadfiUoLhCQlnjVUnHTGY2UNPoLhoKyxw eTuK2XEcOwDuEeMRf1twPjJhQcx030NcQhDYpMHjgjA/DXX8/C20VOBJLqxTcvHJ0m muH1r/MoCE5vtrxerdZglaOJ9AD/rT0hoCUDvuYt7p4qfbx1mKlvzOVVkMzjtNao0n g32wk1ia3wDxJ4UwGh6drNfjjY3TbPSH3I6HZGkA7On0iOj2vjs9LtV4BZb6kD+OM1 vzmf9+Cx+O8YB1DKSn6degCvfOBpcUAXSzBoUMbYcDhYQks1nBskFLHFtNZDNWW+ue UcUe3bJnZ9+BA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , GNU/Weeb Mailing List , Alviro Iskandar Setiawan Subject: [PATCH v4 16/18] Add create_chat_link() function Date: Sat, 30 Jul 2022 11:40:14 +0700 Message-Id: <20220730044016.988-17-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 create a chat link when the pyrogram's Chat object sometimes doesn't have an invite_link value (None), so I create it myself and call it in packages/plugins/commands/manage_broadcast.py Signed-off-by: Muhammad Rizki --- .../packages/plugins/commands/manage_broadcast.py | 3 ++- daemon/scraper/utils.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/daemon/packages/plugins/commands/manage_broadcast.py b/daemon/packages/plugins/commands/manage_broadcast.py index 8397508..e0cc0dc 100644 --- a/daemon/packages/plugins/commands/manage_broadcast.py +++ b/daemon/packages/plugins/commands/manage_broadcast.py @@ -6,6 +6,7 @@ from pyrogram.types import Message from pyrogram import filters, enums from packages import DaemonClient +from scraper import utils @DaemonClient.on_message( @@ -24,7 +25,7 @@ async def add_broadcast(c: DaemonClient, m: Message): type=str(m.chat.type), created_at=m.date, username=m.chat.username, - link=m.chat.invite_link + link=utils.create_chat_link(m.chat) ) if inserted is None: diff --git a/daemon/scraper/utils.py b/daemon/scraper/utils.py index d894c32..e89255b 100644 --- a/daemon/scraper/utils.py +++ b/daemon/scraper/utils.py @@ -4,7 +4,7 @@ # Copyright (C) 2022 Ammar Faizi # -from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton +from pyrogram.types import Chat, InlineKeyboardMarkup, InlineKeyboardButton from email.message import Message from typing import Dict from slugify import slugify @@ -263,3 +263,14 @@ def button_numbers(data: list, callback_prefix: str, limit: int = 8): buttons = [lst[i:i + limit ] for i in range(0, len(lst), limit)] return InlineKeyboardMarkup(buttons) + + +def create_chat_link(chat: Chat): + if chat.invite_link: + return chat.invite_link + + if chat.username: + return f"t.me/{chat.username}" + + chat_id_str = str(chat.id).replace("-100","") + return f"t.me/c/{chat_id_str}/1" -- Muhammad Rizki