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=-1.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,NO_DNS_FOR_FROM, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from [192.168.88.254] (unknown [125.160.106.238]) by gnuweeb.org (Postfix) with ESMTPSA id 573158060F; Sat, 30 Jul 2022 01:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659144183; bh=mBuHn5O7+YaET76KHL6wm05JU/JfGQgTtmUskcHzuXU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=qPe1sSqERB4f9WmwO/VueZpE5XbTJRv6ek9zY3NTmy48vloxUfauNv3H/gtIAr9ym x7nXh0IeRxBJgXDR4MUdfKFWH6TOEsatoX+A7vxhZlgmKx32dD+RUvfEj140smworW 86zFANPrZky90lHhWhW9K0TeANai9wL1ecd8wDBNVgwn+9X+E8w2j7m2HUljnFQZAZ gZsfVwpU0QGROYwJsOMx3+rXdbR5y+oE70pPTKNKNSBkaa1NA59MnvNN9Y1jq7dw6h Fijmt4cfUEccXkKCS3kyo4igNBb9o1v64sjY/yp8DdLdN9DObYigYz0yCJaEHLTatU OHuS9trR0SoQQ== Message-ID: Date: Sat, 30 Jul 2022 08:22:59 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3 16/18] Add create_chat_link() function Content-Language: en-US To: Muhammad Rizki Cc: GNU/Weeb Mailing List , Alviro Iskandar Setiawan References: <20220729014052.1547-1-kiizuha@gnuweeb.org> <20220729014052.1547-17-kiizuha@gnuweeb.org> From: Ammar Faizi In-Reply-To: <20220729014052.1547-17-kiizuha@gnuweeb.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: On 7/29/22 8:40 AM, Muhammad Rizki wrote: > +def create_chat_link(chat: Chat): > + chat_id_str = str(chat.id).replace("-100","") > + if chat.invite_link: > + chat_link = chat.invite_link > + > + elif chat.username: > + chat_link = f"t.me/{chat.username}" > + else: > + chat_link = f"t.me/c/{chat_id_str}/1" > + > + return chat_link This can be further simplified. And that replace() should only be done when needed. Something like this: 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" -- Ammar Faizi