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.1.2] (unknown [101.128.125.157]) by gnuweeb.org (Postfix) with ESMTPSA id C3BF87E257; Sat, 30 Jul 2022 01:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659144341; bh=uDnDF8+gnCZb7+jpgF9sjP2siKv5MVfsHVdxEAQ6BC0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=id5tpzeFYUiRZe3u32+KOQimyVcgdXu/gBDoDQynZfjqNJZPqcuswyCfIzaIdYRqa y7TivQsfMBYJUWyronkfYd1jusIdaKN8xaXY9KCXYCfDW3L8K9yYdjRXi3ttbTVPHb 5l8ZbYZpxAAe7YPhct/w5A/GolwUWoy/mlJ5C7kaso5JeCMvp1sPXuSJ0E7BS1DfsD MvFzaehzCNUN6Qk1kUyPVJ3kHwaSx9qKeovVoX5RMa27t8CqgtDT94vb1PS0031cY1 mH2fjr81QgAdAF/EAVn6XA+C0FHCQ9rDMw564Q7vX6yci1bxG1YRLuIkmkm1/krf3N ZL0ZHYagh1Xiw== Message-ID: <4855b567-1034-9dc4-8a71-610e9ef2eaf3@gnuweeb.org> Date: Sat, 30 Jul 2022 08:25:35 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 Subject: Re: [PATCH v3 16/18] Add create_chat_link() function To: Ammar Faizi Cc: GNU/Weeb Mailing List , Alviro Iskandar Setiawan References: <20220729014052.1547-1-kiizuha@gnuweeb.org> <20220729014052.1547-17-kiizuha@gnuweeb.org> Content-Language: en-US From: Muhammad Rizki In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: On 30/07/2022 08.22, Ammar Faizi wrote: > 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" > Thanks, I'll improve the code.